You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2014/12/09 19:38:18 UTC
svn commit: r1644149 -
/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java
Author: schor
Date: Tue Dec 9 18:38:18 2014
New Revision: 1644149
URL: http://svn.apache.org/r1644149
Log:
[UIMA-4135] add support for removing and adding back multiples of the same value, in support of avoiding index corruption, where allow_duplicate_add_to_indices is true.
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java?rev=1644149&r1=1644148&r2=1644149&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntVector.java Tue Dec 9 18:38:18 2014
@@ -152,6 +152,13 @@ public class IntVector implements Serial
ensure_size(this.pos);
this.array[i] = element;
}
+
+ public void multiAdd(int element, int count) {
+ final int i = this.pos;
+ this.pos += count;
+ ensure_size(this.pos);
+ Arrays.fill(this.array, i, this.pos, element);
+ }
/**
* Add an element at a certain position in the vector. Elements later in the vector are shifted
@@ -171,6 +178,21 @@ public class IntVector implements Serial
}
this.array[index] = element;
}
+
+ public void multiAdd(int index, int element, int count) {
+ final int endPos = index + count;
+ if (index >= this.pos) {
+ ensure_size(endPos);
+ } else {
+ if (this.array.length < this.pos + count) {
+ ensure_size(this.pos + count);
+ } else {
+ this.pos += count;
+ }
+ System.arraycopy(this.array, index, this.array, endPos, this.pos - endPos);
+ }
+ Arrays.fill(this.array, index, endPos, element);
+ }
/**
* Set an element at a certain position in the vector.
@@ -235,6 +257,16 @@ public class IntVector implements Serial
public void removeAllElements() {
this.pos = 0;
}
+
+ public void removeAllElementsAdjustSizeDown() {
+ removeAllElements();
+ int len = array.length;
+ int newSize = len >> (
+ (len > 128) ? 2 :
+ (len > 4 ) ? 1 :
+ 0);
+ resetSize(newSize);
+ }
/**
* Compares the specified <code>Object</code> with this <code>IntVector</code> for equality.