Methods Summary |
---|
public void | add(int index, long val)
if (size == data.length) {
makeRoom(1);
}
System.arraycopy(data, index, data, index+1, size - index);
data[index] = val;
size++;
|
public boolean | add(long val)
if (size == data.length) {
makeRoom(1);
}
data[size++] = val;
return true;
|
public boolean | addAll(com.sun.enterprise.util.collection.LongArray coll)
int collSize = coll.size();
makeRoom(collSize);
LongIterator longIter = coll.longIterator();
while (longIter.hasNext()) {
data[size++] = longIter.nextLong();
}
return (collSize > 0);
|
public boolean | addAll(int index, com.sun.enterprise.util.collection.LongArray coll)
int collSize = coll.size();
makeRoom(collSize);
System.arraycopy(data, index, data, index+collSize, size - index);
LongIterator longIter = coll.longIterator();
while (longIter.hasNext()) {
data[index++] = longIter.nextLong();
}
size += collSize;
return (collSize > 0);
|
public void | clear()
size = 0;
data = new long[6];
|
public boolean | contains(long val)
return (indexOf(val) >= 0);
|
public boolean | containsAll(com.sun.enterprise.util.collection.LongArray coll)
LongIterator iter = coll.longIterator();
while (iter.hasNext()) {
if (contains(iter.nextLong()) == false) {
return false;
}
}
return true;
|
public boolean | containsAll(long[] array)
for (int i=array.length; i > 0; ) {
if (contains(array[--i]) == false) {
return false;
}
}
return true;
|
public boolean | equals(java.lang.Object o)
//For now do this way. Fix it later
return this == o;
|
public long | get(int index)
return data[index];
|
public int | hashCode()
long hashCode = 1;
for (int i=0; i<size; i++) {
hashCode = 31*hashCode + data[i];
}
return (int) hashCode;
|
public int | indexOf(long val)
for (int i=0; i<size; i++) {
if (data[i] == val) {
return i;
}
}
return -1;
|
public boolean | isEmpty()
return size == 0;
|
public java.util.Iterator | iterator()
return new LongIterator(0);
|
public int | lastIndexOf(long val)
for (int i=size-1; i >= 0; i--) {
if (data[i] == val) {
return i;
}
}
return -1;
|
public java.util.ListIterator | listIterator()
return new LongIterator(0);
|
public java.util.ListIterator | listIterator(int index)
return new LongIterator(index);
|
public com.sun.enterprise.util.collection.LongArray$LongIterator | longIterator()
return new LongIterator(0);
|
public static void | main(java.lang.String[] args)
int count = 1000000;
ArrayList al = new ArrayList(count);
LongArray la = new LongArray(count, 0.1);
LongArrayList lal = new LongArrayList(count, 0.1);
long t1, t2;
t1 = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
al.add(Long.valueOf(i));
}
t2 = System.currentTimeMillis();
System.out.println("ArrayList took: " + ((t2 - t1) / 1000.0) + " sec.");
al.clear();
t1 = System.currentTimeMillis();
for (int i=0; i<count; i++) {
la.add(i);
}
t2 = System.currentTimeMillis();
System.out.println("LongArray took: " + ((t2 - t1) / 1000.0) + " sec.");
la.printStat();
la.clear();
t1 = System.currentTimeMillis();
for (int i=0; i<count; i++) {
lal.add(i);
}
t2 = System.currentTimeMillis();
System.out.println("LongArrayList took: " + ((t2 - t1) / 1000.0) + " sec.");
lal.clear();
for (int i=0; i<count; i++) {
la.add(i);
}
for (int i=0; i<10; i++) {
for (int j=0; j<count; j++) {
if (la.get(j) != j) {
System.out.println("data["+j+"]: " + la.get(j));
}
}
}
|
protected void | makeRoom(int space)
if (space + size >= data.length) {
long[] oldData = data;
int newSize = size + space + ((int) (size * growFactor)) + 1;
data = new long[newSize];
System.arraycopy(oldData, 0, data, 0, oldData.length);
}
|
public void | print()
System.out.print("Data (size: " + size + "): ");
for (int i=0; i<size; i++) {
System.out.print(" " + data[i]);
}
System.out.println();
|
public void | printStat()
System.out.println("Size: " + size);
System.out.println("Length: " + data.length);
|
public long | remove(int index)
long val = data[index];
if (index < size - 1) {
System.arraycopy(data, index+1, data, index, size - index);
}
size--;
return val;
|
public boolean | remove(long val)
for (int i=0; i<size; i++) {
if (data[i] == val) {
if (i < size - 1) {
System.arraycopy(data, i+1, data, i, size - i);
size--;
return true;
}
}
}
return false;
|
public boolean | removeAll(com.sun.enterprise.util.collection.LongArray coll)
boolean removed = false;
LongIterator iter = coll.longIterator();
while (iter.hasNext()) {
if (remove(iter.nextLong()) == true) {
removed = true;
}
}
return removed;
|
public boolean | removeAll(long[] array)
boolean removed = false;
for (int i=0; i<array.length; i++) {
if (remove(array[i]) == true) {
removed = true;
}
}
return removed;
|
public boolean | retainAll(com.sun.enterprise.util.collection.LongArray coll)
return false;
|
public boolean | retainAll(long[] array)
return false;
|
public java.lang.Object | set(int index, java.lang.Object o)
long oldVal = data[index];
data[index] = ((Long) o).longValue();
return Long.valueOf(oldVal);
|
public long | set(int index, long val)
long oldVal = data[index];
data[index] = val;
return oldVal;
|
public int | size()
return size;
|
public long[] | toArray()
return data;
|