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

    Modifier and Type
    Method
    Description
    static int[]
    Return an index array corresponding to the 'set' bits of the supplied BitSet.
    static int
    checkInRange(Range<Integer> range, String label, int value)
    Ensure value falls within the specified Range.
    static int[]
    indices(int size)
    Create an int[] of values ascending from 0 to 1-size.
    static int[]
    indices(int from, int to)
    Create an int[] of values spanning from to to, inclusive.
    static BitSet
    indicesToBits(int capacity, int[] indices)
    Return a BitSet with capacity and with all bits at indices 'set'.
    static int
    maxIndex(double... data)
    Find the index of the maximum value in data.
    static int[]
    maxIndex(double[][] data)
    Find the indices of the maximum value in data.
    static int[]
    maxIndex(double[][][] data)
    Find the indices of the maximum value in data.
    static int
    minIndex(double... data)
    Find the index of the minimum value in data.
    static int[]
    minIndex(double[][] data)
    Find the indices of the minimum value in data.
    static int[]
    minIndex(double[][][] data)
    Find the indices of the minimum value in data.
    static List<Integer>
    sortedIndices(List<Double> data, boolean ascending)
    Create an index List of pointers to sorted data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • indices

      public static int[] indices(int size)
      Create an int[] of values ascending from 0 to 1-size.
      Parameters:
      size - of output array
      Returns:
      an index array
      Throws:
      IllegalArgumentException - if size is not in the range [1..10⁷]
    • indices

      public static int[] indices(int from, int to)
      Create an int[] of values spanning from to to, inclusive. Sequence will be descending if from is greater than to.
      Parameters:
      from - start value, inclusive
      to - end value, inclusive
      Returns:
      an index array
      Throws:
      IllegalArgumentException - if from < 0 or to < 0, or the computed size of the index array is < 1
    • sortedIndices

      public static List<Integer> sortedIndices(List<Double> data, boolean ascending)
      Create an index List of pointers to sorted data. Say you have a number of List<Double>s and want to iterate them according to the sort order of one of them. Supply this method with the desired data 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 of Double.compareTo(Double).
      Parameters:
      data - for which to compute sort indices
      ascending - sort order if true, descending if false
      Returns:
      a sorted index List
      Throws:
      IllegalArgumentException - if data is empty
    • bitsToIndices

      public static int[] bitsToIndices(BitSet bits)
      Return an index array corresponding to the 'set' bits of the supplied BitSet.
      Parameters:
      bits - to operate on
      Returns:
      the indices of 'set' bits
    • indicesToBits

      public static BitSet indicesToBits(int capacity, int[] indices)
      Return a BitSet with capacity and with all bits at indices 'set'.
      Parameters:
      capacity - of returned BitSet
      indices - to operate on
      Throws:
      IllegalArgumentException - if capacity < 1
      IndexOutOfBoundsException - if any indices are outside the range specified by capacity
    • minIndex

      public static int minIndex(double... data)
      Find the index of the minimum value in data. 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 in data. 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 in data. 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 in data. 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 in data. 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 in data. 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)
      Ensure value falls within the specified Range.
      Parameters:
      range - of allowable values
      label - for value if check fails
      value - to validate
      Returns:
      the supplied value
      Throws:
      IllegalArgumentException - if value is out of specified range