mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
05.25.2014 f0c7d2dd4fa25e1b91f576a75b61488ce2a4fa30
OPENDJ-1581 CR-5092 Move UNDEFINED_ASSERTION and DEFAULT_COMPARATOR
constants from AbstractMatchingRuleImpl to Assertion interface
2 files modified
51 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java 27 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java 24 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java
@@ -26,6 +26,9 @@
 */
package org.forgerock.opendj.ldap;
import java.util.Comparator;
import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
/**
@@ -33,6 +36,29 @@
 */
public interface Assertion {
    /** An assertion that always return UNDEFINED for matches and that creates a match all query. */
    public static final Assertion UNDEFINED_ASSERTION = new Assertion() {
        @Override
        public ConditionResult matches(final ByteSequence normalizedAttributeValue) {
            return ConditionResult.UNDEFINED;
        }
        @Override
        public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
            // Subclassing this class will always work, albeit inefficiently.
            // This is better than throwing an exception for no good reason.
            return factory.createMatchAllQuery();
        }
    };
    /** A default ByteSequence comparator. */
    public static final Comparator<ByteSequence> DEFAULT_COMPARATOR = new Comparator<ByteSequence>() {
        @Override
        public int compare(final ByteSequence o1, final ByteSequence o2) {
            return o1.compareTo(o2);
        }
    };
    /**
     * Indicates whether the provided attribute value should be considered a
     * match for this assertion value according to the matching rule.
@@ -60,4 +86,5 @@
     *           If an error occurs while generating the index query.
     */
    <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException;
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
@@ -39,6 +39,8 @@
import org.forgerock.opendj.ldap.spi.Indexer;
import org.forgerock.opendj.ldap.spi.IndexingOptions;
import static org.forgerock.opendj.ldap.Assertion.*;
/**
 * This class implements a default equality or approximate matching rule that
 * matches normalized values in byte order.
@@ -98,28 +100,6 @@
        }
    }
    private static final Assertion UNDEFINED_ASSERTION = new Assertion() {
        @Override
        public ConditionResult matches(final ByteSequence normalizedAttributeValue) {
            return ConditionResult.UNDEFINED;
        }
        @Override
        public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
            // Subclassing this class will always work, albeit inefficiently.
            // This is better than throwing an exception for no good reason.
            return factory.createMatchAllQuery();
        }
    };
    private static final Comparator<ByteSequence> DEFAULT_COMPARATOR =
            new Comparator<ByteSequence>() {
                @Override
                public int compare(final ByteSequence o1, final ByteSequence o2) {
                    return o1.compareTo(o2);
                }
            };
    AbstractMatchingRuleImpl() {
        // Nothing to do.
    }