Package xal.tools
Class RealNumericIndexer<T>
java.lang.Object
xal.tools.RealNumericIndexer<T>
- All Implemented Interfaces:
Iterable<T>
Order objects by their specified numeric index and assign a corresponding
integer index based on sequential order and provide mapping between the two
indices.
-
Field Summary
FieldsModifier and TypeFieldDescriptionrecords of data -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the specified value at the specified location.double
findIndex
(double location) Get the index of the specified location.get
(int index) Get the element at the specified indexint
getClosestIndex
(double location) Get the index which is closest to the index of the specified location and round down if two are equally close.int[]
getIndicesWithinLocationRange
(double startLocation, double endLocation) Get the smallest range of indices whose location range contains the specified range inclusive.double
getLocation
(int index) Get the location corresponding to the specified index.int
getLowerIndex
(double location) Get the index which is the greatest integer less than or equal to the index of the specified location.int
getUpperIndex
(double location) Get the index which is the least integer greater than or equal to the index of the specified location but the greatest of equals.iterator()
Get an indexer for the indexed items.remove
(int index) Remove the specified item by index.int
size()
Get the sizetoList()
Generate a list of the values.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
numericRecords
records of data
-
-
Constructor Details
-
RealNumericIndexer
public RealNumericIndexer()Constructor
-
-
Method Details
-
size
public int size()Get the size- Returns:
- the number of items indexed
-
iterator
Get an indexer for the indexed items. -
toList
Generate a list of the values.- Returns:
- a list of the values ordered according to the index
-
get
Get the element at the specified index- Returns:
- the value at the specified index
-
getLocation
public double getLocation(int index) Get the location corresponding to the specified index.- Parameters:
index
- the index of the record to fetch- Returns:
- the location corresponding to the specified index
-
getLowerIndex
public int getLowerIndex(double location) Get the index which is the greatest integer less than or equal to the index of the specified location. However, if there are several indices for the specified location, pick the least one.- Parameters:
location
- the location for which to identify the array index- Returns:
- the index which is the greatest integer less than or equal to the index of the specified location
-
getUpperIndex
public int getUpperIndex(double location) Get the index which is the least integer greater than or equal to the index of the specified location but the greatest of equals. However, if there are several indices for the specified location, pick the greatest one.- Parameters:
location
- the location for which to identify the array index- Returns:
- the index which is the least integer greater than or equal to the index of the specified location
-
getIndicesWithinLocationRange
public int[] getIndicesWithinLocationRange(double startLocation, double endLocation) Get the smallest range of indices whose location range contains the specified range inclusive.- Parameters:
startLocation
- the starting locationendLocation
- the ending location- Returns:
- the indices corresponding to the location range or a range of -1s if none exists
-
getClosestIndex
public int getClosestIndex(double location) Get the index which is closest to the index of the specified location and round down if two are equally close.- Parameters:
location
- the location for which to identify the array index- Returns:
- the closest index
-
findIndex
public double findIndex(double location) Get the index of the specified location.- Parameters:
location
- the location for which to identify the array index- Returns:
- the array index for the specified location
-
add
Add the specified value at the specified location.- Parameters:
value
- the value to addlocation
- the location of the value
-
remove
Remove the specified item by index.- Parameters:
index
- the index of the item to remove
-