Java Code Examples for org.apache.directory.api.util.Strings#compare()
The following examples show how to use
org.apache.directory.api.util.Strings#compare() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Compare two values. We compare the stored bytes * * @param other the byte[] we want to compare the current value with * @return a positive value if the current value is above the provided byte[], a negative value * if it's below, 0 if they are equal. * @throws IllegalStateException on failures to extract the comparator, or the * normalizers needed to perform the required comparisons based on the schema */ public int compareTo( byte[] other ) { if ( isHR ) { String msg = I18n.err( I18n.ERR_13224_FAILED_TO_COMPARE_NORM_VALUES, this, other ); LOG.error( msg ); throw new IllegalStateException( msg ); } // Check if both value are null if ( bytes == null ) { if ( other == null ) { return 0; } else { return -1; } } else if ( other == null ) { return 1; } // Default : compare the bytes return Strings.compare( bytes, other ); }
Example 2
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Compare two values. We either compare the stored bytes, or we use the * AttributeType Comparator, if we have an Ordered MatchingRule. * * @param other The other Value we want to compare the current value with * @return a positive value if the current value is above the provided value, a negative value * if it's below, 0 if they are equal. * @throws IllegalStateException on failures to extract the comparator, or the * normalizers needed to perform the required comparisons based on the schema */ @Override public int compareTo( Value other ) { // The two values must have the same type if ( isHR != other.isHR ) { String msg = I18n.err( I18n.ERR_13224_FAILED_TO_COMPARE_NORM_VALUES, this, other ); LOG.error( msg ); throw new IllegalStateException( msg ); } // Check if both value are null if ( bytes == null ) { if ( other.bytes == null ) { return 0; } else { return -1; } } else if ( other.bytes == null ) { return 1; } // Ok, neither this nor the other have null values. // Shortcut when the value are not HR if ( !isHR ) { return Strings.compare( bytes, other.bytes ); } // We have HR values. We may have an attributeType for the base Value // It actually does not matter if the second value has an attributeType // which is different try { if ( attributeType != null ) { // Check if the other value has been normalized or not if ( other.attributeType == null ) { // No normalization. Use the base AttributeType to normalize // the other value String normalizedOther = attributeType.getEquality().getNormalizer().normalize( other.upValue ); return normValue.compareTo( normalizedOther ); } else { return normValue.compareTo( other.normValue ); } } else { if ( other.attributeType != null ) { // Normalize the current value with the other value normalizer String normalizedThis = other.attributeType.getEquality().getNormalizer().normalize( upValue ); return normalizedThis.compareTo( other.normValue ); } else { // No AtributeType... Compare the normValue return normValue.compareTo( other.normValue ); } } } catch ( LdapException le ) { return -1; } }
Example 3
Source File: ByteArrayComparator.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public int compare( byte[] b1, byte[] b2 ) { return Strings.compare( b1, b2 ); }