Class Is


  • public class Is
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      Is()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean anyEqual​(java.lang.Object object, java.lang.Object... possibleValues)
      Compare the first argurment with the rest and if any if equal returns true.
      static boolean empty​(java.lang.Object object)
      Verifies if the sent object is null or empty string (if it's string) or 0 (if it's number) or empty Map.
      static boolean emptyString​(java.lang.String... strs)
      Verifies if some of the sent strings are null or empty string.
      static boolean emptyStringAll​(java.lang.String... strs)
      Verifies if all sent strings are null or empty string.
      static boolean equal​(java.lang.Object a, java.lang.Object b)
      If a is equals to b.
      static boolean equalAsString​(java.lang.Object a, java.lang.Object b)
      If a.toString().trim() is equals to b.toString().trim().
      static boolean equalAsStringIgnoreCase​(java.lang.Object a, java.lang.Object b)
      If a.toString().trim() is equal to b.toString().trim() ignoring case.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Is

        public Is()
    • Method Detail

      • anyEqual

        public static boolean anyEqual​(java.lang.Object object,
                                       java.lang.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​(java.lang.Object object)
        Verifies if the sent object is null or empty string (if it's string) or 0 (if it's number) or empty Map.

        Since v5.9 it supports Java native arrays.

      • emptyString

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

      • emptyStringAll

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

      • equal

        public static final boolean equal​(java.lang.Object a,
                                          java.lang.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​(java.lang.Object a,
                                                  java.lang.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​(java.lang.Object a,
                                                            java.lang.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.