Package loci.poi.util

Class DoubleList


  • public class DoubleList
    extends Object
    A List of double's; as full an implementation of the java.util.List interface as possible, with an eye toward minimal creation of objects the mimicry of List is as follows:
    • if possible, operations designated 'optional' in the List interface are attempted
    • wherever the List interface refers to an Object, substitute double
    • wherever the List interface refers to a Collection or List, substitute DoubleList
    the mimicry is not perfect, however:
    • operations involving Iterators or ListIterators are not supported
    • remove(Object) becomes removeValue to distinguish it from remove(int index)
    • subList is not supported
    Author:
    Marc Johnson
    • Constructor Summary

      Constructors 
      Constructor Description
      DoubleList()
      create an DoubleList of default size
      DoubleList​(int initialCapacity)
      create an DoubleList with a predefined initial size
      DoubleList​(DoubleList list)
      create a copy of an existing DoubleList
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(double value)
      Appends the specified element to the end of this list
      void add​(int index, double value)
      add the specfied value at the specified index
      boolean addAll​(int index, DoubleList c)
      Inserts all of the elements in the specified collection into this list at the specified position.
      boolean addAll​(DoubleList c)
      Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.
      void clear()
      Removes all of the elements from this list.
      boolean contains​(double o)
      Returns true if this list contains the specified element.
      boolean containsAll​(DoubleList c)
      Returns true if this list contains all of the elements of the specified collection.
      boolean equals​(Object o)
      Compares the specified object with this list for equality.
      double get​(int index)
      Returns the element at the specified position in this list.
      int hashCode()
      THIS MOST LIKELY DOES NOT WORK Returns the hash code value for this list.
      int indexOf​(double o)
      Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
      boolean isEmpty()
      Returns true if this list contains no elements.
      int lastIndexOf​(double o)
      Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
      double remove​(int index)
      Removes the element at the specified position in this list.
      boolean removeAll​(DoubleList c)
      Removes from this list all the elements that are contained in the specified collection
      boolean removeValue​(double o)
      Removes the first occurrence in this list of the specified element (optional operation).
      boolean retainAll​(DoubleList c)
      Retains only the elements in this list that are contained in the specified collection.
      double set​(int index, double element)
      Replaces the element at the specified position in this list with the specified element
      int size()
      Returns the number of elements in this list.
      double[] toArray()
      Returns an array containing all of the elements in this list in proper sequence.
      double[] toArray​(double[] a)
      Returns an array containing all of the elements in this list in proper sequence.
    • Constructor Detail

      • DoubleList

        public DoubleList()
        create an DoubleList of default size
      • DoubleList

        public DoubleList​(DoubleList list)
        create a copy of an existing DoubleList
        Parameters:
        list - the existing DoubleList
      • DoubleList

        public DoubleList​(int initialCapacity)
        create an DoubleList with a predefined initial size
        Parameters:
        initialCapacity - the size for the internal array
    • Method Detail

      • add

        public void add​(int index,
                        double value)
        add the specfied value at the specified index
        Parameters:
        index - the index where the new value is to be added
        value - the new value
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).
      • add

        public boolean add​(double value)
        Appends the specified element to the end of this list
        Parameters:
        value - element to be appended to this list.
        Returns:
        true (as per the general contract of the Collection.add method).
      • addAll

        public boolean addAll​(DoubleList c)
        Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
        Parameters:
        c - collection whose elements are to be added to this list.
        Returns:
        true if this list changed as a result of the call.
      • addAll

        public boolean addAll​(int index,
                              DoubleList c)
        Inserts all of the elements in the specified collection into this list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
        Parameters:
        index - index at which to insert first element from the specified collection.
        c - elements to be inserted into this list.
        Returns:
        true if this list changed as a result of the call.
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())
      • clear

        public void clear()
        Removes all of the elements from this list. This list will be empty after this call returns (unless it throws an exception).
      • contains

        public boolean contains​(double o)
        Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that o == e
        Parameters:
        o - element whose presence in this list is to be tested.
        Returns:
        true if this list contains the specified element.
      • containsAll

        public boolean containsAll​(DoubleList c)
        Returns true if this list contains all of the elements of the specified collection.
        Parameters:
        c - collection to be checked for containment in this list.
        Returns:
        true if this list contains all of the elements of the specified collection.
      • equals

        public boolean equals​(Object o)
        Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if e1 == e2.) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to be compared for equality with this list.
        Returns:
        true if the specified object is equal to this list.
      • get

        public double get​(int index)
        Returns the element at the specified position in this list.
        Parameters:
        index - index of element to return.
        Returns:
        the element at the specified position in this list.
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
      • hashCode

        public int hashCode()
        THIS MOST LIKELY DOES NOT WORK Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation: hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); } This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object.hashCode.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this list.
      • indexOf

        public int indexOf​(double o)
        Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that (o == get(i)), or -1 if there is no such index.
        Parameters:
        o - element to search for.
        Returns:
        the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
      • isEmpty

        public boolean isEmpty()
        Returns true if this list contains no elements.
        Returns:
        true if this list contains no elements.
      • lastIndexOf

        public int lastIndexOf​(double o)
        Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the highest index i such that (o == get(i)), or -1 if there is no such index.
        Parameters:
        o - element to search for.
        Returns:
        the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
      • remove

        public double remove​(int index)
        Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
        Parameters:
        index - the index of the element to removed.
        Returns:
        the element previously at the specified position.
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
      • removeValue

        public boolean removeValue​(double o)
        Removes the first occurrence in this list of the specified element (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o.equals(get(i))) (if such an element exists).
        Parameters:
        o - element to be removed from this list, if present.
        Returns:
        true if this list contained the specified element.
      • removeAll

        public boolean removeAll​(DoubleList c)
        Removes from this list all the elements that are contained in the specified collection
        Parameters:
        c - collection that defines which elements will be removed from this list.
        Returns:
        true if this list changed as a result of the call.
      • retainAll

        public boolean retainAll​(DoubleList c)
        Retains only the elements in this list that are contained in the specified collection. In other words, removes from this list all the elements that are not contained in the specified collection.
        Parameters:
        c - collection that defines which elements this set will retain.
        Returns:
        true if this list changed as a result of the call.
      • set

        public double set​(int index,
                          double element)
        Replaces the element at the specified position in this list with the specified element
        Parameters:
        index - index of element to replace.
        element - element to be stored at the specified position.
        Returns:
        the element previously at the specified position.
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
      • size

        public int size()
        Returns the number of elements in this list. If this list contains more than Doubleeger.MAX_VALUE elements, returns Doubleeger.MAX_VALUE.
        Returns:
        the number of elements in this DoubleList
      • toArray

        public double[] toArray()
        Returns an array containing all of the elements in this list in proper sequence. Obeys the general contract of the Collection.toArray method.
        Returns:
        an array containing all of the elements in this list in proper sequence.
      • toArray

        public double[] toArray​(double[] a)
        Returns an array containing all of the elements in this list in proper sequence. Obeys the general contract of the Collection.toArray(Object[]) method.
        Parameters:
        a - the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose.
        Returns:
        an array containing the elements of this list.