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

Jean-Noël Rouvignac
29.38.2016 128ba28f7c5d5ec1e2e8b08acf590e4ff2062432
Use switch statement with SearchScope instead of if statement
2 files modified
27 ■■■■■ changed files
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java 11 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/MemoryBackend.java 16 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java
@@ -511,20 +511,21 @@
     *             If {@code dn} or {@code scope} was {@code null}.
     */
    public boolean isInScopeOf(DN dn, SearchScope scope) {
        if (scope == SearchScope.BASE_OBJECT) {
        switch (scope.asEnum()) {
        case BASE_OBJECT:
            // The base DN must equal this DN.
            return equals(dn);
        } else if (scope == SearchScope.SINGLE_LEVEL) {
        case SINGLE_LEVEL:
            // The parent DN must equal the base DN.
            return isChildOf(dn);
        } else if (scope == SearchScope.SUBORDINATES) {
        case SUBORDINATES:
            // This DN must be a descendant of the provided base DN, but
            // not equal to it.
            return isSubordinateOrEqualTo(dn) && !equals(dn);
        } else if (scope == SearchScope.WHOLE_SUBTREE) {
        case WHOLE_SUBTREE:
            // This DN must be a descendant of the provided base DN.
            return isSubordinateOrEqualTo(dn);
        } else {
        default:
            // This is a scope that we don't recognize.
            return false;
        }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/MemoryBackend.java
@@ -11,7 +11,7 @@
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2013-2015 ForgeRock AS.
 * Copyright 2013-2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldap;
@@ -379,18 +379,24 @@
            final Matcher matcher = filter.matcher(schema);
            final AttributeFilter attributeFilter =
                new AttributeFilter(request.getAttributes(), schema).typesOnly(request.isTypesOnly());
            if (scope.equals(SearchScope.BASE_OBJECT)) {
            switch (scope.asEnum()) {
            case BASE_OBJECT:
                final Entry baseEntry = getRequiredEntry(request, dn);
                if (matcher.matches(baseEntry).toBoolean()) {
                    sendEntry(attributeFilter, entryHandler, baseEntry);
                }
                resultHandler.handleResult(newResult(ResultCode.SUCCESS));
            } else if (scope.equals(SearchScope.SINGLE_LEVEL) || scope.equals(SearchScope.SUBORDINATES)
                || scope.equals(SearchScope.WHOLE_SUBTREE)) {
                break;
            case SINGLE_LEVEL:
            case SUBORDINATES:
            case WHOLE_SUBTREE:
                searchWithSubordinates(requestContext, entryHandler, resultHandler, dn, matcher, attributeFilter,
                    request.getSizeLimit(), scope,
                    request.getControl(SimplePagedResultsControl.DECODER, new DecodeOptions()));
            } else {
                break;
            default:
                throw newLdapException(ResultCode.PROTOCOL_ERROR,
                        "Search request contains an unsupported search scope");
            }