Search in sources :

Example 1 with ManyAssociationWrapper

use of org.qi4j.api.association.ManyAssociationWrapper in project qi4j-sdk by Qi4j.

the class ManyAssociationInstance method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    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() != thatInstance.manyAssociationState.count()) {
        return false;
    }
    for (EntityReference ref : manyAssociationState) {
        if (!thatInstance.manyAssociationState.contains(ref)) {
            return false;
        }
    }
    return true;
}
Also used : ManyAssociationWrapper(org.qi4j.api.association.ManyAssociationWrapper) EntityReference(org.qi4j.api.entity.EntityReference) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) ManyAssociation(org.qi4j.api.association.ManyAssociation)

Aggregations

AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)1 ManyAssociation (org.qi4j.api.association.ManyAssociation)1 ManyAssociationWrapper (org.qi4j.api.association.ManyAssociationWrapper)1 EntityReference (org.qi4j.api.entity.EntityReference)1