FileDocCategorySizeDatePackage
LongArrayList.javaAPI DocGlassfish v2 API10550Fri May 04 22:32:10 BST 2007package com.sun.enterprise.util.collection

LongArrayList

public class LongArrayList extends Object implements List

Fields Summary
long[]
data
int
minIndex
int
size
double
growFactor
Constructors Summary
public LongArrayList()

		this(6, 0.5);
	
public LongArrayList(int initialCapacity)

		this(initialCapacity, 0.5);
	
public LongArrayList(int initialCapacity, double growFactor)

		data = new long[initialCapacity];
		this.growFactor = growFactor;
	
private LongArrayList(long[] data, int minIndex, int size, double growFactor)

		this.data = data;
		this.minIndex = minIndex;
		this.size = size;
		this.growFactor = growFactor;
	
Methods Summary
public voidadd(int index, java.lang.Object o)

		long val = ((Long) o).longValue();
		if (size == data.length) {
			makeRoom(1);
		}

		System.arraycopy(data, index, data, index+1, size - index);
		data[index] = val;
		size++;

	
public voidadd(int index, long val)

		if (size == data.length) {
			makeRoom(1);
		}

		System.arraycopy(data, index, data, index+1, size - index);
		data[index] = val;
		size++;

	
public booleanadd(java.lang.Object o)

		long		val = ((Long) o).longValue();
		if (size == data.length) {
			makeRoom(1);
		}

		data[size++] = val;
		return true;
	
public booleanadd(long val)

		if (size == data.length) {
			makeRoom(1);
		}

		data[size++] = val;
		return true;
	
public booleanaddAll(com.sun.enterprise.util.collection.LongArrayList coll)

		int collSize = coll.size();
		makeRoom(collSize);
		LongIterator longIter = coll.longIterator();
		while (longIter.hasNext()) {
			data[size++] = longIter.nextLong();
		}
		return (collSize > 0);
	
public booleanaddAll(int index, java.util.Collection coll)

		int collSize = coll.size();
		makeRoom(collSize);
		System.arraycopy(data, index, data, index+collSize, size - index);
		Iterator iter = coll.iterator();
		while (iter.hasNext()) {
			data[index++] = ((Long) iter.next()).longValue();
		}
		size += collSize;
		return (collSize > 0);
	
