/** * 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 AbstractShortList times(int times) { AbstractShortList newList = new ShortArrayList(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 AbstractShortList times(int times) { AbstractShortList newList = new ShortArrayList(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 Short(get(i))); return list; } /**
/** * 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 Short(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 AbstractShortList)) {return false;} if (this==otherObj) return true; if (otherObj==null) return false; AbstractShortList other = (AbstractShortList) 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++,((Number) e.next()).shortValue()); //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++,((Number) e.next()).shortValue()); //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(short 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(short 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(AbstractShortList 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(AbstractShortList 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; } /**
/** * Sorts the specified range of the receiver into * ascending numerical order. The sorting algorithm is a tuned quicksort, * adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a * Sort Function", Software-Practice and Experience, Vol. 23(11) * P. 1249-1265 (November 1993). This algorithm offers n*log(n) * performance on many data sets that cause other quicksorts to degrade to * quadratic performance. * * <p><b>You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set.</b> * It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because those methods automatically choose the best sorting algorithm. * * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (inclusive) to be sorted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void quickSortFromTo(int from, int to) { int mySize = size(); checkRangeFromTo(from, to, mySize); short[] myElements = elements(); java.util.Arrays.sort(myElements, from, to+1); elements(myElements); setSizeRaw(mySize); } /**
/** * 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, AbstractShortList 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) short 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) short tmpElement = getQuick(random); setQuick(random,getQuick(i)); setQuick(i,tmpElement); } } /**
/** * Sorts the specified range of the receiver into ascending order. * * The sorting algorithm is a modified mergesort (in which the merge is * omitted if the highest element in the low sublist is less than the * lowest element in the high sublist). This algorithm offers guaranteed * n*log(n) performance, and can approach linear performance on nearly * sorted lists. * * <p><b>You should never call this method unless you are sure that this particular sorting algorithm is the right one for your data set.</b> * It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because those methods automatically choose the best sorting algorithm. * * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (inclusive) to be sorted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void mergeSortFromTo(int from, int to) { int mySize = size(); checkRangeFromTo(from, to, mySize); short[] myElements = elements(); cern.colt.Sorting.mergeSort(myElements, from, to+1); elements(myElements); setSizeRaw(mySize); } /**