Class ArraySearchUtils

java.lang.Object
uk.ac.ebi.utils.collections.ArraySearchUtils

public class ArraySearchUtils extends Object
Utilities about searches over arrays.
date
25 Sep 2013
Author:
Marco Brandizi
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    static <T extends Comparable<? super T>>
    boolean
    isOneOfByIdentity(T value, T... testValues)
    A variant of #isOneOf(Object, Comparator, Object...) that uses the identity comparison criterion (i.e., the '==' operator).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static <T extends Comparable<? super T>> boolean isOneOfByIdentity(T value, T... testValues)
      A variant of #isOneOf(Object, Comparator, Object...) that uses the identity comparison criterion (i.e., the '==' operator).