public booleanaddAll(int index, com.sun.enterprise.util.collection.LongArrayList 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 booleanaddAll(java.util.Collection coll)

		int collSize = coll.size();
		makeRoom(collSize);
		Iterator iter = coll.iterator();
		while (iter.hasNext()) {
			data[size++] = ((Long) iter.next()).longValue();
		}
		return (collSize > 0);
	
public voidclear()

		size = 0;
		data = new long[6];
	
public booleancontains(java.lang.Object o)

		return (indexOf(o) >= 0);
	
public booleancontains(long val)

		return (indexOf(val) >= 0);
	
public booleancontainsAll(java.util.Collection coll)

		Iterator iter = coll.iterator();
		while (iter.hasNext()) {
			if (contains(iter.next()) == false) {
				return false;
			}
		}
		return true;
	
public booleancontainsAll(com.sun.enterprise.util.collection.LongArrayList coll)

		LongIterator iter = coll.longIterator();
		while (iter.hasNext()) {
			if (contains(iter.nextLong()) == false) {
				return false;
			}
		}
		return true;
	
public booleancontainsAll(long[] array)

		for (int i=array.length; i > 0; ) {
			if (contains(array[--i]) == false) {
				return false;
			}
		}
		return true;
	
public booleanequals(java.lang.Object o)

		//For now do this way. Fix it later
		return this == o;
	
public java.lang.Objectget(int index)

		return Long.valueOf(data[index]);
	
public longgetValue(int index)

		return data[index];
	
public inthashCode()

		long hashCode = 1;
		for (int i=0; i<size; i++) {
			hashCode = 31*hashCode + data[i];
		}
		return (int) hashCode;
	
public intindexOf(java.lang.Object o)

		long val = ((Long) o).longValue();
		for (int i=0; i<size; i++) {
			if (data[i] == val) {
				return i;
			}
		}
		return -1;
	
public intindexOf(long val)

		for (int i=0; i<size; i++) {
			if (data[i] == val) {
				return i;
			}
		}
		return -1;
	
public booleanisEmpty()

		return size == 0;
	
public java.util.Iteratoriterator()

		return new LongIterator(0);
	
public intlastIndexOf(java.lang.Object o)

		long val = ((Long) o).longValue();
		for (int i=size-1; i >= 0; i--) {
			if (data[i] == val) {
				return i;
			}
		}
		return -1;
	
public intlastIndexOf(long val)

		for (int i=size-1; i >= 0; i--) {
			if (data[i] == val) {
				return i;
			}
		}
		return -1;
	
public java.util.ListIteratorlistIterator()

		return new LongIterator(0);
	
public java.util.ListIteratorlistIterator(int index)

		return new LongIterator(index);
	
public com.sun.enterprise.util.collection.LongArrayList$LongIteratorlongIterator()

		return new LongIterator(0);
	
public static voidmain(java.lang.String[] args)

		LongArrayList list = new LongArrayList();

		for (int i=0; i<15; i+=2) {
			list.add(i);
		}

		for (int i=1; i<15; i+=2) {
			list.add(i);
		}
	
protected voidmakeRoom(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 voidprint()

		System.out.print("Data (size: " + size + "): ");
		for (int i=0; i<size; i++) {
			System.out.print(" " + data[i]);
		}
		System.out.println();
	
public java.lang.Objectremove(int index)

		long val = data[index];
		if (index < size - 1) {
			System.arraycopy(data, index+1, data, index, size - index);
		}
		size--;
		return Long.valueOf(val);
	
public booleanremove(java.lang.Object object)

		long val = ((Long) object).longValue();
		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 booleanremove(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 booleanremoveAll(java.util.Collection coll)

		boolean	removed = false;
		Iterator iter = coll.iterator();
		while (iter.hasNext()) {
			if (remove(iter.next()) == true) {
				removed = true;
			}
		}
		return removed;
	
public booleanremoveAll(com.sun.enterprise.util.collection.LongArrayList coll)

		boolean	removed = false;
		LongIterator iter = coll.longIterator();
		while (iter.hasNext()) {
			if (remove(iter.nextLong()) == true) {
				removed = true;
			}
		}
		return removed;
	
public booleanremoveAll(long[] array)

		boolean	removed = false;
		for (int i=0; i<array.length; i++) {
			if (remove(array[i]) == true) {
				removed = true;
			}
		}
		return removed;
	
public longremoveLong(int index)

		long val = data[index];
		if (index < size - 1) {
			System.arraycopy(data, index+1, data, index, size - index);
		}
		size--;
		return val;
	
public booleanretainAll(java.util.Collection coll)

		return false;
	
public booleanretainAll(com.sun.enterprise.util.collection.LongArrayList coll)

		return false;
	
public booleanretainAll(long[] array)

		return false;
	
public java.lang.Objectset(int index, java.lang.Object o)

		long oldVal = data[index];
		data[index] = ((Long) o).longValue();
		return Long.valueOf(oldVal);
	
public longset(int index, long val)

		long oldVal = data[index];
		data[index] = val;
		return oldVal;
	
public intsize()

		return size;
	
public java.util.ListsubList(int fromIndex, int toIndex)

		return new LongArrayList(data, fromIndex, toIndex, growFactor);
	
public java.lang.Object[]toArray()

		Long[]	array = new Long[size];
		for (int i = 0; i < size; i++) {
                     array[i] = Long.valueOf(data[i]);
                 }
		return array;
	
public java.lang.Object[]toArray(java.lang.Object[] arr)

		Long[]	array = new Long[size];
		for (int i = 0; i < size; i++) {
                     array[i] = Long.valueOf(data[i]);
                 }
		return array;