Class ObjectPrimitives

java.lang.Object
com.illumon.iris.libs.primitives.ObjectPrimitives

public class ObjectPrimitives
extends Object
A set of commonly used functions that can be applied to Object types.
  • Constructor Summary

    Constructors 
    Constructor Description
    ObjectPrimitives()  
  • Method Summary

    Modifier and Type Method Description
    static <T extends Comparable<? super T>>
    int
    binSearchIndex​(DbArray<T> values, T key, BinSearch choiceWhenEquals)
    Performs a binary search to find a key.
    static boolean contains​(String target, CharSequence sequence)
    Returns true if a sequence is in the target string.
    static <T> int count​(DbArray<T> values)
    Counts the number of non-null values.
    static <T extends Comparable<? super T>>
    long
    countDistinct​(DbArray<T> values)
    Counts the number of distinct elements in the array.
    static <T extends Comparable<? super T>>
    long
    countDistinct​(DbArray<T> values, boolean countNull)
    Counts the number of distinct elements in the array.
    static <T extends Comparable<? super T>>
    DbArray<T>
    distinct​(DbArray<T> values)
    Returns an array containing only the distinct values from the input.
    static <T extends Comparable<? super T>>
    DbArray<T>
    distinct​(DbArray<T> values, boolean includeNull, boolean sort)
    Returns an array containing only the distinct values from the input.
    static <T> T first​(DbArray<T> values)
    Returns the first value from an array.
    static <T> T[] forwardFill​(T[] values)  
    static <T> boolean in​(T testedValue, T... possibleValues)
    Checks if a value is within a discrete set of possible values.
    static boolean inRange​(Comparable testedValue, Comparable lowInclusiveValue, Comparable highInclusiveValue)
    Checks if a value is within a range.
    static <T> boolean isDBNull​(T value)
    Determines if a value is null.
    static <T> boolean isNull​(T value)
    Determines if a value is null.
    static <T> T last​(DbArray<T> values)
    Returns the last value from an array.
    static <T extends Comparable>
    T
    max​(DbArray<T> values)
    Returns the maximum.
    static <NUM extends Number>
    NUM
    max​(NUM... values)
    Returns the maximum.
    static <T> T max​(T... values)
    Returns the maximum.
    static <T extends Comparable>
    T
    min​(DbArray<T> values)
    Returns the minimum.
    static <NUM extends Number>
    NUM
    min​(NUM... values)
    Returns the minimum.
    static <T> T min​(T... values)
    Returns the minimum.
    static <T> T nth​(int index, DbArray<T> values)
    Returns the nth value from an array.
    static <T> T[] nullToValue​(DbArray<T> values, T defaultValue)
    Replaces null values with a default value.
    static <T> T nullToValue​(T value, T defaultValue)
    Replaces null values with a default value.
    static <T extends Comparable<? super T>>
    int
    rawBinSearchIndex​(DbArray<T> values, T key, BinSearch choiceWhenEquals)
    Performs a binary search to find a key.
    static <T extends Comparable<? super T>>
    DbArray<T>
    sort​(DbArray<T> values)
    Returns sorted values from smallest to largest.
    static <NUM extends Number>
    NUM[]
    sort​(NUM... values)
    Returns sorted values from smallest to largest.
    static <T> T[] sort​(T... values)
    Returns sorted values from smallest to largest.
    static <T extends Comparable<? super T>>
    DbArray<T>
    sortDescending​(DbArray<T> values)
    Returns sorted values from largest to smallest.
    static <NUM extends Number>
    NUM[]
    sortDescending​(NUM... values)
    Returns sorted values from largest to smallest.
    static <T> T[] sortDescending​(T... values)
    Returns sorted values from largest to smallest.
    static <T> T[] vec​(DbArray<T> values)
    Converts a DB array to a primitive array.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • contains

      public static boolean contains​(String target, CharSequence sequence)
      Returns true if a sequence is in the target string.
      Parameters:
      target - string to search for the sequence.
      sequence - sequence to search for.
      Returns:
      true if target is not null and contains sequence; false otherwise.
      Throws:
      NullPointerException - if sequence is null
    • isNull

      public static <T> boolean isNull​(T value)
      Determines if a value is null.
      Parameters:
      value - value.
      Returns:
      true if the value is null, and false otherwise.
    • isDBNull

      public static <T> boolean isDBNull​(T value)
      Determines if a value is null. Beyond checking for simple null values, this method checks to see if the input object is equal to a null value. For example, if a boxed Long value is passed in, this method first checks to see if the value is null. If the value is not null, it checks to see if the value is QueryConstants.NULL_LONG.
      Parameters:
      value - value.
      Returns:
      true if the value is null, and false otherwise.
    • nullToValue

      public static <T> T nullToValue​(T value, T defaultValue)
      Replaces null values with a default value.
      Parameters:
      value - value.
      defaultValue - default value to return for null values.
      Returns:
      value, if value is not null, and defaultValue if value is null.
    • nullToValue

      public static <T> T[] nullToValue​(DbArray<T> values, T defaultValue)
      Replaces null values with a default value.
      Parameters:
      values - values.
      defaultValue - default value to return for null values.
      Returns:
      value, if value is not null, and defaultValue if value is null.
    • count

      public static <T> int count​(DbArray<T> values)
      Counts the number of non-null values.
      Parameters:
      values - values.
      Returns:
      number of non-null values.
    • last

      public static <T> T last​(DbArray<T> values)
      Returns the last value from an array.
      Parameters:
      values - values.
      Returns:
      last value from the array.
    • first

      public static <T> T first​(DbArray<T> values)
      Returns the first value from an array.
      Parameters:
      values - values.
      Returns:
      first value from the array.
    • nth

      public static <T> T nth​(int index, DbArray<T> values)
      Returns the nth value from an array.
      Parameters:
      index - index of the value to return.
      values - values.
      Returns:
      nth value from the array or null, if the index is outside of the array's index range.
    • vec

      public static <T> T[] vec​(DbArray<T> values)
      Converts a DB array to a primitive array.
      Parameters:
      values - DB array
      Returns:
      primitive array.
    • in

      public static <T> boolean in​(T testedValue, T... possibleValues)
      Checks if a value is within a discrete set of possible values.
      Parameters:
      testedValue - tested value.
      possibleValues - possible values.
      Returns:
      true if the tested value is contained in the possible values, and false otherwise.
    • inRange

      public static boolean inRange​(Comparable testedValue, Comparable lowInclusiveValue, Comparable highInclusiveValue)
      Checks if a value is within a range.
      Parameters:
      testedValue - tested value.
      lowInclusiveValue - lower inclusive bound of the range.
      highInclusiveValue - upper inclusive bound of the range.
      Returns:
      true if the tested value is within the range, and false if the tested value is not in the range or is null.
    • min

      public static <T extends Comparable> T min​(DbArray<T> values)
      Returns the minimum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      minimum of non-null values.
    • max

      public static <T extends Comparable> T max​(DbArray<T> values)
      Returns the maximum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      maximum of non-null values.
    • binSearchIndex

      public static <T extends Comparable<? super T>> int binSearchIndex​(DbArray<T> values, T key, BinSearch choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search.
      key - key to search for.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, the index of where the key would be inserted.
    • rawBinSearchIndex

      public static <T extends Comparable<? super T>> int rawBinSearchIndex​(DbArray<T> values, T key, BinSearch choiceWhenEquals)
      Performs a binary search to find a key.
      Parameters:
      values - sorted values to search.
      key - key to search for.
      choiceWhenEquals - algorithm used to resolve ties when performing a binary search.
      Returns:
      index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1).
    • min

      public static <NUM extends Number> NUM min​(NUM... values)
      Returns the minimum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      minimum of non-null values.
    • min

      public static <T> T min​(T... values)
      Returns the minimum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      minimum of non-null values.
    • max

      public static <NUM extends Number> NUM max​(NUM... values)
      Returns the maximum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      maximum of non-null values.
    • max

      public static <T> T max​(T... values)
      Returns the maximum. Null values are excluded.
      Parameters:
      values - values.
      Returns:
      maximum of non-null values.
    • sort

      public static <T extends Comparable<? super T>> DbArray<T> sort​(DbArray<T> values)
      Returns sorted values from smallest to largest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • sort

      public static <NUM extends Number> NUM[] sort​(NUM... values)
      Returns sorted values from smallest to largest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • sort

      public static <T> T[] sort​(T... values)
      Returns sorted values from smallest to largest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • sortDescending

      public static <T extends Comparable<? super T>> DbArray<T> sortDescending​(DbArray<T> values)
      Returns sorted values from largest to smallest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • sortDescending

      public static <NUM extends Number> NUM[] sortDescending​(NUM... values)
      Returns sorted values from largest to smallest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • sortDescending

      public static <T> T[] sortDescending​(T... values)
      Returns sorted values from largest to smallest.
      Parameters:
      values - values.
      Returns:
      sorted values.
    • countDistinct

      public static <T extends Comparable<? super T>> long countDistinct​(DbArray<T> values)
      Counts the number of distinct elements in the array.
      Parameters:
      values - values.
      Returns:
      number of distinct non-null values.
    • countDistinct

      public static <T extends Comparable<? super T>> long countDistinct​(DbArray<T> values, boolean countNull)
      Counts the number of distinct elements in the array.
      Parameters:
      values - values.
      countNull - true to count null values, and false to exclude null values.
      Returns:
      number of distinct values.
    • distinct

      public static <T extends Comparable<? super T>> DbArray<T> distinct​(DbArray<T> values)
      Returns an array containing only the distinct values from the input.
      Parameters:
      values - values.
      Returns:
      unsorted array containing only distinct non-null items from arr.
    • distinct

      public static <T extends Comparable<? super T>> DbArray<T> distinct​(DbArray<T> values, boolean includeNull, boolean sort)
      Returns an array containing only the distinct values from the input.
      Parameters:
      values - values.
      includeNull - true to include null values, and false to exclude null values.
      sort - true to sort the resultant array
      Returns:
      array containing only distinct items from arr.
    • forwardFill

      public static <T> T[] forwardFill​(T[] values)