Save This Page
Home » mahout-collections-1.0-src » org.apache.mahout.math.list.adapter » [javadoc | source]
    1   /*
    2   Copyright ? 1999 CERN - European Organization for Nuclear Research.
    3   Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
    4   is hereby granted without fee, provided that the above copyright notice appear in all copies and 
    5   that both that copyright notice and this permission notice appear in supporting documentation. 
    6   CERN makes no representations about the suitability of this software for any purpose. 
    7   It is provided "as is" without expressed or implied warranty.
    8   */
    9   package org.apache.mahout.math.list.adapter;
   10   
   11   import org.apache.mahout.math.list.AbstractDoubleList;
   12   
   13   import java.util.AbstractList;
   14   /**
   15    * Adapter that permits an {@link org.apache.mahout.math.list.AbstractDoubleList} to be viewed and treated as a JDK 1.2 {@link java.util.AbstractList}.
   16    * Makes the contained list compatible with the JDK 1.2 Collections Framework.
   17    * <p>
   18    * Any attempt to pass elements other than <tt>java.lang.Number</tt> to setter methods will throw a <tt>java.lang.ClassCastException</tt>.
   19    * <tt>java.lang.Number.doubleValue()</tt> is used to convert objects into primitive values which are then stored in the backing templated list.
   20    * Getter methods return <tt>java.lang.Double</tt> objects.
   21    */
   22   
   23   /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
   24   @Deprecated
   25   public class DoubleListAdapter extends AbstractList<Double> {
   26   
   27     private final AbstractDoubleList content;
   28   
   29     /** Constructs a list backed by the specified content list. */
   30     public DoubleListAdapter(AbstractDoubleList content) {
   31       this.content = content;
   32     }
   33   
   34     /**
   35      * Inserts the specified element at the specified position in this list (optional operation).  Shifts the element
   36      * currently at that position (if any) and any subsequent elements to the right (adds one to their indices).<p>
   37      *
   38      * @param index   index at which the specified element is to be inserted.
   39      * @param element element to be inserted.
   40      * @throws ClassCastException        if the class of the specified element prevents it from being added to this list.
   41      * @throws IllegalArgumentException  if some aspect of the specified element prevents it from being added to this
   42      *                                   list.
   43      * @throws IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
   44      */
   45     @Override
   46     public void add(int index, Double element) {
   47       content.beforeInsert(index, element);
   48       modCount++;
   49     }
   50   
   51     /**
   52      * Returns the element at the specified position in this list.
   53      *
   54      * @param index index of element to return.
   55      * @return the element at the specified position in this list.
   56      * @throws IndexOutOfBoundsException if the given index is out of range (<tt>index &lt; 0 || index &gt;=
   57      *                                   size()</tt>).
   58      */
   59     @Override
   60     public Double get(int index) {
   61       return content.get(index);
   62     }
   63   
   64   
   65     /**
   66      * Removes the element at the specified position in this list (optional operation).  Shifts any subsequent elements to
   67      * the left (subtracts one from their indices).  Returns the element that was removed from the list.<p>
   68      *
   69      * @param index the index of the element to remove.
   70      * @return the element previously at the specified position.
   71      * @throws IndexOutOfBoundsException if the specified index is out of range (<tt>index &lt; 0 || index &gt;=
   72      *                                   size()</tt>).
   73      */
   74     @Override
   75     public Double remove(int index) {
   76       Double old = get(index);
   77       content.remove(index);
   78       modCount++;
   79       return old;
   80     }
   81   
   82     /**
   83      * Replaces the element at the specified position in this list with the specified element (optional operation). <p>
   84      *
   85      * @param index   index of element to replace.
   86      * @param element element to be stored at the specified position.
   87      * @return the element previously at the specified position.
   88      * @throws ClassCastException        if the class of the specified element prevents it from being added to this list.
   89      * @throws IllegalArgumentException  if some aspect of the specified element prevents it from being added to this
   90      *                                   list.
   91      * @throws IndexOutOfBoundsException if the specified index is out of range (<tt>index &lt; 0 || index &gt;=
   92      *                                   size()</tt>).
   93      */
   94   
   95     @Override
   96     public Double set(int index, Double element) {
   97       Double old = get(index);
   98       content.set(index, element);
   99       return old;
  100     }
  101   
  102     /**
  103      * Returns the number of elements in this list.
  104      *
  105      * @return the number of elements in this list.
  106      */
  107     @Override
  108     public int size() {
  109       return content.size();
  110     }
  111   
  112   }

Save This Page
Home » mahout-collections-1.0-src » org.apache.mahout.math.list.adapter » [javadoc | source]