You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/10/27 22:20:46 UTC
svn commit: r589209 - in /directory:
apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/
shared/branches/bigbang/ldap/src/...
Author: akarasulu
Date: Sat Oct 27 13:20:43 2007
New Revision: 589209
URL: http://svn.apache.org/viewvc?rev=589209&view=rev
Log:
more tests and changes to new entry interfaces as ideas are solidifying
Added:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java
Removed:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/InvalidValueException.java
Modified:
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java Sat Oct 27 13:20:43 2007
@@ -19,14 +19,13 @@
package org.apache.directory.server.core.entry;
-import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import javax.naming.NamingException;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Set;
/**
@@ -35,9 +34,9 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ServerAttribute implements EntryAttribute
+public class ServerAttribute implements EntryAttribute<ServerValue<?>>
{
- private Set<Value<?>> values = new HashSet<Value<?>>();
+ private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
private AttributeType attributeType;
@@ -62,14 +61,28 @@
* Checks to see if this attribute is valid along with the values it contains.
*
* @return true if the attribute and it's values are valid, false otherwise
+ * @throws NamingException if there is a failure to check syntaxes of values
*/
- boolean isValid()
+ public boolean isValid() throws NamingException
{
- throw new NotImplementedException();
+ if ( attributeType.isSingleValue() && values.size() > 1 )
+ {
+ return false;
+ }
+
+ for ( ServerValue value : values )
+ {
+ if ( ! value.isValid() )
+ {
+ return false;
+ }
+ }
+
+ return true;
}
- public boolean add( Value<?> val )
+ public boolean add( ServerValue<?> val )
{
return values.add( val );
}
@@ -93,22 +106,7 @@
}
- @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
- public ServerAttribute clone() throws CloneNotSupportedException
- {
- Set<Value<?>> clonedValues = new HashSet<Value<?>>();
- for ( Value value : values )
- {
- clonedValues.add( value.clone() );
- }
-
- ServerAttribute cloned = new ServerAttribute( attributeType );
- cloned.values = clonedValues;
- return cloned;
- }
-
-
- public boolean contains( Value<?> val )
+ public boolean contains( ServerValue<?> val )
{
return values.contains( val );
}
@@ -139,7 +137,7 @@
}
- public Iterator<Value<?>> getAll()
+ public Iterator<? extends ServerValue<?>> getAll()
{
return values.iterator();
}
@@ -151,7 +149,7 @@
}
- public boolean remove( Value<?> val )
+ public boolean remove( ServerValue<?> val )
{
return values.remove( val );
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Sat Oct 27 13:20:43 2007
@@ -20,14 +20,15 @@
import org.apache.directory.shared.ldap.entry.BinaryValue;
-import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.naming.NamingException;
import java.util.Arrays;
+import java.util.Comparator;
/**
@@ -36,7 +37,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ServerBinaryValue extends BinaryValue implements Value<byte[]>
+public class ServerBinaryValue extends BinaryValue implements ServerValue<byte[]>
{
private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
@@ -84,24 +85,10 @@
if ( normalizedValue == null )
{
- // search for matchingRules with a normalizer we can use based on
- // the parent attribute type this attribute value is intended for
- Normalizer normalizer = attributeType.getEquality().getNormalizer();
+ Normalizer normalizer = getNormalizer();
if ( normalizer == null )
{
- normalizer = attributeType.getOrdering().getNormalizer();
- }
-
- if ( normalizer == null )
- {
- normalizer = attributeType.getSubstr().getNormalizer();
- }
-
- // at this point if we still have no normalizer then presume as-is
- // normalization - the value is the same as the normalized value
- if ( normalizer == null )
- {
normalizedValue = get();
}
else
@@ -124,6 +111,64 @@
public final boolean isValid() throws NamingException
{
return attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
+ }
+
+
+ public int compareTo( ServerValue<byte[]> value )
+ {
+ try
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalStateException( "Failed to normalize values.", e );
+ }
+ }
+
+
+ private Normalizer getNormalizer() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getNormalizer();
+ }
+
+
+ private MatchingRule getMatchingRule() throws NamingException
+ {
+ MatchingRule mr = attributeType.getEquality();
+
+ if ( mr == null )
+ {
+ mr = attributeType.getOrdering();
+ }
+
+ if ( mr == null )
+ {
+ mr = attributeType.getSubstr();
+ }
+
+ return mr;
+ }
+
+
+ private Comparator getComparator() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getComparator();
}
Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java?rev=589209&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java (added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStreamedValue.java Sat Oct 27 13:20:43 2007
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.entry;
+
+
+import org.apache.directory.shared.ldap.entry.StreamedValue;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.NamingException;
+import java.net.URI;
+import java.util.Comparator;
+
+
+/**
+ * A large streamed value within the server. For all practical purposes
+ * values of this type are treated like referrals. They reference some
+ * value which could not fit without issue into main memory. Instead the
+ * value is referred to. This has implications on the semantics of various
+ * Value operations:
+ *
+ * <ul>
+ * <li>
+ * URI get() does not return the value but a URI referring to the value located
+ * in some streamable target location.
+ * </li>
+ * <li>
+ * set(URI) likewise sets the location target where the value can be streamed
+ * from rather than setting the actual value.
+ * </li>
+ * <li>
+ * @todo need to reflect upon this some more
+ * Don't know if getNormalizedValue() is even relavent but I guess the
+ * same URI can be represented in many ways if it is not already in canonical form
+ * </li>
+ * <li>
+ * @todo need to reflect upon this some more
+ * isValid() is also uncessary since really this does not mean the actual value
+ * stored where pointed to by the URI is actually valid. I think this is a reason
+ * why the server must suspend certain checks for blobs like this. Blobs should be
+ * binary and cannot be used for naming. Hence because they cannot be used for
+ * naming then they should not need to have matchingRules and can just use the
+ * default binary matching.
+ * </li>
+ * <li>
+ * compareTo() is relative to the URI and not the actual streamed value stored at
+ * the URI target. This means another means is needed to determine ordering for
+ * the wrapped streamed values.
+ * </li>
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerStreamedValue extends StreamedValue implements ServerValue<URI>
+{
+ private static final Logger LOG = LoggerFactory.getLogger( ServerStreamedValue.class );
+ private URI normalizedValue;
+
+ // use this to lookup the attributeType when deserializing
+ @SuppressWarnings ( { "UnusedDeclaration" } )
+ private final String oid;
+
+ // do not serialize the schema entity graph associated with the type
+ private transient AttributeType attributeType;
+
+
+ public ServerStreamedValue( AttributeType attributeType )
+ {
+ if ( attributeType == null )
+ {
+ throw new NullPointerException( "attributeType cannot be null" );
+ }
+ this.attributeType = attributeType;
+ this.oid = attributeType.getOid();
+ }
+
+
+ public ServerStreamedValue( AttributeType attributeType, URI wrapped )
+ {
+ if ( attributeType == null )
+ {
+ throw new NullPointerException( "attributeType cannot be null" );
+ }
+ this.attributeType = attributeType;
+ this.oid = attributeType.getOid();
+ super.set( wrapped );
+ }
+
+
+ public URI getNormalizedValue() throws NamingException
+ {
+ if ( get() == null )
+ {
+ return null;
+ }
+
+ if ( normalizedValue == null )
+ {
+ Normalizer normalizer = getNormalizer();
+
+ if ( normalizer == null )
+ {
+ normalizedValue = get();
+ }
+ else
+ {
+ normalizedValue = ( URI ) normalizer.normalize( get() );
+ }
+ }
+
+ return normalizedValue;
+ }
+
+
+ private MatchingRule getMatchingRule() throws NamingException
+ {
+ MatchingRule mr = attributeType.getEquality();
+
+ if ( mr == null )
+ {
+ mr = attributeType.getOrdering();
+ }
+
+ if ( mr == null )
+ {
+ mr = attributeType.getSubstr();
+ }
+
+ return mr;
+ }
+
+
+ private Normalizer getNormalizer() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getNormalizer();
+ }
+
+
+ private Comparator getComparator() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getComparator();
+ }
+
+
+ public boolean isValid() throws NamingException
+ {
+ return attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
+ }
+
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode()
+ {
+ // return zero if the value is null so only one null value can be
+ // stored in an attribute - the binary version does the same
+ if ( get() == null )
+ {
+ return 0;
+ }
+
+ try
+ {
+ return getNormalizedValue().hashCode();
+ }
+ catch ( NamingException e )
+ {
+ LOG.warn( "Failed to get normalized value while trying to get hashCode: {}", toString() , e );
+
+ // recover by using non-normalized values
+ return get().hashCode();
+ }
+ }
+
+ public int compareTo( ServerValue<URI> value )
+ {
+ if ( value == null && get() == null )
+ {
+ return 0;
+ }
+
+ if ( value != null && get() == null )
+ {
+ if ( value.get() == null )
+ {
+ return 0;
+ }
+ return -1;
+ }
+
+ if ( value == null )
+ {
+ return 1;
+ }
+
+
+ try
+ {
+ if ( value instanceof ServerStreamedValue )
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
+ }
+
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(), value.get() );
+ }
+ catch ( NamingException e )
+ {
+ throw new IllegalStateException( "Normalization failed when it should have succeeded", e );
+ }
+ }
+}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Sat Oct 27 13:20:43 2007
@@ -22,11 +22,13 @@
import org.apache.directory.shared.ldap.entry.StringValue;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.naming.NamingException;
+import java.util.Comparator;
/**
@@ -35,13 +37,10 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ServerStringValue extends StringValue implements Value<String>
+public class ServerStringValue extends StringValue implements ServerValue<String>
{
private static final Logger LOG = LoggerFactory.getLogger( ServerStringValue.class );
- @SuppressWarnings ( { "AnalyzingVariableNaming" } )
- static final long serialVersionUID = 2L;
-
private String normalizedValue;
// use this to lookup the attributeType when deserializing
@@ -84,22 +83,8 @@
if ( normalizedValue == null )
{
- // search for matchingRules with a normalizer we can use based on
- // the parent attribute type this attribute value is intended for
- Normalizer normalizer = attributeType.getEquality().getNormalizer();
-
- if ( normalizer == null )
- {
- normalizer = attributeType.getOrdering().getNormalizer();
- }
-
- if ( normalizer == null )
- {
- normalizer = attributeType.getSubstr().getNormalizer();
- }
+ Normalizer normalizer = getNormalizer();
- // at this point if we still have no normalizer then presume as-is
- // normalization - the value is the same as the normalized value
if ( normalizer == null )
{
normalizedValue = get();
@@ -127,12 +112,61 @@
}
- @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
- public final ServerStringValue clone() throws CloneNotSupportedException
+ public int compareTo( ServerValue<String> value )
{
- ServerStringValue copy = new ServerStringValue( attributeType, get() );
- copy.normalizedValue = normalizedValue;
- return copy;
+ try
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(), value.getNormalizedValue() );
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalStateException( "Failed to normalize values.", e );
+ }
+ }
+
+
+ private MatchingRule getMatchingRule() throws NamingException
+ {
+ MatchingRule mr = attributeType.getEquality();
+
+ if ( mr == null )
+ {
+ mr = attributeType.getOrdering();
+ }
+
+ if ( mr == null )
+ {
+ mr = attributeType.getSubstr();
+ }
+
+ return mr;
+ }
+
+
+ private Normalizer getNormalizer() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getNormalizer();
+ }
+
+
+ private Comparator getComparator() throws NamingException
+ {
+ MatchingRule mr = getMatchingRule();
+
+ if ( mr == null )
+ {
+ return null;
+ }
+
+ return mr.getComparator();
}
@@ -158,6 +192,47 @@
// recover by using non-normalized values
return get().hashCode();
+ }
+ }
+
+
+ public int compareTo( Value<String> value )
+ {
+ if ( value == null && get() == null )
+ {
+ return 0;
+ }
+
+ if ( value != null && get() == null )
+ {
+ if ( value.get() == null )
+ {
+ return 0;
+ }
+ return -1;
+ }
+
+ if ( value == null )
+ {
+ return 1;
+ }
+
+
+ try
+ {
+ if ( value instanceof ServerStringValue )
+ {
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(),
+ ( ( ServerStringValue ) value ).getNormalizedValue() );
+ }
+
+ //noinspection unchecked
+ return getComparator().compare( getNormalizedValue(), value.get() );
+ }
+ catch ( NamingException e )
+ {
+ throw new IllegalStateException( "Normalization failed when it should have succeeded", e );
}
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java Sat Oct 27 13:20:43 2007
@@ -18,8 +18,8 @@
*/
package org.apache.directory.server.core.entry;
+
import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.server.core.entry.InvalidValueException;
import javax.naming.NamingException;
@@ -30,17 +30,18 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public interface ServerValue<T> extends Value
+public interface ServerValue<T> extends Value<T>
{
/**
* Gets the normalized representation for the wrapped value of this ServerValue
* wrapper. Implementations
*
* @return the normalized wrapped value
- * @throws InvalidValueException if the value is not valid
- * @throws NamingException if resolution of needed schema entities fail
+ * @throws NamingException if resolution of needed schema entities fails or normalization fails
*/
- T getNormalizedValue() throws InvalidValueException, NamingException;
+ T getNormalizedValue() throws NamingException;
boolean isValid() throws NamingException;
+
+ int compareTo( ServerValue<T> value );
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java Sat Oct 27 13:20:43 2007
@@ -125,10 +125,16 @@
// check equals
assertTrue( v0.equals( v1 ) );
assertTrue( v1.equals( v0 ) );
+ assertEquals( 0, v0.compareTo( v1 ) );
+
assertTrue( v4.equals( v5 ) );
assertTrue( v5.equals( v4 ) );
+ assertEquals( 0, v4.compareTo( v5 ) );
+
assertFalse( v2.equals( v3 ) );
assertFalse( v3.equals( v2 ) );
+ assertTrue( v2.compareTo( v3 ) < 0 );
+ assertTrue( v3.compareTo( v2 ) > 0 );
// add all except v1 and v5 to a set
HashSet<ServerStringValue> set = new HashSet<ServerStringValue>();
@@ -150,42 +156,8 @@
list.add( v2 );
list.add( v4 );
- Comparator<ServerStringValue> c = new Comparator<ServerStringValue>()
- {
- public int compare( ServerStringValue o1, ServerStringValue o2 )
- {
- if ( o1 == null && o2 == null )
- {
- return 0;
- }
-
- //noinspection ConstantConditions
- if ( o1 == null && o2 != null )
- {
- if ( o2.get() == null )
- {
- return 0;
- }
- return -1;
- }
-
- //noinspection ConstantConditions
- if ( o1 != null && o2 == null )
- {
- if ( o1.get() == null )
- {
- return 0;
- }
- return 1;
- }
-
- //noinspection unchecked
- return mr.comparator.compare( o1.get(), o2.get() );
- }
- };
-
//noinspection unchecked
- Collections.sort( list, c );
+ Collections.sort( list );
assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 0 ).equals( v4 ) );
assertTrue( "since v4 equals v5 and has no value either could be at index 0 & 1", list.get( 0 ).equals( v5 ) );
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java Sat Oct 27 13:20:43 2007
@@ -20,10 +20,12 @@
package org.apache.directory.shared.ldap.entry;
-import java.util.Arrays;
-
+import org.apache.directory.shared.ldap.schema.ByteArrayComparator;
import org.apache.directory.shared.ldap.util.StringTools;
+import java.util.Arrays;
+import java.util.Comparator;
+
/**
* A wrapper around byte[] values in entries.
@@ -33,6 +35,7 @@
*/
public class BinaryValue implements Value<byte[]>
{
+ private static final Comparator<byte[]> BYTE_ARRAY_COMPARATOR = new ByteArrayComparator();
/** the wrapped binary value */
private byte[] wrapped;
@@ -141,5 +144,26 @@
}
return Arrays.equals( this.wrapped, binaryValue.wrapped );
+ }
+
+
+ public int compareTo( Value<byte[]> value )
+ {
+ if ( value == null && get() == null )
+ {
+ return 0;
+ }
+
+ if ( value == null )
+ {
+ return 1;
+ }
+
+ if ( value.get() == null )
+ {
+ return -1;
+ }
+
+ return BYTE_ARRAY_COMPARATOR.compare( wrapped, value.get() );
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java Sat Oct 27 13:20:43 2007
@@ -28,7 +28,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public interface EntryAttribute
+public interface EntryAttribute<E extends Value<?>>
{
/**
* Adds a value to this attribute. If the new value is already present in
@@ -43,7 +43,7 @@
* @param val a new value to be added which may be null
* @return true if a value was added, otherwise false
*/
- boolean add( Value<?> val );
+ boolean add( E val );
/**
@@ -85,21 +85,12 @@
/**
- * Returns a deep copy of the attribute containing all the same values. The
- * values <b>are</b> cloned.
- *
- * @return a deep clone of this attribute
- */
- EntryAttribute clone() throws CloneNotSupportedException;
-
-
- /**
* Indicates whether the specified value is one of the attribute's values.
*
* @param val the value which may be null
* @return true if this attribute contains the value, otherwise false
*/
- boolean contains( Value<?> val );
+ boolean contains( E val );
/**
@@ -145,7 +136,7 @@
*
* @return an enumeration of all values of the attribute
*/
- Iterator<Value<?>> getAll();
+ Iterator<? extends E> getAll();
/**
@@ -167,7 +158,7 @@
* @param val the value to be removed
* @return true if the value is removed, otherwise false
*/
- boolean remove( Value<?> val );
+ boolean remove( E val );
/**
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StreamedValue.java Sat Oct 27 13:20:43 2007
@@ -99,16 +99,23 @@
}
- /**
- * A shallow clone however note this is the same as a deep clone since the
- * URI is immutable.
- *
- * @return a copy of this StreamedValue
- * @throws CloneNotSupportedException
- */
- @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
- public StreamedValue clone() throws CloneNotSupportedException
+ public int compareTo( Value<URI> value )
{
- return new StreamedValue( wrapped );
+ if ( value == null && get() == null )
+ {
+ return 0;
+ }
+
+ if ( value == null )
+ {
+ return 1;
+ }
+
+ if ( value.get() == null )
+ {
+ return -1;
+ }
+
+ return wrapped.compareTo( value.get() );
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/StringValue.java Sat Oct 27 13:20:43 2007
@@ -28,9 +28,6 @@
*/
public class StringValue implements Value<String>
{
- @SuppressWarnings ( { "AnalyzingVariableNaming" } )
- static final long serialVersionUID = 2L;
-
/** the wrapped string value */
private String wrapped;
@@ -127,20 +124,27 @@
}
- /**
- * This is a shallow copy but in this case since the String is immutable
- * and thus it makes no difference if the clone is shallow or deep.
- *
- * @return a shallow copy
- */
- @SuppressWarnings ( { "CloneDoesntCallSuperClone" } )
- public Value<String> clone() throws CloneNotSupportedException
+ public int compareTo( Value<String> value )
{
- if ( wrapped == null )
+ if ( value == null && wrapped == null )
+ {
+ return 0;
+ }
+
+ if ( value != null && wrapped == null )
+ {
+ if ( value.get() == null )
+ {
+ return 0;
+ }
+ return -1;
+ }
+
+ if ( value == null || value.get() == null )
{
- return new StringValue();
+ return 1;
}
- return new StringValue( wrapped );
+ return wrapped.compareTo( value.get() );
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Value.java Sat Oct 27 13:20:43 2007
@@ -30,7 +30,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public interface Value<T> extends Serializable, Cloneable
+public interface Value<T> extends Serializable, Cloneable, Comparable<Value<T>>
{
/**
* Get the wrapped value.
@@ -46,13 +46,4 @@
* @param wrapped the value to set. Should be either a String, URI, or a byte[]
*/
void set( T wrapped );
-
-
- /**
- * Makes a deep copy of this Value.
- *
- * @return a deep copy of this Value
- * @throws CloneNotSupportedException if the clone operation is not supported
- */
- Value<?> clone() throws CloneNotSupportedException;
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java?rev=589209&r1=589208&r2=589209&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java Sat Oct 27 13:20:43 2007
@@ -29,18 +29,15 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class ByteArrayComparator implements Comparator
+public class ByteArrayComparator implements Comparator<byte[]>
{
public static final ByteArrayComparator INSTANCE = new ByteArrayComparator();
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- public int compare( Object byteArray1, Object byteArray2 )
+ public int compare( byte[] b1, byte[] b2)
{
- byte[] b1 = ( byte[] ) byteArray1;
- byte[] b2 = ( byte[] ) byteArray2;
-
// -------------------------------------------------------------------
// Handle some basis cases
// -------------------------------------------------------------------