/** * Returns a <code>java.util.ArrayList</code> containing all the elements in the receiver. */ public java.util.ArrayList toList() { int mySize = size(); java.util.ArrayList list = new java.util.ArrayList(mySize); for (int i=0; i < mySize; i++) list.add(new Boolean(get(i))); return list; } /**
/** * Returns a list which is a concatenation of <code>times</code> times the receiver. * @param times the number of times the receiver shall be copied. */ public AbstractBooleanList times(int times) { AbstractBooleanList newList = new BooleanArrayList(times*size()); for (int i=times; --i >= 0; ) { newList.addAllOfFromTo(this,0,size()-1); } return newList; } /**
/** * Returns a list which is a concatenation of <code>times</code> times the receiver. * @param times the number of times the receiver shall be copied. */ public AbstractBooleanList times(int times) { AbstractBooleanList newList = new BooleanArrayList(times*size()); for (int i=times; --i >= 0; ) { newList.addAllOfFromTo(this,0,size()-1); } return newList; } /**
/** * Returns a <code>java.util.ArrayList</code> containing all the elements in the receiver. */ public java.util.ArrayList toList() { int mySize = size(); java.util.ArrayList list = new java.util.ArrayList(mySize); for (int i=0; i < mySize; i++) list.add(new Boolean(get(i))); return list; } /**
/** * 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 AbstractBooleanList)) {return false;} if (this==otherObj) return true; if (otherObj==null) return false; AbstractBooleanList other = (AbstractBooleanList) 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 AbstractBooleanList)) {return false;} if (this==otherObj) return true; if (otherObj==null) return false; AbstractBooleanList other = (AbstractBooleanList) otherObj; if (size()!=other.size()) return false; for (int i=size(); --i >= 0; ) { if (getQuick(i) != other.getQuick(i)) return false; } return true; } /**
/** * Replaces the part of the receiver starting at <code>from</code> (inclusive) with all the elements of the specified collection. * Does not alter the size of the receiver. * Replaces exactly <tt>Math.max(0,Math.min(size()-from, other.size()))</tt> elements. * * @param from the index at which to copy the first element from the specified collection. * @param other Collection to replace part of the receiver * @exception IndexOutOfBoundsException index is out of range (index < 0 || index >= size()). */ public void replaceFromWith(int from, java.util.Collection other) { checkRange(from,size()); java.util.Iterator e = other.iterator(); int index=from; int limit = Math.min(size()-from, other.size()); for (int i=0; i<limit; i++) set(index++,((Boolean) e.next()).booleanValue()); //delta } /**
/** * Replaces the part of the receiver starting at <code>from</code> (inclusive) with all the elements of the specified collection. * Does not alter the size of the receiver. * Replaces exactly <tt>Math.max(0,Math.min(size()-from, other.size()))</tt> elements. * * @param from the index at which to copy the first element from the specified collection. * @param other Collection to replace part of the receiver * @exception IndexOutOfBoundsException index is out of range (index < 0 || index >= size()). */ public void replaceFromWith(int from, java.util.Collection other) { checkRange(from,size()); java.util.Iterator e = other.iterator(); int index=from; int limit = Math.min(size()-from, other.size()); for (int i=0; i<limit; i++) set(index++,((Boolean) e.next()).booleanValue()); //delta } /**
/** * 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(boolean 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(boolean 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 a string representation of the receiver, containing * the String representation of each element. */ public String toString() { return cern.colt.Arrays.toString(partFromTo(0, size()-1).elements()); } }
/** * Returns a string representation of the receiver, containing * the String representation of each element. */ public String toString() { return cern.colt.Arrays.toString(partFromTo(0, size()-1).elements()); } }
/** * 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(AbstractBooleanList 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(AbstractBooleanList 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; } /**
/** * 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(AbstractBooleanList 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; } /**
/** * 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(AbstractBooleanList 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; } /**
/** * 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) boolean 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) boolean tmpElement = getQuick(random); setQuick(random,getQuick(i)); setQuick(i,tmpElement); } } /**