public class ComplexComparisonResult extends ComparisonResult
Instance of this class represents 'complex' recursive result of performed comparison for two objects.
This result may contain other comparison results mapped by instances of the ClassPropertyKey
pointing to the specific (if possible) properties of the objects.
Example:
class SimplePerson {
public String name;
public int age;
public boolean male;
}
Now imagine we have two instances of this class:
false. This way you could create instance of this complex comparison result, with
fields like this:
false
Of course you always can use isSuccess() to get simple "yes/no" answer if there's no need
for such a depth. Complex comparison result is assumed to be successful, if all property results
from getPropertyResults() are successful.
Note: due to specifics of the ClassPropertyKey class single complex result may contain
property results mapped by keys pointing to any class - no validation is performed. But main recommendation is
for a single complex result to contain results for properties 'declared' by the class of compared objects, or its
superclasses. So if class JobPosition declares fields "String title" and "SimplePerson employee", then complex result
for this class should contain only properties declared in JobPosition or it's ancestors.
| Constructor and Description |
|---|
ComplexComparisonResult(java.lang.Object actual,
java.lang.Object expected,
ComparisonPerformer<?> comparisonPerformer,
java.util.Map<ClassPropertyKey,ComparisonResult> unequalProperties)
Construct complex result using specified map of sub results.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object object) |
java.util.Map<ClassPropertyStack,ComparisonResult> |
flatten()
Method creates flat representation of the property results.
|
java.util.Map<ClassPropertyStack,ComparisonResult> |
flatten(ClassPropertyStack parent)
Analogue of the
flatten() method, but all the keys in the result map will contains specified stack
as parent. |
java.util.Map<ClassPropertyKey,ComparisonResult> |
getPropertyResults()
Returns map that describes results of comparison performed for properties of objects from this result.
|
int |
hashCode() |
boolean |
isSuccess()
Complex comparison result assumed to be successful if all the property comparison result
from
getPropertyResults() returns true from isSuccess(). |
java.lang.String |
toString() |
getActual, getComparisonPerformer, getExpectedpublic ComplexComparisonResult(java.lang.Object actual,
java.lang.Object expected,
ComparisonPerformer<?> comparisonPerformer,
java.util.Map<ClassPropertyKey,ComparisonResult> unequalProperties)
public java.util.Map<ClassPropertyKey,ComparisonResult> getPropertyResults()
Returns map that describes results of comparison performed for properties of objects from this result.
Instances of ClassPropertyKey are used as keys of the map pointing to the specific comparison result
for specific property.
This result is assumed to be successful if all the results in the map are successful.
public java.util.Map<ClassPropertyStack,ComparisonResult> flatten()
Method creates flat representation of the property results.
Result map will contain only simple comparison results, mapped by ClassPropertyStack instances.
All complex subresults will be also flattened.
Property stacks are built this way: if this result contains simple sub-result with key String#length()
the result map will contain this sub-result with key {String#length()} (it's a stack of one element)
or {length()} (it's a call-string stack representation). And if this result contains complex sub-result
with key String#getBytes() and it contains simple sub-result with key byte[]#length
then result map will contain this simple sub-sub-result with key {String#getBytes()->byte[]#length}
or {getBytes().length}
Note: all the keys in the result map will contain null as parent, for calling of this
method is considered to be the beginning of a stack.
flatten(ClassPropertyStack)public java.util.Map<ClassPropertyStack,ComparisonResult> flatten(ClassPropertyStack parent)
flatten() method, but all the keys in the result map will contains specified stack
as parent.public boolean isSuccess()
getPropertyResults() returns true from isSuccess().isSuccess in class ComparisonResultpublic java.lang.String toString()
toString in class ComparisonResultpublic int hashCode()
hashCode in class ComparisonResultpublic boolean equals(java.lang.Object object)
equals in class ComparisonResult