Package blbutil

Class DoubleArray


  • public class DoubleArray
    extends java.lang.Object
    Class DoubleArray represents an immutable list of double floating point values.
    • Constructor Summary

      Constructors 
      Constructor Description
      DoubleArray​(double[] values)
      Constructs an DoubleArray object with the specified values.
      DoubleArray​(java.util.stream.DoubleStream values)
      Constructs an DoubleArray object with the specified values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int binarySearch​(double key)
      Searches this for the specified value using the binary search algorithm.
      int binarySearch​(int fromIndex, int toIndex, double key)
      Searches the specified range of this for the specified value using the binary search algorithm.
      double get​(int index)
      Returns the double at the specified position in this list.
      boolean isEmpty()
      Returns true if this list has no elements, and returns false otherwise.
      int size()
      Returns the number of elements in this list.
      double[] toArray()
      Returns an integer array containing the sequence of elements in this list.
      java.lang.String toString()
      Returns a string representation of this list that is obtained by calling java.util.Arrays.toString(this.toArray()).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DoubleArray

        public DoubleArray​(double[] values)
        Constructs an DoubleArray object with the specified values.
        Parameters:
        values - the list of floating point values
        Throws:
        java.lang.NullPointerException - if values == null
      • DoubleArray

        public DoubleArray​(java.util.stream.DoubleStream values)
        Constructs an DoubleArray object with the specified values.
        Parameters:
        values - a stream of floating point values
        Throws:
        java.lang.NullPointerException - if values == null
        java.lang.IllegalStateException - if the stream has previously been used
    • Method Detail

      • get

        public double get​(int index)
        Returns the double at the specified position in this list.
        Parameters:
        index - the index of the returned double
        Returns:
        the double at the specified position in this list
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= this.size()
      • size

        public int size()
        Returns the number of elements in this list.
        Returns:
        the number of elements in this list
      • isEmpty

        public boolean isEmpty()
        Returns true if this list has no elements, and returns false otherwise.
        Returns:
        true if this list has no elements, and returns false otherwise
      • binarySearch

        public int binarySearch​(double key)
        Searches this for the specified value using the binary search algorithm. This list must be sorted (as by the java.util.Arrays.sort(double[]) method) prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
        Parameters:
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or this.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      • binarySearch

        public int binarySearch​(int fromIndex,
                                int toIndex,
                                double key)
        Searches the specified range of this for the specified value using the binary search algorithm. This range must be sorted (as by the java.util.Arrays.sort(double[]) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
        Parameters:
        fromIndex - the index of the first element (inclusive) to be searched
        toIndex - the index of the last element (exclusive) to be searched
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or this.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > this.size()
      • toArray

        public double[] toArray()
        Returns an integer array containing the sequence of elements in this list.
        Returns:
        an integer array containing the sequence of elements in this list
      • toString

        public java.lang.String toString()
        Returns a string representation of this list that is obtained by calling java.util.Arrays.toString(this.toArray()).
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this list