/** * Sets the specified range of elements in the specified array to the specified value. * * @param from the index of the first element (inclusive) to be filled with the specified value. * @param to the index of the last element (inclusive) to be filled with the specified value. * @param val the value to be stored in the specified elements of the receiver. */ public void fillFromToWith(int from, int to, boolean val) { checkRangeFromTo(from,to,this.size); for (int i=from; i<=to;) setQuick(i++,val); } /**
/** * Sets the specified range of elements in the specified array to the specified value. * * @param from the index of the first element (inclusive) to be filled with the specified value. * @param to the index of the last element (inclusive) to be filled with the specified value. * @param val the value to be stored in the specified elements of the receiver. */ public void fillFromToWith(int from, int to, boolean val) { checkRangeFromTo(from,to,this.size); for (int i=from; i<=to;) setQuick(i++,val); } /**
/** * 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(boolean 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(boolean 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 a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive. * @param from the index of the first element (inclusive). * @param to the index of the last element (inclusive). * @return a new list * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public AbstractBooleanList partFromTo(int from, int to) { checkRangeFromTo(from, to, size); int length = to-from+1; BooleanArrayList part = new BooleanArrayList(length); part.addAllOfFromTo(this,from,to); return part; } /**
/** * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive. * @param from the index of the first element (inclusive). * @param to the index of the last element (inclusive). * @return a new list * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public AbstractBooleanList partFromTo(int from, int to) { checkRangeFromTo(from, to, size); int length = to-from+1; BooleanArrayList part = new BooleanArrayList(length); part.addAllOfFromTo(this,from,to); return part; } /**
/** * 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 } /**
/** * Removes from the receiver all elements whose index is between * <code>from</code>, inclusive and <code>to</code>, inclusive. Shifts any succeeding * elements to the left (reduces their index). * This call booleanens the list by <tt>(to - from + 1)</tt> elements. * * @param from index of first element to be removed. * @param to index of last element to be removed. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void removeFromTo(int from, int to) { checkRangeFromTo(from, to, size); int numMoved = size - to - 1; if (numMoved > 0) { replaceFromToWithFrom(from, from-1+numMoved, this, to+1); //fillFromToWith(from+numMoved, size-1, 0.0f); //delta } int width = to-from+1; if (width>0) setSizeRaw(size-width); } /**
/** * Removes from the receiver all elements whose index is between * <code>from</code>, inclusive and <code>to</code>, inclusive. Shifts any succeeding * elements to the left (reduces their index). * This call booleanens the list by <tt>(to - from + 1)</tt> elements. * * @param from index of first element to be removed. * @param to index of last element to be removed. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void removeFromTo(int from, int to) { checkRangeFromTo(from, to, size); int numMoved = size - to - 1; if (numMoved > 0) { replaceFromToWithFrom(from, from-1+numMoved, this, to+1); //fillFromToWith(from+numMoved, size-1, 0.0f); //delta } int width = to-from+1; if (width>0) setSizeRaw(size-width); } /**
/** * 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 } /**
/** * Replaces a number of elements in the receiver with the same number of elements of another list. * Replaces elements in the receiver, between <code>from</code> (inclusive) and <code>to</code> (inclusive), * with elements of <code>other</code>, starting from <code>otherFrom</code> (inclusive). * * @param from the position of the first element to be replaced in the receiver * @param to the position of the last element to be replaced in the receiver * @param other list holding elements to be copied into the receiver. * @param otherFrom position of first element within other list to be copied. */ public void replaceFromToWithFrom(int from, int to, AbstractBooleanList other, int otherFrom) { int length=to-from+1; if (length>0) { checkRangeFromTo(from, to, size()); checkRangeFromTo(otherFrom,otherFrom+length-1,other.size()); // unambiguous copy (it may hold other==this) if (from<=otherFrom) { for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++)); } else { int otherTo = otherFrom+length-1; for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--)); } } } /**
/** * Replaces a number of elements in the receiver with the same number of elements of another list. * Replaces elements in the receiver, between <code>from</code> (inclusive) and <code>to</code> (inclusive), * with elements of <code>other</code>, starting from <code>otherFrom</code> (inclusive). * * @param from the position of the first element to be replaced in the receiver * @param to the position of the last element to be replaced in the receiver * @param other list holding elements to be copied into the receiver. * @param otherFrom position of first element within other list to be copied. */ public void replaceFromToWithFrom(int from, int to, AbstractBooleanList other, int otherFrom) { int length=to-from+1; if (length>0) { checkRangeFromTo(from, to, size()); checkRangeFromTo(otherFrom,otherFrom+length-1,other.size()); // unambiguous copy (it may hold other==this) if (from<=otherFrom) { for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++)); } else { int otherTo = otherFrom+length-1; for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--)); } } } /**
/** * 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); } } /**