in ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java [1922:2124]
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj instanceof String )
{
String other = ( String ) obj;
if ( !isHR )
{
return false;
}
if ( attributeType == null )
{
if ( upValue != null )
{
return upValue.equals( other );
}
else
{
return obj == null;
}
}
else
{
// Use the comparator
// We have an AttributeType, we use the associated comparator
try
{
LdapComparator<String> comparator = ( LdapComparator<String> ) getLdapComparator();
Normalizer normalizer = null;
if ( attributeType.getEquality() != null )
{
normalizer = attributeType.getEquality().getNormalizer();
}
if ( normalizer == null )
{
if ( comparator == null )
{
return normValue.equals( other );
}
else
{
return comparator.compare( normValue, other ) == 0;
}
}
String thisNormValue = normValue;
String otherNormValue = normalizer.normalize( other );
// Compare normalized values
if ( comparator == null )
{
return thisNormValue.equals( otherNormValue );
}
else
{
return comparator.compare( thisNormValue, otherNormValue ) == 0;
}
}
catch ( LdapException ne )
{
return false;
}
}
}
if ( !( obj instanceof Value ) )
{
return false;
}
Value other = ( Value ) obj;
// Check if the values aren't of the same type
if ( isHR != other.isHR )
{
// Both values must be HR or not HR
return false;
}
if ( !isHR )
{
// Shortcut for binary values
return Arrays.equals( bytes, other.bytes );
}
// HR values
if ( bytes == null )
{
return other.bytes == null;
}
// Special case
if ( other.bytes == null )
{
return false;
}
// Not null, but empty. We try to avoid a spurious String Preparation
if ( bytes.length == 0 )
{
return other.bytes.length == 0;
}
else if ( other.bytes.length == 0 )
{
return false;
}
// Ok, now, let's see if we have an AttributeType at all. If both have one,
// and if they aren't equal, then we get out. If one of them has an AttributeType and
// not the other, we will assume that this is the AttributeType to use.
MatchingRule equalityMR;
if ( attributeType == null )
{
if ( other.attributeType != null )
{
// Use the Other value AT
equalityMR = other.attributeType.getEquality();
// We may not have an Equality MR, and in tjis case, we compare the bytes
if ( equalityMR == null )
{
return Arrays.equals( bytes, other.bytes );
}
LdapComparator<Object> ldapComparator = equalityMR.getLdapComparator();
if ( ldapComparator == null )
{
// This is an error !
LOG.error( I18n.err( I18n.ERR_13249_NO_COMPARATOR_FOR_AT, other.attributeType ) );
return false;
}
return ldapComparator.compare( normValue, other.normValue ) == 0;
}
else
{
// Both are null. We will compare the prepared String if we have one,
// or the bytes otherwise.
if ( upValue != null )
{
return upValue.equals( other.upValue );
}
else
{
return Arrays.equals( bytes, other.bytes );
}
}
}
else
{
if ( other.attributeType != null )
{
// Both attributeType must be equal
if ( !attributeType.equals( other.attributeType ) )
{
return false;
}
// Use the comparator
// We have an AttributeType, we use the associated comparator
LdapComparator<String> comparator = ( LdapComparator<String> ) getLdapComparator();
if ( other.attributeType.getEquality() == null )
{
// No equality ? Default to comparing using a String comparator
return stringComparator.compare( normValue, other.normValue ) == 0;
}
// Compare normalized values
if ( comparator == null )
{
return normValue.equals( other.normValue );
}
else
{
return comparator.compare( normValue, other.normValue ) == 0;
}
}
// No attributeType
if ( normValue == null )
{
return other.normValue == null;
}
else
{
return normValue.equals( other.normValue );
}
}
}