Package org.alfresco.util
Class EqualsHelper
- java.lang.Object
-
- org.alfresco.util.EqualsHelper
-
@AlfrescoPublicApi public class EqualsHelper extends java.lang.Object
Utility class providing helper methods for various types ofequals
functionality- Author:
- Derek Hulley
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EqualsHelper.MapValueComparison
Enumeration for results returned bymap comparisons
.
-
Constructor Summary
Constructors Constructor Description EqualsHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
binaryStreamEquals(java.io.InputStream left, java.io.InputStream right)
Performs a byte-level comparison between two streams.static <K,V>
java.util.Map<K,EqualsHelper.MapValueComparison>getMapComparison(java.util.Map<K,V> left, java.util.Map<K,V> right)
Compare two maps.static java.lang.String
getMapDifferenceReport(java.util.Map<?,?> actual, java.util.Map<?,?> expected)
Compare two maps and generate a difference report between the actual and expected values.static boolean
nullSafeEquals(java.lang.Object left, java.lang.Object right)
Performs an equality checkleft.equals(right)
after checking for null valuesstatic boolean
nullSafeEquals(java.lang.String left, java.lang.String right, boolean ignoreCase)
Performs an case-sensitive or case-insensitive equality check after checking for null values
-
-
-
Method Detail
-
nullSafeEquals
public static boolean nullSafeEquals(java.lang.Object left, java.lang.Object right)
Performs an equality checkleft.equals(right)
after checking for null values- Parameters:
left
- the Object appearing in the left side of anequals
statementright
- the Object appearing in the right side of anequals
statement- Returns:
- Return true or false even if one or both of the objects are null
-
nullSafeEquals
public static boolean nullSafeEquals(java.lang.String left, java.lang.String right, boolean ignoreCase)
Performs an case-sensitive or case-insensitive equality check after checking for null values- Parameters:
ignoreCase
- true to ignore case
-
binaryStreamEquals
public static boolean binaryStreamEquals(java.io.InputStream left, java.io.InputStream right) throws java.io.IOException
Performs a byte-level comparison between two streams.- Parameters:
left
- the left stream. This is closed at the end of the operation.right
- an right stream. This is closed at the end of the operation.- Returns:
- Returns true if the streams are identical to the last byte
- Throws:
java.io.IOException
-
getMapDifferenceReport
public static java.lang.String getMapDifferenceReport(java.util.Map<?,?> actual, java.util.Map<?,?> expected)
Compare two maps and generate a difference report between the actual and expected values. This method is particularly useful during unit tests as the result (if not null) can be appended to a failure message.- Parameters:
actual
- the map in handexpected
- the map expected- Returns:
- Returns a difference report or null if there were no differences. The message starts with a new line and is neatly formatted.
-
getMapComparison
public static <K,V> java.util.Map<K,EqualsHelper.MapValueComparison> getMapComparison(java.util.Map<K,V> left, java.util.Map<K,V> right)
Compare two maps. The return codes that accompany the keys are:- Type Parameters:
K
- the map key typeV
- the map value type- Parameters:
left
- the left side of the comparisonright
- the right side of the comparison- Returns:
- Returns a map whose keys are a union of the two maps' keys, along with the value comparison result
-
-