Package com.illumon.iris.libs.primitives
Class ObjectPrimitives
java.lang.Object
com.illumon.iris.libs.primitives.ObjectPrimitives
A set of commonly used functions that can be applied to Object types.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
intbinSearchIndex(DbArray<T> values, T key, BinSearch choiceWhenEquals) Performs a binary search to find a key.static booleancontains(String target, CharSequence sequence) Returns true if a sequence is in the target string.static <T> intCounts the number of non-null values.static <T extends Comparable<? super T>>
longcountDistinct(DbArray<T> values) Counts the number of distinct elements in the array.static <T extends Comparable<? super T>>
longcountDistinct(DbArray<T> values, boolean countNull) Counts the number of distinct elements in the array.static <T extends Comparable<? super T>>
DbArray<T>Returns an array containing only the distinct values from the input.static <T extends Comparable<? super T>>
DbArray<T>Returns an array containing only the distinct values from the input.static <T> TReturns the first value from an array.static <T> T[]forwardFill(T[] values) static <T> booleanin(T testedValue, T... possibleValues) Checks if a value is within a discrete set of possible values.static booleaninRange(Comparable testedValue, Comparable lowInclusiveValue, Comparable highInclusiveValue) Checks if a value is within a range.static <T> booleanisDBNull(T value) Determines if a value is null.static <T> booleanisNull(T value) Determines if a value is null.static <T> TReturns the last value from an array.static <T extends Comparable>
TReturns the maximum.static <NUM extends Number>
NUMmax(NUM... values) Returns the maximum.static <T> Tmax(T... values) Returns the maximum.static <T extends Comparable>
TReturns the minimum.static <NUM extends Number>
NUMmin(NUM... values) Returns the minimum.static <T> Tmin(T... values) Returns the minimum.static <T> TReturns the nth value from an array.static <T> T[]nullToValue(DbArray<T> values, T defaultValue) Replaces null values with a default value.static <T> TnullToValue(T value, T defaultValue) Replaces null values with a default value.static <T extends Comparable<? super T>>
intrawBinSearchIndex(DbArray<T> values, T key, BinSearch choiceWhenEquals) Performs a binary search to find a key.static <T extends Comparable<? super T>>
DbArray<T>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[]Converts a DB array to a primitive array.
-
Constructor Details
-
ObjectPrimitives
public ObjectPrimitives()
-
-
Method Details
-
contains
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
targetis not null and containssequence; false otherwise. - Throws:
NullPointerException- ifsequenceisnull
-
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 boxedLongvalue 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 isQueryConstants.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
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
Counts the number of non-null values.- Parameters:
values- values.- Returns:
- number of non-null values.
-
last
Returns the last value from an array.- Parameters:
values- values.- Returns:
- last value from the array.
-
first
Returns the first value from an array.- Parameters:
values- values.- Returns:
- first value from the array.
-
nth
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
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
Returns the minimum. Null values are excluded.- Parameters:
values- values.- Returns:
- minimum of non-null values.
-
max
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
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
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
Returns sorted values from smallest to largest.- Parameters:
values- values.- Returns:
- sorted values.
-
sort
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
Returns sorted values from largest to smallest.- Parameters:
values- values.- Returns:
- sorted values.
-
sortDescending
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
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
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)
-