Package com.identityworksllc.iiq.common
Class Sameness
- java.lang.Object
-
- com.identityworksllc.iiq.common.Sameness
-
public class Sameness extends Object
Utility methods for detecting whether two objects are the same, 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.
-
-
Constructor Summary
Constructors Constructor Description Sameness()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static boolean
isNotSame(Object newValue, Object oldValue, boolean ignoreCase)
A typo-friendly inversion ofisSame(Object, Object, boolean)
.static boolean
isSame(Object newValue, Object oldValue, boolean ignoreCase)
Decide whether the two inputs are the same.
-
-
-
Constructor Detail
-
Sameness
public Sameness()
-
-
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 ofisSame(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)
.- 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
- Null and empty: Null is the same as any empty object (strings, lists, maps, boolean false)
- 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 - 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.
- String case: Two strings will be compared case-insensitive if the flag is passed as true
- 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
-
-