mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robina...@apache.org
Subject svn commit: r894251 [2/3] - in /lucene/mahout/trunk: collections-codegen-plugin/src/main/java/org/apache/mahout/collection_codegen/ math/ math/src/main/java-templates/org/apache/mahout/math/buffer/ math/src/main/java-templates/org/apache/mahout/math/fu...
Date Mon, 28 Dec 2009 21:30:23 GMT
Added: lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t?rev=894251&view=auto
==============================================================================
--- lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t (added)
+++ lucene/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t Mon Dec 28 21:30:05 2009
@@ -0,0 +1,681 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+Copyright � 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
+is hereby granted without fee, provided that the above copyright notice appear in all copies and 
+that both that copyright notice and this permission notice appear in supporting documentation. 
+CERN makes no representations about the suitability of this software for any purpose. 
+It is provided "as is" without expressed or implied warranty.
+*/
+package org.apache.mahout.math.list;
+
+import org.apache.mahout.math.function.${valueTypeCap}Procedure;
+import org.apache.mahout.math.jet.random.Uniform;
+import org.apache.mahout.math.jet.random.engine.DRand;
+
+import java.util.Date;
+/**
+ Resizable list holding <code>${valueType}</code> elements; implemented with arrays.
+*/
+
+public class ${valueTypeCap}ArrayList extends Abstract${valueTypeCap}List {
+
+  /**
+   * The array buffer into which the elements of the list are stored. The capacity of the list is the length of this
+   * array buffer.
+   */
+  private ${valueType}[] elements;
+
+  /** Constructs an empty list. */
+  public ${valueTypeCap}ArrayList() {
+    this(10);
+  }
+
+  /**
+   * Constructs a list containing the specified elements. The initial size and capacity of the list is the length of the
+   * array.
+   *
+   * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, <b>the array is not copied</b>. So if
+   * subsequently you modify the specified array directly via the [] operator, be sure you know what you're doing.
+   *
+   * @param elements the array to be backed by the the constructed list
+   */
+  public ${valueTypeCap}ArrayList(${valueType}[] elements) {
+    elements(elements);
+  }
+
+  /**
+   * Constructs an empty list with the specified initial capacity.
+   *
+   * @param initialCapacity the number of elements the receiver can hold without auto-expanding itself by allocating new
+   *                        internal memory.
+   */
+  public ${valueTypeCap}ArrayList(int initialCapacity) {
+    this(new ${valueType}[initialCapacity]);
+    setSizeRaw(0);
+  }
+
+  /**
+   * Appends the specified element to the end of this list.
+   *
+   * @param element element to be appended to this list.
+   */
+  public void add(${valueType} element) {
+    // overridden for performance only.
+    if (size == elements.length) {
+      ensureCapacity(size + 1);
+    }
+    elements[size++] = element;
+  }
+
+  /**
+   * Inserts the specified element before the specified position into the receiver. Shifts the element currently at that
+   * position (if any) and any subsequent elements to the right.
+   *
+   * @param index   index before which the specified element is to be inserted (must be in [0,size]).
+   * @param element element to be inserted.
+   * @throws IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
+   */
+  public void beforeInsert(int index, ${valueType} element) {
+    // overridden for performance only.
+    if (size == index) {
+      add(element);
+      return;
+    }
+    if (index > size || index < 0) {
+      throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+    }
+    ensureCapacity(size + 1);
+    System.arraycopy(elements, index, elements, index + 1, size - index);
+    elements[index] = element;
+    size++;
+  }
+
+  /**
+   * Searches the receiver for the specified value using the binary search algorithm.  The receiver must
+   * <strong>must</strong> be sorted (as by the sort method) prior to making this call.  If it is not sorted, the
+   * results are undefined: in particular, the call may enter an infinite loop.  If the receiver contains multiple
+   * elements equal to the specified object, there is no guarantee which instance will be found.
+   *
+   * @param key  the value to be searched for.
+   * @param from the leftmost search position, inclusive.
+   * @param to   the rightmost search position, inclusive.
+   * @return index of the search key, if it is contained in the receiver; otherwise, <tt>(-(<i>insertion point</i>) -
+   *         1)</tt>.  The <i>insertion point</i> is defined as the the point at which the value would be inserted into
+   *         the receiver: the index of the first element greater than the key, or <tt>receiver.size()</tt>, if all
+   *         elements in the receiver are less than the specified key.  Note that this guarantees that the return value
+   *         will be &gt;= 0 if and only if the key is found.
+   * @see org.apache.mahout.math.Sorting
+   * @see java.util.Arrays
+   */
+  @Override
+  public int binarySearchFromTo(${valueType} key, int from, int to) {
+    return org.apache.mahout.math.Sorting.binarySearchFromTo(elements, key, from, to);
+  }
+  
+  /**
+   * Returns a deep copy of the receiver.
+   *
+   * @return a deep copy of the receiver.
+   */
+  @Override
+  public Object clone() {
+    // overridden for performance only.
+    ${valueTypeCap}ArrayList clone = new ${valueTypeCap}ArrayList(elements.clone());
+    clone.setSizeRaw(size);
+    return clone;
+  }
+
+  /**
+   * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result.
+   *
+   * @return a deep copy of the receiver.
+   */
+  public ${valueTypeCap}ArrayList copy() {
+    return (${valueTypeCap}ArrayList) clone();
+  }
+
+  #if ($valueType != 'float' && $valueType != 'double' && $valueType != 'long') 
+  /**
+   * Sorts the specified range of the receiver into ascending numerical order.
+   *
+   * The sorting algorithm is a count sort. This algorithm offers guaranteed <dt>Performance: O(Max(n,max-min+1)).
+   * <dt>Space requirements: int[max-min+1] buffer. <p>This algorithm is only applicable if max-min+1 is not large! But
+   * if applicable, it usually outperforms quicksort by a factor of 3-4.
+   *
+   * @param from the index of the first element (inclusive) to be sorted.
+   * @param to   the index of the last element (inclusive) to be sorted.
+   * @param min  the smallest element contained in the range.
+   * @param max  the largest element contained in the range.
+   */
+  protected void countSortFromTo(int from, int to, ${valueType} min, ${valueType} max) {
+    if (size == 0) {
+      return;
+    }
+    checkRangeFromTo(from, to, size);
+
+    ${valueType} width = (${valueType})(max - min + 1);
+
+    int[] counts = new int[width];
+    ${valueType}[] theElements = elements;
+    for (int i = from; i <= to;) {
+      counts[(theElements[i++] - min)]++;
+    }
+
+    int fromIndex = from;
+    ${valueType} val = min;
+    for (int i = 0; i < width; i++, val++) {
+      int c = counts[i];
+      if (c > 0) {
+        if (c == 1) {
+          theElements[fromIndex++] = val;
+        } else {
+          int toIndex = fromIndex + c - 1;
+          fillFromToWith(fromIndex, toIndex, val);
+          fromIndex = toIndex + 1;
+        }
+      }
+    }
+  }
+  #end
+
+  /**
+   * Returns the elements currently stored, including invalid elements between size and capacity, if any.
+   *
+   * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, <b>the array is not copied</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 ${valueType}[] elements() {
+    return elements;
+  }
+
+  /**
+   * Sets the receiver's elements to be the specified array (not a copy of it).
+   *
+   * The size and capacity of the list is the length of the array. <b>WARNING:</b> For efficiency reasons and to keep
+   * memory usage low, <b>the array is not copied</b>. So if subsequently you modify the specified array directly via
+   * the [] operator, be sure you know what you're doing.
+   *
+   * @param elements the new elements to be stored.
+   * @return the receiver itself.
+   */
+  public Abstract${valueTypeCap}List elements(${valueType}[] elements) {
+    this.elements = elements;
+    this.size = elements.length;
+    return this;
+  }
+
+  /**
+   * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new
+   * internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver.
+   *
+   * @param minCapacity the desired minimum capacity.
+   */
+  public void ensureCapacity(int minCapacity) {
+    elements = org.apache.mahout.math.Arrays.ensureCapacity(elements, minCapacity);
+  }
+
+  /**
+   * 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
+    // overridden for performance only.
+    if (!(otherObj instanceof ${valueTypeCap}ArrayList)) {
+      return super.equals(otherObj);
+    }
+    if (this == otherObj) {
+      return true;
+    }
+    if (otherObj == null) {
+      return false;
+    }
+    ${valueTypeCap}ArrayList other = (${valueTypeCap}ArrayList) otherObj;
+    if (size() != other.size()) {
+      return false;
+    }
+
+    ${valueType}[] theElements = elements();
+    ${valueType}[] otherElements = other.elements();
+    for (int i = size(); --i >= 0;) {
+      if (theElements[i] != otherElements[i]) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Applies a procedure to each element of the receiver, if any. Starts at index 0, moving rightwards.
+   *
+   * @param procedure the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise
+   *                  continues.
+   * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise.
+   */
+  public boolean forEach(${valueTypeCap}Procedure procedure) {
+    // overridden for performance only.
+    ${valueType}[] theElements = elements;
+    int theSize = size;
+
+    for (int i = 0; i < theSize;) {
+      if (!procedure.apply(theElements[i++])) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Returns the element at the specified position in the receiver.
+   *
+   * @param index index of element to return.
+   * @throws IndexOutOfBoundsException index is out of range (index &lt; 0 || index &gt;= size()).
+   */
+  public ${valueType} get(int index) {
+    // overridden for performance only.
+    if (index >= size || index < 0) {
+      throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+    }
+    return elements[index];
+  }
+
+  /**
+   * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions.
+   * Provided with invalid parameters this method may return invalid elements without throwing any exception! <b>You
+   * should only use this method when you are absolutely sure that the index is within bounds.</b> Precondition
+   * (unchecked): <tt>index &gt;= 0 && index &lt; size()</tt>.
+   *
+   * @param index index of element to return.
+   */
+  @Override
+  public ${valueType} getQuick(int index) {
+    return elements[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.
+   * @throws IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to ||
+   *                                   to&gt;=size())</tt>).
+   */
+  @Override
+  public int indexOfFromTo(${valueType} element, int from, int to) {
+    // overridden for performance only.
+    if (size == 0) {
+      return -1;
+    }
+    checkRangeFromTo(from, to, size);
+
+    ${valueType}[] theElements = elements;
+    for (int i = from; i <= to; i++) {
+      if (element == theElements[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.
+   * @throws IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to ||
+   *                                   to&gt;=size())</tt>).
+   */
+  @Override
+  public int lastIndexOfFromTo(${valueType} element, int from, int to) {
+    // overridden for performance only.
+    if (size == 0) {
+      return -1;
+    }
+    checkRangeFromTo(from, to, size);
+
+    ${valueType}[] theElements = elements;
+    for (int i = to; i >= from; i--) {
+      if (element == theElements[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
+   * @throws IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to ||
+   *                                   to&gt;=size())</tt>).
+   */
+  @Override
+  public Abstract${valueTypeCap}List partFromTo(int from, int to) {
+    if (size == 0) {
+      return new ${valueTypeCap}ArrayList(0);
+    }
+
+    checkRangeFromTo(from, to, size);
+
+    ${valueType}[] part = new ${valueType}[to - from + 1];
+    System.arraycopy(elements, from, part, 0, to - from + 1);
+    return new ${valueTypeCap}ArrayList(part);
+  }
+
+  /**
+   * 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.
+   */
+  @Override
+  public boolean removeAll(Abstract${valueTypeCap}List other) {
+    // overridden for performance only.
+    if (!(other instanceof ${valueTypeCap}ArrayList)) {
+      return super.removeAll(other);
+    }
+
+    /* There are two possibilities to do the thing
+       a) use other.indexOf(...)
+       b) sort other, then use other.binarySearch(...)
+
+       Let's try to figure out which one is faster. Let M=size, N=other.size, then
+       a) takes O(M*N) steps
+       b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+
+       Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+    */
+    if (other.isEmpty()) {
+      return false;
+    } //nothing to do
+    int limit = other.size() - 1;
+    int j = 0;
+    ${valueType}[] theElements = elements;
+    int mySize = size();
+
+    double N = (double) other.size();
+    double M = (double) mySize;
+    if ((N + M) * org.apache.mahout.math.jet.math.Arithmetic.log2(N) < M * N) {
+      // it is faster to sort other before searching in it
+      ${valueTypeCap}ArrayList sortedList = (${valueTypeCap}ArrayList) other.clone();
+      sortedList.quickSort();
+
+      for (int i = 0; i < mySize; i++) {
+        if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) {
+          theElements[j++] = theElements[i];
+        }
+      }
+    } else {
+      // it is faster to search in other without sorting
+      for (int i = 0; i < mySize; i++) {
+        if (other.indexOfFromTo(theElements[i], 0, limit) < 0) {
+          theElements[j++] = theElements[i];
+        }
+      }
+    }
+
+    boolean modified = (j != mySize);
+    setSize(j);
+    return modified;
+  }
+
+  /**
+   * 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.
+   */
+  @Override
+  public void replaceFromToWithFrom(int from, int to, Abstract${valueTypeCap}List other, int otherFrom) {
+    // overridden for performance only.
+    if (!(other instanceof ${valueTypeCap}ArrayList)) {
+      // slower
+      super.replaceFromToWithFrom(from, to, other, otherFrom);
+      return;
+    }
+    int length = to - from + 1;
+    if (length > 0) {
+      checkRangeFromTo(from, to, size());
+      checkRangeFromTo(otherFrom, otherFrom + length - 1, other.size());
+      System.arraycopy(((${valueTypeCap}ArrayList) other).elements, otherFrom, elements, from, length);
+    }
+  }
+
+  /**
+   * 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.
+   */
+  @Override
+  public boolean retainAll(Abstract${valueTypeCap}List other) {
+    // overridden for performance only.
+    if (!(other instanceof ${valueTypeCap}ArrayList)) {
+      return super.retainAll(other);
+    }
+
+    /* There are two possibilities to do the thing
+       a) use other.indexOf(...)
+       b) sort other, then use other.binarySearch(...)
+
+       Let's try to figure out which one is faster. Let M=size, N=other.size, then
+       a) takes O(M*N) steps
+       b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+
+       Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+    */
+    int limit = other.size() - 1;
+    int j = 0;
+    ${valueType}[] theElements = elements;
+    int mySize = size();
+
+    double N = (double) other.size();
+    double M = (double) mySize;
+    if ((N + M) * org.apache.mahout.math.jet.math.Arithmetic.log2(N) < M * N) {
+      // it is faster to sort other before searching in it
+      ${valueTypeCap}ArrayList sortedList = (${valueTypeCap}ArrayList) other.clone();
+      sortedList.quickSort();
+
+      for (int i = 0; i < mySize; i++) {
+        if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) {
+          theElements[j++] = theElements[i];
+        }
+      }
+    } else {
+      // it is faster to search in other without sorting
+      for (int i = 0; i < mySize; i++) {
+        if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) {
+          theElements[j++] = theElements[i];
+        }
+      }
+    }
+
+    boolean modified = (j != mySize);
+    setSize(j);
+    return modified;
+  }
+
+  /** Reverses the elements of the receiver. Last becomes first, second last becomes second first, and so on. */
+  @Override
+  public void reverse() {
+    // overridden for performance only.
+    int limit = size / 2;
+    int j = size - 1;
+
+    ${valueType}[] theElements = elements;
+    for (int i = 0; i < limit;) { //swap
+      ${valueType} tmp = theElements[i];
+      theElements[i++] = theElements[j];
+      theElements[j--] = tmp;
+    }
+  }
+
+  /**
+   * Replaces the element at the specified position in the receiver with the specified element.
+   *
+   * @param index   index of element to replace.
+   * @param element element to be stored at the specified position.
+   * @throws IndexOutOfBoundsException index is out of range (index &lt; 0 || index &gt;= size()).
+   */
+  @Override
+  public void set(int index, ${valueType} element) {
+    // overridden for performance only.
+    if (index >= size || index < 0) {
+      throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+    }
+    elements[index] = element;
+  }
+
+  /**
+   * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not
+   * check preconditions. Provided with invalid parameters this method may access invalid indexes without throwing any
+   * exception! <b>You should only use this method when you are absolutely sure that the index is within bounds.</b>
+   * Precondition (unchecked): <tt>index &gt;= 0 && index &lt; size()</tt>.
+   *
+   * @param index   index of element to replace.
+   * @param element element to be stored at the specified position.
+   */
+  @Override
+  public void setQuick(int index, ${valueType} element) {
+    elements[index] = element;
+  }
+
+  /**
+   * 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.
+   * @throws IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to ||
+   *                                   to&gt;=size())</tt>).
+   */
+  @Override
+  public void shuffleFromTo(int from, int to) {
+    // overridden for performance only.
+    if (size == 0) {
+      return;
+    }
+    checkRangeFromTo(from, to, size);
+
+    Uniform gen = new Uniform(new DRand(new Date()));
+    ${valueType}[] theElements = elements;
+    for (int i = from; i < to; i++) {
+      int random = gen.nextIntFromTo(i, to);
+
+      //swap(i, random)
+      ${valueType} tmpElement = theElements[random];
+      theElements[random] = theElements[i];
+      theElements[i] = tmpElement;
+    }
+  }
+
+  /**
+   * Sorts the specified range of the receiver into ascending order.
+   *
+   * The sorting algorithm is dynamically chosen according to the characteristics of the data set. Currently quicksort
+   * and countsort are considered. Countsort is not always applicable, but if applicable, it usually outperforms
+   * quicksort by a factor of 3-4.
+   *
+   * <p>Best case performance: O(N). <dt>Worst case performance: O(N^2) (a degenerated quicksort). <dt>Best case space
+   * requirements: 0 KB. <dt>Worst case space requirements: 40 KB.
+   *
+   * @param from the index of the first element (inclusive) to be sorted.
+   * @param to   the index of the last element (inclusive) to be sorted.
+   * @throws IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to ||
+   *                                   to&gt;=size())</tt>).
+   */
+  @Override
+  public void sortFromTo(int from, int to) {
+    /*
+    * Computes min and max and decides on this basis.
+    * In practice the additional overhead is very small compared to the potential gains.
+    */
+
+    if (size == 0) {
+      return;
+    }
+    checkRangeFromTo(from, to, size);
+
+    // determine minimum and maximum.
+    ${valueType} min = elements[from];
+    ${valueType} max = elements[from];
+
+    ${valueType}[] theElements = elements;
+    for (int i = from + 1; i <= to;) {
+      ${valueType} elem = theElements[i++];
+      if (elem > max) {
+        max = elem;
+      } else if (elem < min) {
+        min = elem;
+      }
+    }
+
+    #if ($valueType == 'byte' || $valueType == 'char' || $valueType == 'int') 
+    // try to figure out which option is fastest.
+    double N = (double) to - (double) from + 1.0;
+    double quickSortEstimate = N * Math.log(N) / 0.6931471805599453; // O(N*log(N,base=2)) ; ln(2)=0.6931471805599453
+
+    double width = (double) max - (double) min + 1.0;
+    double countSortEstimate = Math.max(width, N); // O(Max(width,N))
+
+    int widthThreshold = 10000; // never consider options resulting in outrageous memory allocations.
+    if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
+      countSortFromTo(from, to, min, max);
+    } else {
+      quickSortFromTo(from, to);
+    }
+    #else
+    quickSortFromTo(from, to);
+    #end
+  }
+
+  /**
+   * Trims the capacity of the receiver to be the receiver's current size. Releases any superfluous internal memory. An
+   * application can use this operation to minimize the storage of the receiver.
+   */
+  @Override
+  public void trimToSize() {
+    elements = org.apache.mahout.math.Arrays.trimToCapacity(elements, size());
+  }
+}

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Arrays.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Arrays.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Arrays.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Arrays.java Mon Dec 28 21:30:05 2009
@@ -15,12 +15,8 @@
  * @see org.apache.mahout.math.Sorting
  *
  */
+public final class Arrays {
 
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
-public class Arrays {
-
-  /** Makes this class non instantiable, but still let's others inherit from it. */
   private Arrays() {
   }
 

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/PersistentObject.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/PersistentObject.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/PersistentObject.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/PersistentObject.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -14,9 +32,6 @@
  * If this class inherits from <tt>com.objy.db.app.ooObj</tt> then all subclasses are <i>additionally</i> serializable with the Objectivity ODBMS persistance mechanism.
  * Thus, by modifying the inheritance of this class the entire tree of subclasses can be switched to Objectivity compatibility (and back) with minimum effort.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public abstract class PersistentObject implements java.io.Serializable, Cloneable {
 
   /** Not yet commented. */

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java Mon Dec 28 21:30:05 2009
@@ -1,4 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 /*
+
 Copyright � 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
 is hereby granted without fee, provided that the above copyright notice appear in all copies and 
@@ -30,15 +50,11 @@
  * @see java.util.Arrays
  *
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
-public class Sorting {
+public final class Sorting {
 
   private static final int SMALL = 7;
   private static final int MEDIUM = 40;
 
-  /** Makes this class non instantiable, but still let's others inherit from it. */
   private Sorting() {
   }
 
@@ -267,10 +283,10 @@
    * @see java.util.Arrays
    * @see java.util.Comparator
    */
-  public static int binarySearchFromTo(Object[] list, Object key, int from, int to, Comparator<Object> comparator) {
+  public static <T> int binarySearchFromTo(T[] list, T key, int from, int to, Comparator<? super T> comparator) {
     while (from <= to) {
       int mid = (from + to) / 2;
-      Object midVal = list[mid];
+      T midVal = list[mid];
       int cmp = comparator.compare(midVal, key);
 
       if (cmp < 0) {
@@ -316,37 +332,6 @@
     return -(from + 1);  // key not found.
   }
 
-  /**
-   * Generically searches the list for the specified value using the binary search algorithm.  The list must
-   * <strong>must</strong> be sorted (as by the sort method) prior to making this call.  If it is not sorted, the
-   * results are undefined: in particular, the call may enter an infinite loop.  If the list contains multiple elements
-   * equal to the specified key, there is no guarantee which of the multiple elements will be found.
-   *
-   * @param from the leftmost search position, inclusive.
-   * @param to   the rightmost search position, inclusive.
-   * @return index of the search key, if it is contained in the list; otherwise, <tt>(-(<i>insertion point</i>) -
-   *         1)</tt>. The <i>insertion point</i> is defined as the the point at which the value would be inserted into
-   *         the list: the index of the first element greater than the key, or <tt>list.length</tt>, if all elements in
-   *         the list are less than the specified key.  Note that this guarantees that the return value will be &gt;= 0
-   *         if and only if the key is found.
-   * @see java.util.Arrays
-   */
-  public static int binarySearchFromTo(int from, int to, IntComparator comp) {
-    int dummy = 0;
-    while (from <= to) {
-      int mid = (from + to) / 2;
-      int comparison = comp.compare(dummy, mid);
-      if (comparison < 0) {
-        from = mid + 1;
-      } else if (comparison > 0) {
-        to = mid - 1;
-      } else {
-        return mid;
-      } // key found
-    }
-    return -(from + 1);  // key not found.
-  }
-
   private static int lower_bound(int[] array, int first, int last, int x) {
     int len = last - first;
     while (len > 0) {
@@ -499,17 +484,17 @@
   }
 
   /** Returns the index of the median of the three indexed chars. */
-  private static int med3(Object[] x, int a, int b, int c) {
-    int ab = ((Comparable<Object>) x[a]).compareTo(x[b]);
-    int ac = ((Comparable<Object>) x[a]).compareTo(x[c]);
-    int bc = ((Comparable<Object>) x[b]).compareTo(x[c]);
+  private static <T extends Comparable<? super T>> int med3(T[] x, int a, int b, int c) {
+    int ab = x[a].compareTo(x[b]);
+    int ac = x[a].compareTo(x[c]);
+    int bc = x[b].compareTo(x[c]);
     return (ab < 0 ?
         (bc < 0 ? b : ac < 0 ? c : a) :
         (bc > 0 ? b : ac > 0 ? c : a));
   }
 
   /** Returns the index of the median of the three indexed chars. */
-  private static int med3(Object[] x, int a, int b, int c, Comparator<Object> comp) {
+  private static <T> int med3(T[] x, int a, int b, int c, Comparator<? super T> comp) {
     int ab = comp.compare(x[a], x[b]);
     int ac = comp.compare(x[a], x[c]);
     int bc = comp.compare(x[b], x[c]);
@@ -1449,53 +1434,6 @@
   }
 
   /**
-   * Sorts the specified range of the specified array of elements.
-   *
-   * <p>This sort is guaranteed to be <i>stable</i>:  equal elements will not be reordered as a result of the sort.<p>
-   *
-   * 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.
-   *
-   * @param a         the array to be sorted.
-   * @param fromIndex the index of the first element (inclusive) to be sorted.
-   * @param toIndex   the index of the last element (exclusive) to be sorted.
-   * @throws IllegalArgumentException       if <tt>fromIndex &gt; toIndex</tt>
-   * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or <tt>toIndex &gt; a.length</tt>
-   */
-  public static void mergeSortInPlace(int[] a, int fromIndex, int toIndex) {
-    rangeCheck(a.length, fromIndex, toIndex);
-    int length = toIndex - fromIndex;
-
-    // Insertion sort on smallest arrays
-    if (length < SMALL) {
-      for (int i = fromIndex; i < toIndex; i++) {
-        for (int j = i; j > fromIndex && a[j - 1] > a[j]; j--) {
-          int tmp = a[j];
-          a[j] = a[j - 1];
-          a[j - 1] = tmp;
-        }
-      }
-      return;
-    }
-
-    // Recursively sort halves
-    int mid = (fromIndex + toIndex) / 2;
-    mergeSortInPlace(a, fromIndex, mid);
-    mergeSortInPlace(a, mid, toIndex);
-
-    // If list is already sorted, nothing left to do.  This is an
-    // optimization that results in faster sorts for nearly ordered lists.
-    if (a[mid - 1] <= a[mid]) {
-      return;
-    }
-
-    // Merge sorted halves
-    //jal.INT.Sorting.inplace_merge(a, fromIndex, mid, toIndex);
-    inplace_merge(a, fromIndex, mid, toIndex);
-  }
-
-  /**
    * Sorts the specified range of the specified array of elements according to the order induced by the specified
    * comparator.  All elements in the range must be <i>mutually comparable</i> by the specified comparator (that is,
    * <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> for any elements <tt>e1</tt> and
@@ -1657,7 +1595,7 @@
    *
    * @param a the array to be sorted.
    */
-  public static void quickSort(Object[] a) {
+  public static <T extends Comparable<? super T>>  void quickSort(T[] a) {
     quickSort1(a, 0, a.length);
   }
 
@@ -1673,7 +1611,7 @@
    * @throws IllegalArgumentException       if <tt>fromIndex &gt; toIndex</tt>
    * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or <tt>toIndex &gt; a.length</tt>
    */
-  public static void quickSort(Object[] a, int fromIndex, int toIndex) {
+  public static <T extends Comparable<? super T>> void quickSort(T[] a, int fromIndex, int toIndex) {
     rangeCheck(a.length, fromIndex, toIndex);
     quickSort1(a, fromIndex, toIndex - fromIndex);
   }
@@ -1698,7 +1636,7 @@
    * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or <tt>toIndex &gt; a.length</tt>
    * @see Comparator
    */
-  public static void quickSort(Object[] a, int fromIndex, int toIndex, Comparator<Object> c) {
+  public static <T> void quickSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) {
     rangeCheck(a.length, fromIndex, toIndex);
     quickSort1(a, fromIndex, toIndex - fromIndex, c);
   }
@@ -1720,7 +1658,7 @@
    * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or <tt>toIndex &gt; a.length</tt>
    * @see Comparator
    */
-  public static void quickSort(Object[] a, Comparator<Object> c) {
+  public static <T extends Comparable<? super T>> void quickSort(T[] a, Comparator<? super T> c) {
     quickSort1(a, 0, a.length, c);
   }
 
@@ -2142,11 +2080,11 @@
   }
 
   /** Sorts the specified sub-array of chars into ascending order. */
-  private static void quickSort1(Object[] x, int off, int len) {
+  private static <T extends Comparable<? super T>> void quickSort1(T[] x, int off, int len) {
     // Insertion sort on smallest arrays
     if (len < SMALL) {
       for (int i = off; i < len + off; i++) {
-        for (int j = i; j > off && ((Comparable<Object>) x[j - 1]).compareTo(x[j]) > 0; j--) {
+        for (int j = i; j > off && x[j - 1].compareTo(x[j]) > 0; j--) {
           swap(x, j, j - 1);
         }
       }
@@ -2166,19 +2104,19 @@
       }
       m = med3(x, l, m, n); // Mid-size, med of 3
     }
-    Comparable<?> v = (Comparable<?>) x[m];
+    T v = x[m];
 
     // Establish Invariant: v* (<v)* (>v)* v*
     int a = off, b = a, c = off + len - 1, d = c;
     while (true) {
       int comparison;
-      while (b <= c && (comparison = ((Comparable<Object>) x[b]).compareTo(v)) <= 0) {
+      while (b <= c && (comparison = x[b].compareTo(v)) <= 0) {
         if (comparison == 0) {
           swap(x, a++, b);
         }
         b++;
       }
-      while (c >= b && (comparison = ((Comparable<Object>) x[c]).compareTo(v)) >= 0) {
+      while (c >= b && (comparison = x[c].compareTo(v)) >= 0) {
         if (comparison == 0) {
           swap(x, c, d--);
         }
@@ -2207,7 +2145,7 @@
   }
 
   /** Sorts the specified sub-array of chars into ascending order. */
-  private static void quickSort1(Object[] x, int off, int len, Comparator<Object> comp) {
+  private static <T> void quickSort1(T[] x, int off, int len, Comparator<? super T> comp) {
     // Insertion sort on smallest arrays
     if (len < SMALL) {
       for (int i = off; i < len + off; i++) {
@@ -2231,7 +2169,7 @@
       }
       m = med3(x, l, m, n, comp); // Mid-size, med of 3
     }
-    Object v = x[m];
+    T v = x[m];
 
     // Establish Invariant: v* (<v)* (>v)* v*
     int a = off, b = a, c = off + len - 1, d = c;

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/BooleanProcedure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/BooleanProcedure.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/BooleanProcedure.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/BooleanProcedure.java Mon Dec 28 21:30:05 2009
@@ -12,11 +12,7 @@
 /**
  * Interface that represents a procedure object: a procedure that takes a single argument and does not return a value.
  *
- * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public interface BooleanProcedure {
 
   /**

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/DoubleFunction.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/DoubleFunction.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/DoubleFunction.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/DoubleFunction.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 package org.apache.mahout.math.function;
 
 /*
@@ -12,11 +31,7 @@
 /**
  * Interface that represents a function object: a function that takes a single argument and returns a single value.
  *
- * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public interface DoubleFunction {
 
   /**

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/IntFunction.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/IntFunction.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/IntFunction.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/IntFunction.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.mahout.math.function;
 
 /*
@@ -11,12 +29,7 @@
 
 /**
  * Interface that represents a function object: a function that takes a single argument and returns a single value.
- *
- * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public interface IntFunction {
 
   /**

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/ObjectProcedure.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/ObjectProcedure.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/ObjectProcedure.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/function/ObjectProcedure.java Mon Dec 28 21:30:05 2009
@@ -11,13 +11,8 @@
 
 /**
  * Interface that represents a procedure object: a procedure that takes a single argument and does not return a value.
- *
- * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
-public interface ObjectProcedure {
+public interface ObjectProcedure<T> {
 
   /**
    * Applies a procedure to an argument. Optionally can return a boolean flag to inform the object calling the
@@ -30,5 +25,5 @@
    * @param element element passed to the procedure.
    * @return a flag  to inform the object calling the procedure.
    */
-  boolean apply(Object element);
+  boolean apply(T element);
 }

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Arithmetic.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -11,9 +29,6 @@
 /**
  * Arithmetic functions.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public class Arithmetic extends Constants {
   // for method stirlingCorrection(...)
   private static final double[] stirlingCorrection = {
@@ -356,47 +371,6 @@
     return (0.5 * (b0 - b2));
   }
 
-  /** Returns the factorial of the argument. */
-  private static long fac1(int j) {
-    long i = j;
-    if (j < 0) {
-      i = Math.abs(j);
-    }
-    if (i > longFactorials.length) {
-      throw new IllegalArgumentException("Overflow");
-    }
-
-    long d = 1;
-    while (i > 1) {
-      d *= i--;
-    }
-
-    if (j < 0) {
-      return -d;
-    } else {
-      return d;
-    }
-  }
-
-  /** Returns the factorial of the argument. */
-  private static double fac2(int j) {
-    long i = j;
-    if (j < 0) {
-      i = Math.abs(j);
-    }
-
-    double d = 1.0;
-    while (i > 1) {
-      d *= i--;
-    }
-
-    if (j < 0) {
-      return -d;
-    } else {
-      return d;
-    }
-  }
-
   /**
    * Instantly returns the factorial <tt>k!</tt>.
    *

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Constants.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Constants.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Constants.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/math/Constants.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 /*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -11,9 +30,6 @@
 /**
  * Defines some useful constants.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public class Constants {
   /*
    * machine constants
@@ -55,8 +71,6 @@
  * THPIO4 =  2.35619449019234492885           3*pi/4
  * TWOOPI =  6.36619772367581343075535E-1     2/pi
  */
-
-  /** Makes this class non instantiable, but still let's others inherit from it. */
   protected Constants() {
   }
 }

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractContinousDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractContinousDistribution.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractContinousDistribution.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractContinousDistribution.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -9,15 +27,8 @@
 package org.apache.mahout.math.jet.random;
 
 /**
- * Abstract base class for all continous distributions.
+ * Abstract base class for all continuous distributions.
  *
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public abstract class AbstractContinousDistribution extends AbstractDistribution {
-
-  /** Makes this class non instantiable, but still let's others inherit from it. */
-  protected AbstractContinousDistribution() {
-  }
 }

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/AbstractDistribution.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright � 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -9,12 +27,12 @@
 package org.apache.mahout.math.jet.random;
 
 import org.apache.mahout.math.PersistentObject;
+import org.apache.mahout.math.function.DoubleFunction;
+import org.apache.mahout.math.function.IntFunction;
 import org.apache.mahout.math.jet.random.engine.RandomEngine;
 
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public abstract class AbstractDistribution extends PersistentObject
-    implements org.apache.mahout.math.function.DoubleFunction, org.apache.mahout.math.function.IntFunction {
+    implements DoubleFunction, IntFunction {
 
   protected RandomEngine randomGenerator;
 
@@ -78,6 +96,22 @@
   public int nextInt() {
     return (int) Math.round(nextDouble());
   }
+  
+  public byte nextByte() {
+    return (byte)nextInt();
+  }
+  
+  public char nextChar() {
+    return (char)nextInt();
+  }
+  
+  public long nextLong() {
+    return Math.round(nextDouble());
+  }
+  
+  public float nextFloat() {
+    return (float)nextDouble();
+  }
 
   /** Sets the uniform random generator internally used. */
   protected void setRandomGenerator(RandomEngine randomGenerator) {

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/Uniform.java Mon Dec 28 21:30:05 2009
@@ -11,8 +11,6 @@
 import org.apache.mahout.math.jet.random.engine.MersenneTwister;
 import org.apache.mahout.math.jet.random.engine.RandomEngine;
 
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public class Uniform extends AbstractContinousDistribution {
 
   private double min;
@@ -91,7 +89,8 @@
   }
 
   /**
-   * Returns a uniformly distributed random number in the closed interval <tt>[from,to]</tt> (including <tt>from</tt>
+   * Returns a uniformly distributed random number in the closed interval
+   *  <tt>[from,to]</tt> (including <tt>from</tt>
    * and <tt>to</tt>). Pre conditions: <tt>from &lt;= to</tt>.
    */
   public int nextIntFromTo(int from, int to) {

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/DRand.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/DRand.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/DRand.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/DRand.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * u
+ /*
+Copyright � 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
+is hereby granted without fee, provided that the above copyright notice appear in all copies and 
+that both that copyright notice and this permission notice appear in supporting documentation. 
+CERN makes no representations about the suitability of this software for any purpose. 
+It is provided "as is" without expressed or implied warranty.
+*/
 /*
 Copyright � 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -36,9 +61,6 @@
  * @see MersenneTwister
  * @see java.util.Random
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public class DRand extends RandomEngine {
 
   private int current;

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/random/engine/RandomEngine.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright � 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -9,6 +27,8 @@
 package org.apache.mahout.math.jet.random.engine;
 
 import org.apache.mahout.math.PersistentObject;
+import org.apache.mahout.math.function.DoubleFunction;
+import org.apache.mahout.math.function.IntFunction;
 
 /**
  * Abstract base class for uniform pseudo-random number generating engines.
@@ -32,17 +52,8 @@
  * @see MersenneTwister64
  * @see java.util.Random
  */
-
-//public abstract class RandomEngine extends edu.cornell.lassp.houle.RngPack.RandomSeedable implements org.apache.mahout.math.function.DoubleFunction, org.apache.mahout.math.function.IntFunction {
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
 public abstract class RandomEngine extends PersistentObject
-    implements org.apache.mahout.math.function.DoubleFunction, org.apache.mahout.math.function.IntFunction {
-
-  /** Makes this class non instantiable, but still let's others inherit from it. */
-  protected RandomEngine() {
-  }
+    implements DoubleFunction, IntFunction {
 
   /**
    * Equivalent to <tt>raw()</tt>. This has the effect that random engines can now be used as function objects,

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/DoubleQuantileEstimator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/DoubleQuantileEstimator.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/DoubleQuantileEstimator.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/DoubleQuantileEstimator.java Mon Dec 28 21:30:05 2009
@@ -11,7 +11,6 @@
 import org.apache.mahout.math.PersistentObject;
 import org.apache.mahout.math.function.DoubleProcedure;
 import org.apache.mahout.math.list.DoubleArrayList;
-import org.apache.mahout.math.list.ObjectArrayList;
 
 /**
  * The abstract base class for approximate quantile finders computing quantiles over a sequence of <tt>double</tt>
@@ -141,8 +140,14 @@
     if (this.bufferSet != null) {
       copy.bufferSet = (DoubleBufferSet) copy.bufferSet.clone();
       if (this.currentBufferToFill != null) {
-        int index = new ObjectArrayList(this.bufferSet.buffers).indexOf(this.currentBufferToFill, true);
-        copy.currentBufferToFill = copy.bufferSet.buffers[index];
+        int index;
+        for (index = 0; index < bufferSet.buffers.length; index ++) {
+          if (bufferSet.buffers[index].equals(currentBufferToFill)) {
+            copy.currentBufferToFill = copy.bufferSet.buffers[index];
+            return copy;
+          }
+        }
+        throw new IllegalStateException("current buffer not on the list.");
       }
     }
     return copy;

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/quantile/UnknownDoubleQuantileEstimator.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 /*
 Copyright � 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -8,10 +26,10 @@
 */
 package org.apache.mahout.math.jet.stat.quantile;
 
+import org.apache.mahout.math.Sorting;
 import org.apache.mahout.math.jet.random.engine.RandomEngine;
 import org.apache.mahout.math.jet.random.sampling.WeightedRandomSampler;
 import org.apache.mahout.math.list.DoubleArrayList;
-import org.apache.mahout.math.list.ObjectArrayList;
 
 import java.util.Comparator;
 
@@ -166,10 +184,10 @@
 
   /** To do. This could faster be done without sorting (min and second min). */
   private static void sortAscendingByLevel(DoubleBuffer[] fullBuffers) {
-    new ObjectArrayList(fullBuffers).quickSortFromTo(0, fullBuffers.length - 1,
-        new Comparator<Object>() {
+    Sorting.quickSort(fullBuffers, 0, fullBuffers.length - 1,
+        new Comparator<DoubleBuffer>() {
           @Override
-          public int compare(Object o1, Object o2) {
+          public int compare(DoubleBuffer o1, DoubleBuffer o2) {
             int l1 = ((Buffer) o1).level();
             int l2 = ((Buffer) o2).level();
             return l1 < l2 ? -1 : l1 == l2 ? 0 : 1;

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractList.java?rev=894251&r1=894250&r2=894251&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractList.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractList.java Mon Dec 28 21:30:05 2009
@@ -1,3 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+Copyright � 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
+is hereby granted without fee, provided that the above copyright notice appear in all copies and 
+that both that copyright notice and this permission notice appear in supporting documentation. 
+CERN makes no representations about the suitability of this software for any purpose. 
+It is provided "as is" without expressed or implied warranty.
+*/
 /*
 Copyright 1999 CERN - European Organization for Nuclear Research.
 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
@@ -8,7 +34,7 @@
 */
 package org.apache.mahout.math.list;
 
-import java.util.Collection;
+import org.apache.mahout.math.PersistentObject;
 
 /**
  Abstract base class for resizable lists holding objects or primitive data types such as <code>int</code>, <code>float</code>, etc.
@@ -22,33 +48,12 @@
  @see      java.util.Vector
  @see      java.util.Arrays
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
-public abstract class AbstractList<T> extends AbstractCollection<T> {
-
-  /**
-   * Appends all of the elements of the specified Collection to the receiver.
-   *
-   * @throws ClassCastException if an element in the collection is not of the same parameter type of the receiver.
-   */
-  public void addAllOf(Collection<T> collection) {
-    this.beforeInsertAllOf(size(), collection);
-  }
-
-  /**
-   * Inserts all elements of the specified collection before the specified position into the receiver. Shifts the
-   * element currently at that position (if any) and any subsequent elements to the right (increases their indices).
-   *
-   * @param index      index before which to insert first element from the specified collection.
-   * @param collection the collection to be inserted
-   * @throws ClassCastException        if an element in the collection is not of the same parameter type of the
-   *                                   receiver.
-   * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
-   */
-  public void beforeInsertAllOf(int index, Collection<T> collection) {
-    this.beforeInsertDummies(index, collection.size());
-    this.replaceFromWith(index, collection);
+public abstract class AbstractList extends PersistentObject {
+  
+  public abstract int size();
+  
+  public boolean isEmpty() {
+    return 0 == size();
   }
 
   /**
@@ -87,7 +92,6 @@
    * Removes all elements from the receiver.  The receiver will be empty after this call returns, but keep its current
    * capacity.
    */
-  @Override
   public void clear() {
     removeFromTo(0, size() - 1);
   }
@@ -177,17 +181,6 @@
    */
   public abstract void removeFromTo(int fromIndex, int toIndex);
 
-  /**
-   * 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
-   * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt;= size()</tt>.
-   */
-  public abstract void replaceFromWith(int from, Collection<T> other);
-
   /** Reverses the elements of the receiver. Last becomes first, second last becomes second first, and so on. */
   public abstract void reverse();
 

Added: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractObjectList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractObjectList.java?rev=894251&view=auto
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractObjectList.java (added)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/list/AbstractObjectList.java Mon Dec 28 21:30:05 2009
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+Copyright 1999 CERN - European Organization for Nuclear Research.
+Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
+is hereby granted without fee, provided that the above copyright notice appear in all copies and 
+that both that copyright notice and this permission notice appear in supporting documentation. 
+CERN makes no representations about the suitability of this software for any purpose. 
+It is provided "as is" without expressed or implied warranty.
+*/
+package org.apache.mahout.math.list;
+
+import java.util.Collection;
+
+/**
+ Abstract base class for resizable lists holding objects or primitive data types such as <code>int</code>, <code>float</code>, etc.
+ First see the <a href="package-summary.html">package summary</a> and javadoc <a href="package-tree.html">tree view</a> to get the broad picture.
+ <p>
+ <b>Note that this implementation is not synchronized.</b>
+
+ @author wolfgang.hoschek@cern.ch
+ @version 1.0, 09/24/99
+ @see     ArrayList
+ @see      java.util.Vector
+ @see      java.util.Arrays
+ */
+public abstract class AbstractObjectList<T> extends AbstractList {
+
+  /**
+   * Appends all of the elements of the specified Collection to the receiver.
+   *
+   * @throws ClassCastException if an element in the collection is not of the same parameter type of the receiver.
+   */
+  public void addAllOf(Collection<T> collection) {
+    this.beforeInsertAllOf(size(), collection);
+  }
+
+  /**
+   * Inserts all elements of the specified collection before the specified position into the receiver. Shifts the
+   * element currently at that position (if any) and any subsequent elements to the right (increases their indices).
+   *
+   * @param index      index before which to insert first element from the specified collection.
+   * @param collection the collection to be inserted
+   * @throws ClassCastException        if an element in the collection is not of the same parameter type of the
+   *                                   receiver.
+   * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
+   */
+  public void beforeInsertAllOf(int index, Collection<T> collection) {
+    this.beforeInsertDummies(index, collection.size());
+    this.replaceFromWith(index, collection);
+  }
+
+
+  /**
+   * 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 shortens the list by
+   * <tt>(to - from + 1)</tt> elements.
+   *
+   * @param fromIndex index of first element to be removed.
+   * @param toIndex   index of last element to be removed.
+   * @throws IndexOutOfBoundsException if <tt>(from&lt;0 || from&gt;to || to&gt;=size()) && to!=from-1</tt>.
+   */
+  public abstract void removeFromTo(int fromIndex, int toIndex);
+
+  /**
+   * 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
+   * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt;= size()</tt>.
+   */
+  public abstract void replaceFromWith(int from, Collection<T> other);
+}



Mime
View raw message