Author: elecharny
Date: Sun Dec 18 15:57:09 2005
New Revision: 357571
URL: http://svn.apache.org/viewcvs?rev=357571&view=rev
Log:
We can now compare ATAV with case sensitivity or not.
Modified:
directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/AttributeTypeAndValue.java
Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/AttributeTypeAndValue.java?rev=357571&r1=357570&r2=357571&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/AttributeTypeAndValue.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/AttributeTypeAndValue.java
Sun Dec 18 15:57:09 2005
@@ -43,6 +43,8 @@
/** The name value */
private String value;
+ private static final boolean CASE_SENSITIVE = false;
+
/**
* Construct an empty AttributeTypeAndValue
*/
@@ -173,7 +175,7 @@
{
AttributeTypeAndValue nc = (AttributeTypeAndValue)object;
- return ( compare( type, nc.type ) && compare( value, nc.value ) ? 0 :
-1 );
+ return ( compareType( type, nc.type ) && compareValue( value, nc.value,
CASE_SENSITIVE ) ? 0 : -1 );
}
else
{
@@ -182,12 +184,12 @@
}
/**
- * Compare two strings, trimed and case insensitive
+ * Compare two types, trimed and case insensitive
* @param val1 First String
* @param val2 Second String
* @return true if both strings are equals or null.
*/
- private boolean compare( String val1, String val2 )
+ private boolean compareType( String val1, String val2 )
{
if ( StringUtils.isEmpty( val1 ) )
{
@@ -200,6 +202,35 @@
else
{
return ( StringUtils.lowerCase( StringUtils.trim( val1 ) ) ).equals(StringUtils.lowerCase(
StringUtils.trim( val2 ) ) );
+ }
+ }
+
+ /**
+ * Compare two values
+ * @param val1 First String
+ * @param val2 Second String
+ * @return true if both strings are equals or null.
+ */
+ private boolean compareValue( String val1, String val2, boolean caseSensitive )
+ {
+ if ( StringUtils.isEmpty( val1 ) )
+ {
+ return StringUtils.isEmpty( val2 );
+ }
+ else if ( StringUtils.isEmpty( val2 ) )
+ {
+ return false;
+ }
+ else
+ {
+ if ( caseSensitive )
+ {
+ return ( StringUtils.lowerCase( StringUtils.trim( val1 ) ) ).equals(StringUtils.lowerCase(
StringUtils.trim( val2 ) ) );
+ }
+ else
+ {
+ return ( StringUtils.trim( val1 ) ).equals( StringUtils.trim( val2 ) );
+ }
}
}
|