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

de.malkusch.whoisServerList.publicSuffixList.rule.RuleFactory Maven / Gradle / Ivy

package de.malkusch.whoisServerList.publicSuffixList.rule;

import net.jcip.annotations.Immutable;

/**
 * The rule factory.
 *
 * This factory builds {@link Rule} objects from rule strings.
 *
 * @author [email protected]
 * @see Donations
 */
@Immutable
public final class RuleFactory {

    /**
     * Builds a {@code Rule}.
     *
     * The rule pattern is as it was in the Public Suffix List.
     * I.e. including the wildcards and exception token.
     *
     * @param pattern  the rule pattern, not null
     * @return the rule, not null
     */
    public Rule build(final String pattern) {
        boolean exceptionRule = pattern.charAt(0) == Rule.EXCEPTION_TOKEN;
        String matchPattern = exceptionRule ? pattern.substring(1) : pattern;

        Rule rule = new Rule(matchPattern, exceptionRule);

        return rule;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy