public class ListNumbers extends Object
Constructor and Description |
---|
ListNumbers() |
Modifier and Type | Method and Description |
---|---|
static 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.
|
public static SortedListView sortedView(ListNumber 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.
values
- the values to be sortedpublic static SortedListView sortedView(ListNumber values, ListInt indexes)
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.
values
- the values to be sortedindexes
- the ordering to be used for the viewpublic static int binarySearchValueOrLower(ListNumber values, double value)
values
- a list of valuesvalue
- a valuepublic static int binarySearchValueOrHigher(ListNumber values, double value)
values
- a list of valuesvalue
- a valuepublic static ListNumber linearListFromRange(double minValue, double maxValue, int size)
Note that, due to rounding errors in double precision, the difference between the elements may not be exactly the same.
minValue
- the first value in the listmaxValue
- the last value in the listsize
- the size of the listpublic static ListNumber linearList(double initialValue, double increment, int size)
initialValue
- the first value in the listincrement
- the difference between elementssize
- the size of the listpublic static boolean isLinear(ListNumber listNumber)
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.
listNumber
- a list numberpublic static ListNumber toListNumber(Object primitiveArray)
primitiveArray
- must be an array of primitive numbers (byte[],
short[], int[], long[], float[] or double[])public static ListNumber listView(ListNumber list, ListInt indexes)
list
- a numeric listindexes
- the indexes with the values to exposeCopyright © 2015. All rights reserved.