Package com.illumon.iris.libs.primitives
Class ShortPrimitives
java.lang.Object
com.illumon.iris.libs.primitives.ShortPrimitives
A set of commonly used functions that can be applied to Short types.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DbShortArray
array
(short[] values) Converts a primitive array to a DB array.static short[]
concat
(short[]... values) Returns the concatenation of multiple arrays into a single array.static short[]
concat
(DbShortArray... values) Returns the concatenation of multiple arrays into a single array.static int
count
(short[] values) Counts the number of non-null values.static int
count
(DbShortArray values) Counts the number of non-null values.static int
Counts the number of non-null values.static long
countDistinct
(short[] values) Counts the number of distinct elements in the array.static long
countDistinct
(short[] values, boolean countNull) Counts the number of distinct elements in the array.static long
countDistinct
(DbShortArray values) Counts the number of distinct elements in the array.static long
countDistinct
(DbShortArray values, boolean countNull) Counts the number of distinct elements in the array.static short[]
distinct
(short[] values) Returns an array containing only the distinct values from the input.static short[]
distinct
(short[] values, boolean includeNull, boolean sort) Returns an array containing only the distinct values from the input.static DbShortArray
distinct
(DbShortArray values) Returns an array containing only the distinct values from the input.static DbShortArray
distinct
(DbShortArray values, boolean includeNull, boolean sort) Returns an array containing only the distinct values from the input.static short[]
enlist
(short... values) Returns a list containing its arguments.static short
first
(short[] values) Returns the first value from an array.static short
first
(DbShortArray values) Returns the first value from an array.static short[]
forwardFill
(short[] values) static boolean
in
(short testedValues, short... possibleValues) Checks if a value is within a discrete set of possible values.static boolean
inRange
(short testedValue, short lowInclusiveValue, short highInclusiveValue) Checks if a value is within a range.static boolean
isNull
(short value) Determines if a value is null.static short
last
(short[] values) Returns the last value from an array.static short
last
(DbShortArray values) Returns the last value from an array.static short
nth
(int index, short[] values) Returns the nth value from an array.static short
nth
(int index, DbShortArray values) Returns the nth value from an array.static short[]
nullToValue
(short[] values, short defaultValue) Replaces null values with a default value.static short
nullToValue
(short value, short defaultValue) Replaces null values with a default value.static short[]
nullToValue
(DbShortArray values, short defaultValue) Replaces null values with a default value.static short[]
repeat
(short value, int size) Returns an array with a value repeated.static short[]
reverse
(short... values) Returns an array with the values reversed.static short[]
reverse
(DbShortArray values) Returns an array with the values reversed.static short[]
Unboxes a array of values.static short
uniqueValue
(DbShortArray arr, boolean countNull) Get the single unique value in the array, or null if there are none, or there are more than 1 distinct values.static short[]
vec
(DbShortArray values) Converts a DB array to a primitive array.
-
Constructor Details
-
ShortPrimitives
public ShortPrimitives()
-
-
Method Details
-
unbox
Unboxes a array of values.- Parameters:
values
- values.- Returns:
- unboxed array of values.
-
isNull
public static boolean isNull(short value) Determines if a value is null.- Parameters:
value
- value.- Returns:
- true if the value is null, and false otherwise.
-
nullToValue
public static short nullToValue(short value, short 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 short[] nullToValue(short[] values, short defaultValue) Replaces null values with a default value.- Parameters:
values
- values.defaultValue
- default value to return for null values.- Returns:
- values with nulls replaced by defaultValue.
-
nullToValue
Replaces null values with a default value.- Parameters:
values
- values.defaultValue
- default value to return for null values.- Returns:
- values with nulls replaced by defaultValue.
-
count
Counts the number of non-null values.- Parameters:
values
- values.- Returns:
- number of non-null values.
-
count
public static int count(short[] values) Counts the number of non-null values.- Parameters:
values
- values.- Returns:
- number of non-null values.
-
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.
-
last
public static short last(short[] values) 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.
-
first
public static short first(short[] values) 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.
-
nth
public static short nth(int index, short[] 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
Converts a DB array to a primitive array.- Parameters:
values
- DB array- Returns:
- primitive array.
-
array
Converts a primitive array to a DB array.- Parameters:
values
- primitive array- Returns:
- DB array.
-
inRange
public static boolean inRange(short testedValue, short lowInclusiveValue, short 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.
-
in
public static boolean in(short testedValues, short... possibleValues) Checks if a value is within a discrete set of possible values.- Parameters:
testedValues
- tested value.possibleValues
- possible values.- Returns:
- true if the tested value is contained in the possible values, and false otherwise.
-
countDistinct
public static long countDistinct(short[] values) Counts the number of distinct elements in the array.- Parameters:
values
- values.- Returns:
- number of distinct non-null values.
-
countDistinct
Counts the number of distinct elements in the array.- Parameters:
values
- values.- Returns:
- number of distinct non-null values.
-
countDistinct
public static long countDistinct(short[] 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.
-
countDistinct
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.
-
uniqueValue
Get the single unique value in the array, or null if there are none, or there are more than 1 distinct values.- Parameters:
arr
- the arraycountNull
- if nulls should count as values- Returns:
- the single unique value in the array, or null.
-
distinct
public static short[] distinct(short[] 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
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 short[] distinct(short[] 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.
-
distinct
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.
-
repeat
public static short[] repeat(short value, int size) Returns an array with a value repeated.- Parameters:
value
- value.size
- number of times to repeat the value.- Returns:
- array of repeated values. If
size
is less than zero, an empty array is returned.
-
enlist
public static short[] enlist(short... values) Returns a list containing its arguments.- Parameters:
values
- values.- Returns:
- list containing values.
-
concat
public static short[] concat(short[]... values) Returns the concatenation of multiple arrays into a single array.- Parameters:
values
- values.- Returns:
- concatenation of multiple arrays into a single array.
-
concat
Returns the concatenation of multiple arrays into a single array.- Parameters:
values
- values.- Returns:
- concatenation of multiple arrays into a single array.
-
reverse
public static short[] reverse(short... values) Returns an array with the values reversed.- Parameters:
values
- values.- Returns:
- array with the values reversed.
-
reverse
Returns an array with the values reversed.- Parameters:
values
- values.- Returns:
- array with the values reversed.
-
forwardFill
public static short[] forwardFill(short[] values)
-