Package gov.usgs.earthquake.nshmp.data
Class Indexing
- java.lang.Object
-
- gov.usgs.earthquake.nshmp.data.Indexing
-
public final class Indexing extends Object
Utilities pertaining to the creation, calculation, and derivation of data indices.- Author:
- U.S. Geological Survey
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]
bitsToIndices(BitSet bits)
Return an index array corresponding to the 'set' bits of the suppliedBitSet
.static int
checkInRange(Range<Integer> range, String label, int value)
Ensurevalue
falls within the specifiedRange
.static int[]
indices(int size)
Create anint[]
of values ascending from0
to1-size
.static int[]
indices(int from, int to)
Create anint[]
of values spanningfrom
toto
, inclusive.static BitSet
indicesToBits(int capacity, int[] indices)
Return aBitSet
withcapacity
and with all bits atindices
'set'.static int
maxIndex(double... data)
Find the index of the maximum value indata
.static int[]
maxIndex(double[][] data)
Find the indices of the maximum value indata
.static int[]
maxIndex(double[][][] data)
Find the indices of the maximum value indata
.static int
minIndex(double... data)
Find the index of the minimum value indata
.static int[]
minIndex(double[][] data)
Find the indices of the minimum value indata
.static int[]
minIndex(double[][][] data)
Find the indices of the minimum value indata
.static List<Integer>
sortedIndices(List<Double> data, boolean ascending)
Create an indexList
of pointers to sorteddata
.
-
-
-
Method Detail
-
indices
public static int[] indices(int size)
Create anint[]
of values ascending from0
to1-size
.- Parameters:
size
- of output array- Returns:
- an index array
- Throws:
IllegalArgumentException
- ifsize
is not in the range[1..10⁷]
-
indices
public static int[] indices(int from, int to)
Create anint[]
of values spanningfrom
toto
, inclusive. Sequence will be descending iffrom
is greater thanto
.- Parameters:
from
- start value, inclusiveto
- end value, inclusive- Returns:
- an index array
- Throws:
IllegalArgumentException
- iffrom < 0
orto < 0
, or the computed size of the index array is< 1
-
sortedIndices
public static List<Integer> sortedIndices(List<Double> data, boolean ascending)
Create an indexList
of pointers to sorteddata
. Say you have a number ofList<Double>
s and want to iterate them according to the sort order of one of them. Supply this method with the desireddata
and use the returned indices in a custom iterator, leaving all original data in place.Notes:
- This method does not modify the supplied
data
. NaN
is considered to be equal to itself and greater than all other double values (including Double.POSITIVE_INFINITY) per the behavior ofDouble.compareTo(Double)
.
- Parameters:
data
- for which to compute sort indicesascending
- sort order iftrue
, descending iffalse
- Returns:
- a sorted index
List
- Throws:
IllegalArgumentException
- ifdata
is empty
- This method does not modify the supplied
-
bitsToIndices
public static int[] bitsToIndices(BitSet bits)
Return an index array corresponding to the 'set' bits of the suppliedBitSet
.- Parameters:
bits
- to operate on- Returns:
- the indices of 'set' bits
-
indicesToBits
public static BitSet indicesToBits(int capacity, int[] indices)
Return aBitSet
withcapacity
and with all bits atindices
'set'.- Parameters:
capacity
- of returnedBitSet
indices
- to operate on- Throws:
IllegalArgumentException
- ifcapacity < 1
IndexOutOfBoundsException
- if anyindices
are outside the range specified bycapacity
-
minIndex
public static int minIndex(double... data)
Find the index of the minimum value indata
. For equivalent minima, method returns the index of the first minimum encountered. If the supplied array is empty, method returns-1
.- Parameters:
data
- to evaluate- Returns:
- the index of the minimum value or
-1
if the array is empty
-
minIndex
public static int[] minIndex(double[][] data)
Find the indices of the minimum value indata
. For equivalent maxima, method returns the indices of the first minimum encountered. If the 1st dimension of the supplied array is empty or all arrays in the 2nd dimension are empty, method returns[-1, -1]
.- Parameters:
data
- to evaluate- Returns:
- the indices of the minimum value or
[-1, -1]
for empty arrays
-
minIndex
public static int[] minIndex(double[][][] data)
Find the indices of the minimum value indata
. For equivalent minima, method returns the indices of the first minimum encountered. If the 1st dimension of the supplied array is empty or all arrays in the 2nd or 3rd dimensions are empty, method returns[-1, -1, -1]
.- Parameters:
data
- to evaluate- Returns:
- the indices of the minimum value or
[-1, -1, -1]
for empty arrays
-
maxIndex
public static int maxIndex(double... data)
Find the index of the maximum value indata
. For equivalent maxima, method returns the index of the first maximum encountered. If the supplied array is empty, method returns-1
.- Parameters:
data
- to evaluate- Returns:
- the index of the maximum value or -1 if the array is empty
-
maxIndex
public static int[] maxIndex(double[][] data)
Find the indices of the maximum value indata
. For equivalent maxima, method returns the indices of the first maximum encountered. If the 1st dimension of the supplied array is empty or all arrays in the 2nd dimension are empty, method returns[-1, -1]
.- Parameters:
data
- to evaluate- Returns:
- the indices of the maximum value or
[-1, -1]
for empty arrays
-
maxIndex
public static int[] maxIndex(double[][][] data)
Find the indices of the maximum value indata
. For equivalent maxima, method returns the indices of the first maximum encountered. If the 1st dimension of the supplied array is empty or all arrays in the 2nd or 3rd dimensions are empty, method returns[-1, -1, -1]
.- Parameters:
data
- to evaluate- Returns:
- the indices of the maximum value or
[-1, -1, -1]
for empty arrays
-
checkInRange
public static int checkInRange(Range<Integer> range, String label, int value)
Ensurevalue
falls within the specifiedRange
.- Parameters:
range
- of allowable valueslabel
- for value if check failsvalue
- to validate- Returns:
- the supplied
value
- Throws:
IllegalArgumentException
- if value is out of specified range
-
-