Core Runtime: Fix Association and ManyAssociation equality Associations and ManyAssociations using *Wrappers were not unwrapper. This commit fixes that.
Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/5b513e0f Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/5b513e0f Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/5b513e0f Branch: refs/heads/master Commit: 5b513e0fc9db78f23a434b4c8b27fc4c0b0b3110 Parents: ff99cbd Author: Paul Merlin <[email protected]> Authored: Wed Feb 20 10:21:01 2013 +0100 Committer: Paul Merlin <[email protected]> Committed: Wed Feb 20 10:21:01 2013 +0100 ---------------------------------------------------------------------- .../runtime/association/AssociationInstance.java | 15 +++++++++++---- .../runtime/association/ManyAssociationInstance.java | 15 +++++++++++---- .../org/qi4j/runtime/property/PropertyInstance.java | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/5b513e0f/core/runtime/src/main/java/org/qi4j/runtime/association/AssociationInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/association/AssociationInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/association/AssociationInstance.java index d94aae2..d5babcd 100644 --- a/core/runtime/src/main/java/org/qi4j/runtime/association/AssociationInstance.java +++ b/core/runtime/src/main/java/org/qi4j/runtime/association/AssociationInstance.java @@ -17,6 +17,7 @@ package org.qi4j.runtime.association; import java.lang.reflect.Type; import org.qi4j.api.association.Association; import org.qi4j.api.association.AssociationDescriptor; +import org.qi4j.api.association.AssociationWrapper; import org.qi4j.api.entity.EntityReference; import org.qi4j.api.property.Property; import org.qi4j.functional.Function2; @@ -99,17 +100,23 @@ public final class AssociationInstance<T> { return false; } - AssociationInstance<?> that = (AssociationInstance) o; - AssociationDescriptor thatDescriptor = (AssociationDescriptor) that.associationInfo(); + Association<?> that = (Association) o; + // Unwrap if needed + while( that instanceof AssociationWrapper ) + { + that = ( (AssociationWrapper) that ).next(); + } // Descriptor equality + AssociationInstance<?> thatInstance = (AssociationInstance) that; + AssociationDescriptor thatDescriptor = (AssociationDescriptor) thatInstance.associationInfo(); if( !associationInfo.equals( thatDescriptor ) ) { return false; } // State equality if( associationState.get() != null - ? !associationState.get().equals( that.associationState.get() ) - : that.associationState.get() != null ) + ? !associationState.get().equals( thatInstance.associationState.get() ) + : thatInstance.associationState.get() != null ) { return false; } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/5b513e0f/core/runtime/src/main/java/org/qi4j/runtime/association/ManyAssociationInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/association/ManyAssociationInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/association/ManyAssociationInstance.java index ad5a734..a946862 100644 --- a/core/runtime/src/main/java/org/qi4j/runtime/association/ManyAssociationInstance.java +++ b/core/runtime/src/main/java/org/qi4j/runtime/association/ManyAssociationInstance.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Set; import org.qi4j.api.association.AssociationDescriptor; import org.qi4j.api.association.ManyAssociation; +import org.qi4j.api.association.ManyAssociationWrapper; import org.qi4j.api.entity.EntityReference; import org.qi4j.functional.Function2; import org.qi4j.runtime.composite.ConstraintsCheck; @@ -120,21 +121,27 @@ public class ManyAssociationInstance<T> { return false; } - ManyAssociationInstance<?> that = (ManyAssociationInstance) o; - AssociationDescriptor thatDescriptor = (AssociationDescriptor) that.associationInfo(); + ManyAssociation<?> that = (ManyAssociation) o; + // Unwrap if needed + while( that instanceof ManyAssociationWrapper ) + { + that = ( (ManyAssociationWrapper) that ).next(); + } // Descriptor equality + ManyAssociationInstance<?> thatInstance = (ManyAssociationInstance) that; + AssociationDescriptor thatDescriptor = (AssociationDescriptor) thatInstance.associationInfo(); if( !associationInfo.equals( thatDescriptor ) ) { return false; } // State equality - if( manyAssociationState.count() != that.manyAssociationState.count() ) + if( manyAssociationState.count() != thatInstance.manyAssociationState.count() ) { return false; } for( EntityReference ref : manyAssociationState ) { - if( !that.manyAssociationState.contains( ref ) ) + if( !thatInstance.manyAssociationState.contains( ref ) ) { return false; } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/5b513e0f/core/runtime/src/main/java/org/qi4j/runtime/property/PropertyInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/qi4j/runtime/property/PropertyInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/property/PropertyInstance.java index 75bda37..499fec4 100644 --- a/core/runtime/src/main/java/org/qi4j/runtime/property/PropertyInstance.java +++ b/core/runtime/src/main/java/org/qi4j/runtime/property/PropertyInstance.java @@ -122,8 +122,8 @@ public class PropertyInstance<T> { that = ( (PropertyWrapper) that ).next(); } - PropertyDescriptor thatDescriptor = (PropertyDescriptor) ( (PropertyInstance) that ).propertyInfo(); // Descriptor equality + PropertyDescriptor thatDescriptor = (PropertyDescriptor) ( (PropertyInstance) that ).propertyInfo(); if( !model.equals( thatDescriptor ) ) { return false;
