/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.util.ArrayList
 *  java.util.Collection
 *  java.util.Collections
 *  java.util.List
 */
package org.dom4j.rule;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.dom4j.Node;
import org.dom4j.rule.Rule;

public class RuleSet {
    private Rule[] ruleArray;
    private ArrayList rules = new ArrayList();

    public void addAll(RuleSet ruleSet) {
        this.rules.addAll((Collection)ruleSet.rules);
        this.ruleArray = null;
    }

    public void addRule(Rule rule) {
        this.rules.add((Object)rule);
        this.ruleArray = null;
    }

    public Rule getMatchingRule(Node node) {
        Rule[] arrrule = this.getRuleArray();
        for (int i = -1 + arrrule.length; i >= 0; --i) {
            Rule rule = arrrule[i];
            if (!rule.matches(node)) continue;
            return rule;
        }
        return null;
    }

    protected Rule[] getRuleArray() {
        if (this.ruleArray == null) {
            Collections.sort((List)this.rules);
            this.ruleArray = new Rule[this.rules.size()];
            this.rules.toArray(this.ruleArray);
        }
        return this.ruleArray;
    }

    public void removeRule(Rule rule) {
        this.rules.remove((Object)rule);
        this.ruleArray = null;
    }

    public String toString() {
        return new StringBuffer().append(super.toString()).append(" [RuleSet: ").append((Object)this.rules).append(" ]").toString();
    }
}

