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

de.malkusch.whoisServerList.publicSuffixList.index.array.ArrayIndex Maven / Gradle / Ivy

package de.malkusch.whoisServerList.publicSuffixList.index.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import net.jcip.annotations.Immutable;
import de.malkusch.whoisServerList.publicSuffixList.index.Index;
import de.malkusch.whoisServerList.publicSuffixList.rule.Rule;

/**
 * Array based implementation with O(n) complexity.
 *
 * @author [email protected]
 * @see Donations
 */
@Immutable
final class ArrayIndex extends Index {

    /**
     * All rules.
     */
    private final Rule[] rules;

    /**
     * Sets the rules.
     *
     * @param rules  the rules, not null
     */
    ArrayIndex(final List rules) {
        this.rules = rules.toArray(new Rule[]{});
    }

    @Override
    protected Collection findRules(final String domain) {
        List matches = new ArrayList<>();
        for (Rule rule : rules) {
            if (rule.match(domain) != null) {
                matches.add(rule);

            }
        }
        return matches;
    }

    @Override
    public List getRules() {
        return Arrays.asList(rules);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy