Search in sources :

Example 1 with PropertyWrapper

use of org.qi4j.api.property.PropertyWrapper in project qi4j-sdk by Qi4j.

the class PropertyInstance method equals.

/**
     * Perform equals with {@code o} argument.
     * <p>
     *     The definition of equals() for the Property is that if both the state and descriptor are equal,
     *     then the properties are equal.
     * </p>
     *
     * @param o The other object to compare.
     * @return Returns a {@code boolean} indicator whether this object is equals the other.
     */
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    Property<?> that = (Property<?>) o;
    // Unwrap if needed
    while (that instanceof PropertyWrapper) {
        that = ((PropertyWrapper) that).next();
    }
    // Descriptor equality
    PropertyDescriptor thatDescriptor = (PropertyDescriptor) ((PropertyInstance) that).propertyInfo();
    if (!model.equals(thatDescriptor)) {
        return false;
    }
    // State equality
    T value = get();
    if (value == null) {
        return that.get() == null;
    }
    return value.equals(that.get());
}
Also used : PropertyWrapper(org.qi4j.api.property.PropertyWrapper) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) Property(org.qi4j.api.property.Property)

Aggregations

Property (org.qi4j.api.property.Property)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 PropertyWrapper (org.qi4j.api.property.PropertyWrapper)1