Class ListNumbers
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
binarySearchValueOrHigher
(ListNumber values, double value) Finds the value in the list, or the one right above it.static int
binarySearchValueOrLower
(ListNumber values, double value) Finds the value in the list, or the one right below it.static boolean
isLinear
(ListNumber listNumber) Tests whether the list contains a equally spaced numbers.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.static ListNumber
linearListFromRange
(double minValue, double maxValue, int size) Creates a list of equally spaced values given the range and the number of elements.static ListNumber
listView
(ListNumber list, ListInt indexes) Returns a view of the given list that presents only the elements at the given indexes.static SortedListView
sortedView
(ListNumber values) Creates a sorted view of the given ListNumber.static SortedListView
sortedView
(ListNumber values, ListInt indexes) Creates a sorted view of the given ListNumber based on the indexes provided.static ListNumber
toListNumber
(Object primitiveArray) Converts an array of primitive numbers to the appropriate ListNumber implementation.
-
Constructor Details
-
ListNumbers
public ListNumbers()
-
-
Method Details
-
sortedView
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
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 sortedindexes
- the ordering to be used for the view- Returns:
- the sorted view
-
binarySearchValueOrLower
Finds the value in the list, or the one right below it.- Parameters:
values
- a list of valuesvalue
- a value- Returns:
- the index of the value
-
binarySearchValueOrHigher
Finds the value in the list, or the one right above it.- Parameters:
values
- a list of valuesvalue
- a value- Returns:
- the index of the value
-
linearListFromRange
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 listmaxValue
- the last value in the listsize
- the size of the list- Returns:
- a new list
-
linearList
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 listincrement
- the difference between elementssize
- the size of the list- Returns:
- a new list
-
isLinear
Tests whether the list contains a equally spaced numbers.Always returns true if the list was created with
linearList(double, double, int)
orlinearListFromRange(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
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
Returns a view of the given list that presents only the elements at the given indexes.- Parameters:
list
- a numeric listindexes
- the indexes with the values to expose- Returns:
- a wrapper around list
-