/** * Returns the elements currently stored, possibly including invalid elements between size and capacity. * * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, this method may decide <b>not to copy the array</b>. * So if subsequently you modify the returned array directly via the [] operator, be sure you know what you're doing. * * @return the elements currently stored. */ public int[] elements() { int[] myElements = new int[size]; for (int i=size; --i >= 0; ) myElements[i]=getQuick(i); return myElements; } /**
/** * Returns the elements currently stored, possibly including invalid elements between size and capacity. * * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, this method may decide <b>not to copy the array</b>. * So if subsequently you modify the returned array directly via the [] operator, be sure you know what you're doing. * * @return the elements currently stored. */ public int[] elements() { int[] myElements = new int[size]; for (int i=size; --i >= 0; ) myElements[i]=getQuick(i); return myElements; } /**
/** * Returns the elements currently stored, possibly including invalid * elements between size and capacity. * * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, this * method may decide <b>not to copy the array</b>. So if subsequently you * modify the returned array directly via the [] operator, be sure you know * what you're doing. * * @return the elements currently stored. */ public int[] elements() { int[] myElements = new int[size]; for (int i = size; --i >= 0;) myElements[i] = getQuick(i); return myElements; }
/** * Returns the element at the specified position in the receiver. * * @param index index of element to return. * @exception IndexOutOfBoundsException index is out of range (index * < 0 || index >= size()). */ public int get(int index) { if (index >= size || index < 0) throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size); return getQuick(index); } /**
/** * Returns the element at the specified position in the receiver. * * @param index index of element to return. * @exception IndexOutOfBoundsException index is out of range (index * < 0 || index >= size()). */ public int get(int index) { if (index >= size || index < 0) throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size); return getQuick(index); } /**
/** * Returns the element at the specified position in the receiver. * * @param index * index of element to return. * @exception IndexOutOfBoundsException * index is out of range (index < 0 || index >= * size()). */ public int get(int index) { if (index >= size || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); return getQuick(index); }
/** * Returns the index of the first occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches between <code>from</code>, inclusive and <code>to</code>, inclusive. * Tests for identity. * * @param element element to search for. * @param from the leftmost search position, inclusive. * @param to the rightmost search position, inclusive. * @return the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int indexOfFromTo(int element, int from, int to) { checkRangeFromTo(from, to, size); for (int i = from ; i <= to; i++) { if (element==getQuick(i)) return i; //found } return -1; //not found } /**
/** * Returns the index of the first occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches between <code>from</code>, inclusive and <code>to</code>, inclusive. * Tests for identity. * * @param element element to search for. * @param from the leftmost search position, inclusive. * @param to the rightmost search position, inclusive. * @return the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int indexOfFromTo(int element, int from, int to) { checkRangeFromTo(from, to, size); for (int i = from ; i <= to; i++) { if (element==getQuick(i)) return i; //found } return -1; //not found } /**
/** * Compares the specified Object with the receiver. * Returns true if and only if the specified Object is also an ArrayList of the same type, both Lists have the * same size, and all corresponding pairs of elements in the two Lists are identical. * In other words, two Lists are defined to be equal if they contain the * same elements in the same order. * * @param otherObj the Object to be compared for equality with the receiver. * @return true if the specified Object is equal to the receiver. */ public boolean equals(Object otherObj) { //delta if (! (otherObj instanceof AbstractIntList)) {return false;} if (this==otherObj) return true; if (otherObj==null) return false; AbstractIntList other = (AbstractIntList) otherObj; if (size()!=other.size()) return false; for (int i=size(); --i >= 0; ) { if (getQuick(i) != other.getQuick(i)) return false; } return true; } /**
/** * Compares the specified Object with the receiver. * Returns true if and only if the specified Object is also an ArrayList of the same type, both Lists have the * same size, and all corresponding pairs of elements in the two Lists are identical. * In other words, two Lists are defined to be equal if they contain the * same elements in the same order. * * @param otherObj the Object to be compared for equality with the receiver. * @return true if the specified Object is equal to the receiver. */ public boolean equals(Object otherObj) { //delta if (! (otherObj instanceof AbstractIntList)) {return false;} if (this==otherObj) return true; if (otherObj==null) return false; AbstractIntList other = (AbstractIntList) otherObj; if (size()!=other.size()) return false; for (int i=size(); --i >= 0; ) { if (getQuick(i) != other.getQuick(i)) return false; } return true; } /**
/** * Reverses the elements of the receiver. Last becomes first, second last * becomes second first, and so on. */ public void reverse() { int tmp; int limit = size() / 2; int j = size() - 1; for (int i = 0; i < limit;) { // swap tmp = getQuick(i); setQuick(i++, getQuick(j)); setQuick(j--, tmp); } }
/** * Returns the index of the last occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches beginning at <code>to</code>, inclusive until <code>from</code>, inclusive. * Tests for identity. * * @param element element to search for. * @param from the leftmost search position, inclusive. * @param to the rightmost search position, inclusive. * @return the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int lastIndexOfFromTo(int element, int from, int to) { checkRangeFromTo(from, to, size()); for (int i = to ; i >= from; i--) { if (element==getQuick(i)) return i; //found } return -1; //not found } /**
/** * Returns the index of the last occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches beginning at <code>to</code>, inclusive until <code>from</code>, inclusive. * Tests for identity. * * @param element element to search for. * @param from the leftmost search position, inclusive. * @param to the rightmost search position, inclusive. * @return the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int lastIndexOfFromTo(int element, int from, int to) { checkRangeFromTo(from, to, size()); for (int i = to ; i >= from; i--) { if (element==getQuick(i)) return i; //found } return -1; //not found } /**
/** * Removes from the receiver all elements that are contained in the specified list. * Tests for identity. * * @param other the other list. * @return <code>true</code> if the receiver changed as a result of the call. */ public boolean removeAll(AbstractIntList other) { if (other.size()==0) return false; //nothing to do int limit = other.size()-1; int j=0; for (int i=0; i<size ; i++) { if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i)); } boolean modified = (j!=size); setSize(j); return modified; } /**
/** * Removes from the receiver all elements that are contained in the specified list. * Tests for identity. * * @param other the other list. * @return <code>true</code> if the receiver changed as a result of the call. */ public boolean removeAll(AbstractIntList other) { if (other.size()==0) return false; //nothing to do int limit = other.size()-1; int j=0; for (int i=0; i<size ; i++) { if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i)); } boolean modified = (j!=size); setSize(j); return modified; } /**
/** * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). * @param from the index of the first element (inclusive) to be permuted. * @param to the index of the last element (inclusive) to be permuted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void shuffleFromTo(int from, int to) { checkRangeFromTo(from, to, size()); cern.jet.random.Uniform gen = new cern.jet.random.Uniform(new cern.jet.random.engine.DRand(new java.util.Date())); for (int i=from; i<to; i++) { int random = gen.nextIntFromTo(i, to); //swap(i, random) int tmpElement = getQuick(random); setQuick(random,getQuick(i)); setQuick(i,tmpElement); } } /**
/** * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). * @param from the index of the first element (inclusive) to be permuted. * @param to the index of the last element (inclusive) to be permuted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void shuffleFromTo(int from, int to) { checkRangeFromTo(from, to, size()); cern.jet.random.Uniform gen = new cern.jet.random.Uniform(new cern.jet.random.engine.DRand(new java.util.Date())); for (int i=from; i<to; i++) { int random = gen.nextIntFromTo(i, to); //swap(i, random) int tmpElement = getQuick(random); setQuick(random,getQuick(i)); setQuick(i,tmpElement); } } /**
/** * Retains (keeps) only the elements in the receiver that are contained in the specified other list. * In other words, removes from the receiver all of its elements that are not contained in the * specified other list. * @param other the other list to test against. * @return <code>true</code> if the receiver changed as a result of the call. */ public boolean retainAll(AbstractIntList other) { if (other.size()==0) { if (size==0) return false; setSize(0); return true; } int limit = other.size()-1; int j=0; for (int i=0; i<size ; i++) { if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i)); } boolean modified = (j!=size); setSize(j); return modified; } /**