Class ListNumbers


  • public class ListNumbers
    extends Object
    Utilities for manipulating ListNumbers.
    Author:
    carcassi
    • Constructor Detail

      • ListNumbers

        public ListNumbers()
    • Method Detail

      • sortedView

        public static SortedListView sortedView​(ListNumber values)
        Creates a sorted view of the given ListNumber.

        The ListNumber is not sorted in place, and the data is not copied out. Therefore it's intended that the ListNumber is not changed while the view is used.

        Parameters:
        values - the values to be sorted
        Returns:
        the sorted view
      • sortedView

        public static SortedListView sortedView​(ListNumber values,
                                                ListInteger indexes)
        Creates a sorted view of the given ListNumber based on the indexes provided. This method can be used to sort the given values based on the ordering by another (sorted) list of values.

        The ListNumber is not sorted in place, and the data is not copied out. Therefore it's intended that the ListNumber is not changed while the view is used.

        Parameters:
        values - the values to be sorted
        indexes - the ordering to be used for the view
        Returns:
        the sorted view
      • binarySearchValueOrLower

        public static int binarySearchValueOrLower​(ListNumber values,
                                                   double value)
        Finds the value in the list, or the one right below it.
        Parameters:
        values - a list of values
        value - a value
        Returns:
        the index of the value
      • binarySearchValueOrHigher

        public static int binarySearchValueOrHigher​(ListNumber values,
                                                    double value)
        Finds the value in the list, or the one right above it.
        Parameters:
        values - a list of values
        value - a value
        Returns:
        the index of the value
      • linearListFromRange

        public static ListNumber linearListFromRange​(double minValue,
                                                     double maxValue,
                                                     int size)
        Creates a list of equally spaced values given the range and the number of elements.

        Note that, due to rounding errors in double precision, the difference between the elements may not be exactly the same.

        Parameters:
        minValue - the first value in the list
        maxValue - the last value in the list
        size - the size of the list
        Returns:
        a new list
      • linearList

        public static ListNumber linearList​(double initialValue,
                                            double increment,
                                            int size)
        Creates a list of equally spaced values given the first value, the step between element and the size of the list.
        Parameters:
        initialValue - the first value in the list
        increment - the difference between elements
        size - the size of the list
        Returns:
        a new list
      • isLinear

        public static boolean isLinear​(ListNumber listNumber)
        Tests whether the list contains a equally spaced numbers.

        Always returns true if the list was created with linearList(double, double, int) or linearListFromRange(double, double, int). For all other cases, takes the first and last value, creates a linearListFromRange, and checks whether the difference is greater than the precision allowed by double. Note that this method is really strict, and it may rule out cases that may be considered to be linear.

        Parameters:
        listNumber - a list number
        Returns:
        true if the elements of the list are equally spaced
      • listView

        public static ListNumber listView​(ListNumber list,
                                          ListInteger indexes)
        Returns a view of the given list that presents only the elements at the given indexes.
        Parameters:
        list - a numeric list
        indexes - the indexes with the values to expose
        Returns:
        a wrapper around list
      • concatenate

        public static ListDouble concatenate​(ListNumber... lists)
        Concatenates a sequence of lists into a single one. The returned list is a view on the previous lists. This means that no copy is performed during the concatenation and that changes in the arguments will be seen through the concatenation. When reading and writing, the type is always cast to a double.
        Parameters:
        lists - the lists to concatenate.
        Returns:
        the concatenated list.