Class Sameness


  • public class Sameness
    extends Object
    Utility methods for detecting sameness in two objects, since IIQ is inconsistent about it.

    The primary method in here is isSame(Object, Object, boolean). This class is heavily used throughout the IIQCommon libraries as well as the IDW plugins.

    • Method Detail

      • isEmpty

        public static boolean isEmpty​(Object thing)
        Returns true if the given thing is empty in the isSame() sense, i.e., if it ought to be the same as null.

        These are values that are often optimized out by SailPoint when serializing to XML.

        A thing is empty if it is null or is an empty string, array, collection, or map. Boolean false and integer 0 are also empty.

        All other values are not empty.

        Parameters:
        thing - The thing to check for emptiness
        Returns:
        True if the thing is empty; false otherwise
      • isNotSame

        public static boolean isNotSame​(Object newValue,
                                        Object oldValue,
                                        boolean ignoreCase)
        A typo-friendly inversion of isSame(Object, Object, boolean).
        Parameters:
        newValue - The new value (can be null)
        oldValue - The old value (can be null)
        ignoreCase - True if strings and collections should be compared ignoring case. Maps are always compared case-insensitively.
        Returns:
        True if the values are NOT “the same” according to our definition
      • isSame

        public static boolean isSame​(Object newValue,
                                     Object oldValue,
                                     boolean ignoreCase)
        Decide whether the two inputs are the same.

        This can be an expensive check and so should be used in concert with existing .equals(), e.g. o1.equals(o2) || isSame(o1, o2).

        1. Type differences: If the two values are a String and a Boolean (or a String and a Number), but will be stored the same way by Hibernate, they are the same
        2. Null and empty: Null is the same as any empty object (strings, lists, maps, boolean false)
        3. Dates and Longs: If one value is a long and one is a Date, they are the same if Date.getTime() equals the long value
        4. Collections: Two collections are the same if they have equal elements in any order. If ignoreCase is true, elements will be converted to strings and compared case-insensitively.
        5. String case: Two strings will be compared case-insensitive if the flag is passed as true
        6. String vs. Collection case: A string is the same as collection containing only that string
        Parameters:
        newValue - The new value (can be null)
        oldValue - The old value (can be null)
        ignoreCase - True if strings and collections should be compared ignoring case. Maps are always compared case-insensitively.
        Returns:
        True if the values are “the same” according to our definition