All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.security.auth.client.RuleNode Maven / Gradle / Ivy

The newest version!
/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2016 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed 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.wildfly.security.auth.client;

/**
 * @author David M. Lloyd
 */
class RuleNode {
    final RuleNode next;
    final MatchRule rule;
    final T configuration;

    RuleNode(final RuleNode next, final MatchRule rule, final T configuration) {
        this.next = next;
        this.rule = rule;
        this.configuration = configuration;
    }

    RuleNode getNext() {
        return next;
    }

    MatchRule getRule() {
        return rule;
    }

    T getConfiguration() {
        return configuration;
    }

    RuleNode without(int idx) {
        if (idx < 0) {
            throw new IndexOutOfBoundsException();
        }
        final RuleNode next = this.next;
        if (idx == 0) {
            return next;
        }
        if (next == null) {
            throw new IndexOutOfBoundsException();
        }
        return new RuleNode(next.without(idx - 1), rule, configuration);
    }

    RuleNode with(MatchRule rule, T configuration, int idx) {
        if (idx < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (idx == 0) {
            return new RuleNode(this, rule, configuration);
        }
        final RuleNode next = this.next;
        if (next == null) {
            throw new IndexOutOfBoundsException();
        }
        return new RuleNode(next.with(rule, configuration, idx - 1), this.rule, this.configuration);
    }

    RuleNode with(final MatchRule rule, final T configuration) {
        return withAll(new RuleNode(null, rule, configuration));
    }

    RuleNode withAll(RuleNode other) {
        final RuleNode next = this.next;
        if (next == null) {
            return new RuleNode(other, rule, configuration);
        } else {
            return new RuleNode(next.withAll(other), rule, configuration);
        }
    }

    RuleNode withAll(final RuleNode authRules, final int idx) {
        if (idx < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (idx == 0) {
            return authRules.withAll(this);
        }
        final RuleNode next = this.next;
        if (next == null) {
            throw new IndexOutOfBoundsException();
        }
        return new RuleNode(next.withAll(authRules, idx - 1), rule, configuration);
    }

    RuleNode replacing(final MatchRule rule, final T configuration, final int idx) {
        if (idx < 0) {
            throw new IndexOutOfBoundsException();
        }
        final RuleNode next = this.next;
        if (idx == 0) {
            return new RuleNode(next, rule, configuration);
        }
        if (next == null) {
            throw new IndexOutOfBoundsException();
        }
        return new RuleNode(next.replacing(rule, configuration, idx - 1), this.rule, this.configuration);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy