Class Is

java.lang.Object
org.openxava.util.Is

public class Is extends Object
Utility class to reduce the ifs size.

Useful for implementing asserts (invariants, preconditions, postcondition).
For example:

if (name != null || name.trim().equals("") ||
  surname1 != null || surname1.trim().equals("")) ||
  surname2 != null || surname2.trim().equals(""))
{
  doSomething();
}
can be write:
if (Is.emptyString(name, surname1, surname2)) {
  doSomethis();
}
Author:
Javier Paniza, Hayrol Reyes
  • Constructor Details

    • Is

      public Is()
  • Method Details

    • anyEqual

      public static boolean anyEqual(Object object, Object... possibleValues)
      Compare the first argurment with the rest and if any if equal returns true. Uses Is.equal() to compare the elements. The null is a valid value, so if you send null as first argument and any of the possible value is null returns true.
      Parameters:
      object - The object we are looking for. Can null.
      possibleValues - The objects where we are looking for. Can contain nulls.
      Since:
      5.6
    • empty

      public static final boolean empty(Object object)
      Verifies if the sent object is null or a "neutral" value: - Empty string - Number zero (including BigDecimal ZERO) - Empty-or-zero Map (see Maps.isEmptyOrZero(Map)) - Empty-or-zero Collection (see XCollections.isEmptyOrZero(Collection)) - Empty Java native array

      Since v5.9 it supports Java native arrays. Since v7.6 it supports collections.

    • emptyString

      public static final boolean emptyString(String... strs)
      Verifies if some of the sent strings are null or empty string.

    • emptyStringAll

      public static final boolean emptyStringAll(String... strs)
      Verifies if all sent strings are null or empty string.

    • equal

      public static final boolean equal(Object a, Object b)
      If a is equals to b.

      Takes in account the nulls. Use compareTo when appropriate and compares Java 5 enums with numbers by the ordinal value. Compares Integer, Long, Short among themselves.
      Also admits to compare objects of not compatible types, just it returns false in this case. Since v5.9 works fine with Java native arrays.

      Parameters:
      a - Can be null.
      b - Can be null.
    • equalAsString

      public static final boolean equalAsString(Object a, Object b)
      If a.toString().trim() is equals to b.toString().trim().

      Takes in account the nulls.

      Parameters:
      a - Can be null.
      b - Can be null.
    • equalAsStringIgnoreCase

      public static final boolean equalAsStringIgnoreCase(Object a, Object b)
      If a.toString().trim() is equal to b.toString().trim() ignoring case.

      Takes in account the nulls.

      Parameters:
      a - Can be null.
      b - Can be null.