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.AbstractLongList;
   12   
   13   import java.util.AbstractList;
   14   /**
   15    * Adapter that permits an {@link org.apache.mahout.math.list.AbstractLongList} 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.longValue()</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.Long</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 LongListAdapter extends AbstractList<Long> {
   26   
   27     private final AbstractLongList content;
   28   
   29     /** Constructs a list backed by the specified content list. */
   30     public LongListAdapter(AbstractLongList 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, Long 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 Long get(int index) {
   61       return content.get(index);
   62     }
   63   
   64     /**
   65      * Removes the element at the specified position in this list (optional operation).  Shifts any subsequent elements to
   66      * the left (subtracts one from their indices).  Returns the element that was removed from the list.<p>
   67      *
   68      * @param index the index of the element to remove.
   69      * @return the element previously at the specified position.
   70      * @throws IndexOutOfBoundsException if the specified index is out of range (<tt>index &lt; 0 || index &gt;=
   71      *                                   size()</tt>).
   72      */
   73     @Override
   74     public Long remove(int index) {
   75       Long old = get(index);
   76       content.remove(index);
   77       modCount++;
   78       return old;
   79     }
   80   
   81     /**
   82      * Replaces the element at the specified position in this list with the specified element (optional operation). <p>
   83      *
   84      * @param index   index of element to replace.
   85      * @param element element to be stored at the specified position.
   86      * @return the element previously at the specified position.
   87      * @throws ClassCastException        if the class of the specified element prevents it from being added to this list.
   88      * @throws IllegalArgumentException  if some aspect of the specified element prevents it from being added to this
   89      *                                   list.
   90      * @throws IndexOutOfBoundsException if the specified index is out of range (<tt>index &lt; 0 || index &gt;=
   91      *                                   size()</tt>).
   92      */
   93   
   94     @Override
   95     public Long set(int index, Long element) {
   96       Long old = get(index);
   97       content.set(index, element);
   98       return old;
   99     }
  100   
  101     /**
  102      * Returns the number of elements in this list.
  103      *
  104      * @return the number of elements in this list.
  105      */
  106     @Override
  107     public int size() {
  108       return content.size();
  109     }
  110   
  111   }

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