r9815 - helma/helma/trunk/src/helma/objectmodel/db
[email protected] Wed, 27 May 2009 13:59:15 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090527115915.2327B3D0E3@mia> |
Author: hannes
Date: 2009-05-27 13:59:15 +0200 (Wed, 27 May 2009)
New Revision: 9815
Modified:
helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java
Log:
Consistently update subnodeCount in add/remove methods, and fix bug where size() returns wrong result.
Details at http://dev.helma.org/trac/helma/changeset/9815
Modified: helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java 2009-05-27 11:42:57 UTC (rev 9814)
+++ helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java 2009-05-27 11:59:15 UTC (rev 9815)
@@ -36,7 +36,14 @@
* @param obj element to be inserted.
*/
public synchronized boolean add(Object obj) {
+ if (!hasRelationalNodes() || segments == null) {
+ return super.add(obj);
+ }
+ if (subnodeCount == -1) {
+ update();
+ }
subnodeCount++;
+ segments[segments.length - 1].length += 1;
return list.add(obj);
}
/**
@@ -49,6 +56,10 @@
super.add(index, obj);
return;
}
+ if (subnodeCount == -1) {
+ update();
+ }
+ subnodeCount++;
list.add(index, obj);
// shift segment indices by one
int s = getSegment(index);
@@ -108,12 +119,16 @@
if (!hasRelationalNodes() || segments == null) {
return super.remove(index);
}
+ if (subnodeCount == -1) {
+ update();
+ }
Object removed = list.remove(index);
int s = getSegment(index);
segments[s].length -= 1;
for (int i = s + 1; i < segments.length; i++) {
segments[i].startIndex -= 1;
}
+ subnodeCount--;
return removed;
}
@@ -125,6 +140,9 @@
if (!hasRelationalNodes() || segments == null) {
return super.remove(object);
}
+ if (subnodeCount == -1) {
+ update();
+ }
int index = indexOf(object);
if (index > -1) {
list.remove(object);
@@ -133,6 +151,7 @@
for (int i = s + 1; i < segments.length; i++) {
segments[i].startIndex -= 1;
}
+ subnodeCount--;
return true;
}
return false;
@@ -189,6 +208,7 @@
protected synchronized void update() {
if (!hasRelationalNodes()) {
super.update();
+ return;
}
// also reload if the type mapping has changed.
long lastChange = getLastSubnodeChange();
@@ -216,7 +236,7 @@
}
public int size() {
- if (!hasRelationalNodes()) {
+ if (!hasRelationalNodes() || segments == null) {
return super.size();
}