|
|
@@ -16,6 +16,7 @@ import net.ranides.assira.collection.IntCollection;
|
|
|
import net.ranides.assira.collection.arrays.ArrayAllocator;
|
|
|
import net.ranides.assira.collection.arrays.IntArrayAllocator;
|
|
|
import net.ranides.assira.collection.iterators.IntIterator;
|
|
|
+import net.ranides.assira.collection.BlockCollection;
|
|
|
|
|
|
/**
|
|
|
* A type-specific array-based list; provides some additional methods that use
|
|
|
@@ -41,7 +42,7 @@ import net.ranides.assira.collection.iterators.IntIterator;
|
|
|
* @see java.util.ArrayList
|
|
|
*
|
|
|
*/
|
|
|
-public class IntArrayList extends AIntList implements RandomAccess {
|
|
|
+public class IntArrayList extends AIntList implements BlockCollection<Integer>, RandomAccess {
|
|
|
|
|
|
private static final long serialVersionUID = 2;
|
|
|
|
|
|
@@ -208,6 +209,7 @@ public class IntArrayList extends AIntList implements RandomAccess {
|
|
|
* without resizing.
|
|
|
*
|
|
|
* @param capacity the new minimum capacity for this array list.
|
|
|
+ * @todo (assira # 2) move #ensureCapacity to BlockCollection
|
|
|
*/
|
|
|
public void ensureCapacity(int capacity) {
|
|
|
data = IntArrayAllocator.ensureCapacity(data, capacity, size);
|
|
|
@@ -317,13 +319,19 @@ public class IntArrayList extends AIntList implements RandomAccess {
|
|
|
this.size = size;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int capacity() {
|
|
|
+ return data.length;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Trims this array list so that the capacity is equal to the size.
|
|
|
*
|
|
|
* @see java.util.ArrayList#trimToSize()
|
|
|
*/
|
|
|
- public void trim() {
|
|
|
- trim(0);
|
|
|
+ @Override
|
|
|
+ public boolean trim() {
|
|
|
+ return trim(0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -341,14 +349,20 @@ public class IntArrayList extends AIntList implements RandomAccess {
|
|
|
*
|
|
|
* @param n the threshold for the trimming.
|
|
|
*/
|
|
|
- public void trim(int n) {
|
|
|
+ @Override
|
|
|
+ public boolean trim(int n) {
|
|
|
if (n >= data.length || size == data.length) {
|
|
|
- return;
|
|
|
+ return true;
|
|
|
}
|
|
|
- int t[] = new int[Math.max(n, size)];
|
|
|
- System.arraycopy(data, 0, t, 0, size);
|
|
|
- data = t;
|
|
|
- assert size <= data.length;
|
|
|
+ try {
|
|
|
+ int t[] = new int[Math.max(n, size)];
|
|
|
+ System.arraycopy(data, 0, t, 0, size);
|
|
|
+ data = t;
|
|
|
+ return true;
|
|
|
+ } catch(OutOfMemoryError e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|