Package uk.ac.ebi.utils.collections
Class ArraySearchUtils
java.lang.Object
uk.ac.ebi.utils.collections.ArraySearchUtils
Utilities about searches over arrays.
- date
- 25 Sep 2013
- Author:
- Marco Brandizi
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
booleanisOneOf
(T value, Comparator<T> comparator, T... testValues) Tells if a value is equals to one of the values specified in an array.static <T extends Comparable<? super T>>
booleanisOneOf
(T value, T... testValues) A variant of#isOneOf(Object, Comparator, Object...)
that uses the natural comparison as comparator (i.e.static <T extends Comparable<? super T>>
booleanisOneOfByIdentity
(T value, T... testValues) A variant of#isOneOf(Object, Comparator, Object...)
that uses the identity comparison criterion (i.e., the '==' operator).
-
Method Details
-
isOneOf
@SafeVarargs public static <T extends Comparable<? super T>> boolean isOneOf(T value, Comparator<T> comparator, T... testValues) Tells if a value is equals to one of the values specified in an array. This is different than similar functions, eg,ArrayUtils.contains(Object[], Object)
, in the fact that the search can be based on a comparator.- Parameters:
value
- the value to check, if it is null, the method returns null in case comparator.compare ( null, null ) returns 0 and testValues contains null.comparator
- the comparator to be used for equality test. Note that what this returns when two values are different isn't relevant here.#isOneOf(Object, Object...)
and#isOneOfByIdentity(Object, Object...)
are convenient variants for common use cases.testValues
- the values that the target parameter has to be compared to
-
isOneOf
@SafeVarargs public static <T extends Comparable<? super T>> boolean isOneOf(T value, T... testValues) A variant of#isOneOf(Object, Comparator, Object...)
that uses the natural comparison as comparator (i.e. T.equals(). -
isOneOfByIdentity
A variant of#isOneOf(Object, Comparator, Object...)
that uses the identity comparison criterion (i.e., the '==' operator).
-