Class ListNumbers

java.lang.Object
org.yamcs.studio.data.vtype.ListNumbers

public class ListNumbers extends Object
Utilities for manipulating ListNumbers.
  • Constructor Details

    • ListNumbers

      public ListNumbers()
  • Method Details

    • 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, ListInt 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
    • toListNumber

      public static ListNumber toListNumber(Object primitiveArray)
      Converts an array of primitive numbers to the appropriate ListNumber implementation.
      Parameters:
      primitiveArray - must be an array of primitive numbers (byte[], short[], int[], long[], float[] or double[])
      Returns:
      the wrapped array
    • listView

      public static ListNumber listView(ListNumber list, ListInt 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