Package org.apache.sis.util
Class Utilities
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.util.Utilities
Static methods for object comparisons in different ways (deeply, approximately, etc).
- Since:
- 0.3
- Version:
- 0.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
deepEquals
(Object object1, Object object2, ComparisonMode mode) Convenience method for testing two objects for equality using the given level of strictness.static int
deepHashCode
(Object object) Returns a hash code for the specified object, which may be an array.static String
deepToString
(Object object) Returns a string representation of the specified object, which may be an array.private static boolean
equals
(Iterable<?> object1, Iterable<?> object2, ComparisonMode mode) Compares two collections.private static boolean
equals
(LenientComparable[] array1, Object[] array2, ComparisonMode mode) Compares two arrays where at least one array is known to containLenientComparable
elements.static boolean
equalsApproximately
(Object object1, Object object2) Compares the specified objects for equality, ignoring metadata and slight differences in numerical values.static boolean
equalsIgnoreMetadata
(Object object1, Object object2) Compares the specified objects for equality, ignoring metadata.private static boolean
isNotDebug
(ComparisonMode mode) Returnstrue
if the given mode is notComparisonMode.DEBUG
.private static String
mismatchedElement
(String header, Iterable<?> object1, Iterable<?> object2, String tail) Returns an assertion error message for mismatched collections.private static String
mismatchedType
(Class<?> expected, Object actual) Returns an assertion error message for mismatched types.
-
Constructor Details
-
Utilities
private Utilities()Do not allow object creation.
-
-
Method Details
-
equalsIgnoreMetadata
Compares the specified objects for equality, ignoring metadata. If this method returnstrue
, then:- If the two given objects are math transforms, then transforming a set of coordinate values using one transform will produce the same results than transforming the same coordinates with the other transform.
- If the two given objects are
Coordinate Reference Systems (CRS), then a call to
findOperation(crs1, crs2, null)
will return an identity operation.
equalsApproximately(Object, Object)
can be used instead.Implementation note
This is a convenience method for the following method call:- Parameters:
object1
- the first object to compare (may be null).object2
- the second object to compare (may be null).- Returns:
true
if both objects are equal, ignoring metadata.- See Also:
-
equalsApproximately
Compares the specified objects for equality, ignoring metadata and slight differences in numerical values. If this method returnstrue
, then:- If the two given objects are math transforms, then transforming a set of coordinate values using one transform will produce approximately the same results than transforming the same coordinates with the other transform.
- If the two given objects are
Coordinate Reference Systems (CRS), then a call to
findOperation(crs1, crs2, null)
will return an operation close to identity.
Implementation note
This is a convenience method for the following method call:- Parameters:
object1
- the first object to compare (may be null).object2
- the second object to compare (may be null).- Returns:
true
if both objects are approximately equal.- See Also:
-
deepEquals
Convenience method for testing two objects for equality using the given level of strictness. If at least one of the given objects implement theLenientComparable
interface, then the comparison is performed using theLenientComparable.equals(Object, ComparisonMode)
method. Otherwise this method performs the same work than theObjects.deepEquals(Object, Object)
convenience method.If both arguments are arrays or collections, then the elements are compared recursively.
- Parameters:
object1
- the first object to compare, ornull
.object2
- the second object to compare, ornull
.mode
- the strictness level of the comparison.- Returns:
true
if both objects are equal for the given level of strictness.- See Also:
-
equals
Compares two arrays where at least one array is known to containLenientComparable
elements. This knowledge avoid the need to test each element individually. The two arrays shall be non-null. -
equals
Compares two collections. Order are significant, unless both collections implement theSet
interface. -
isNotDebug
Returnstrue
if the given mode is notComparisonMode.DEBUG
. In debug mode, the expected behavior ofdeepEquals(Object, Object, ComparisonMode)
is to thrown an exception (rather than returningfalse
) when two objects are not equal. -
mismatchedType
Returns an assertion error message for mismatched types.- Parameters:
expected
- the expected type.actual
- the actual object (not its type).- Returns:
- the error message to use in assertions.
-
mismatchedElement
private static String mismatchedElement(String header, Iterable<?> object1, Iterable<?> object2, String tail) Returns an assertion error message for mismatched collections. -
deepHashCode
Returns a hash code for the specified object, which may be an array. This method returns one of the following values:- If the supplied object is
null
, then this method returns 0. - Otherwise if the object is an array of objects, then
Arrays.deepHashCode(Object[])
is invoked. - Otherwise if the object is an array of primitive type, then the corresponding
Arrays.hashCode(...)
method is invoked. - Otherwise
Object.hashCode()
is invoked.
Object
, not as some subtype likeObject[]
,String
orfloat[]
. In the latter cases, use the appropriateArrays
method instead.- Parameters:
object
- the object to compute hash code. May benull
.- Returns:
- the hash code of the given object.
- If the supplied object is
-
deepToString
Returns a string representation of the specified object, which may be an array. This method returns one of the following values:- If the object is an array of objects, then
Arrays.deepToString(Object[])
is invoked. - Otherwise if the object is an array of primitive type, then the corresponding
Arrays.toString(...)
method is invoked. - Otherwise
String.valueOf(Object)
is invoked.
Object
, not as some subtype likeObject[]
,Number
orfloat[]
. In the latter cases, use the appropriateArrays
method instead.- Parameters:
object
- the object to format as a string. May benull
.- Returns:
- a string representation of the given object.
- If the object is an array of objects, then
-