// Path: library/src/main/java/de/mrapp/android/validation/Constraint.java
// public interface Constraint<Type> {
// 
//     /**
//      * Returns, whether a specific value satisfies the constraint, or not.
//      *
//      * @param value
//      *         The value, which should be verified, as an instance of the generic type Type
//      * @return True, if the given value satisfies the constraint, false otherwise
//      */
//     boolean isSatisfied(Type value);
// 
// }


import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.NonNull;
import de.mrapp.android.validation.Constraint;
import de.mrapp.util.Condition;
/*
 * Copyright 2015 - 2019 Michael Rapp
 *
 * 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 de.mrapp.android.validation.constraints.text;



/**
 * A constraint, which allows to verify a text in order to check, if it matches a certain regular
 * expression.
 *
 * @author Michael Rapp
 * @since 1.0.0
 */
public class RegexConstraint implements Constraint<CharSequence> {

    /**
     * The regular expression, which is used to verify the texts.
     */
    private Pattern regex;

    /**
     * Creates a new constraint, which allows to verify a text in order to check, if it matches a
     * certain regular expression.
     *
     * @param regex
     *         The regular expression, which should be used to verify the texts, as an instance of
     *         the class {@link Pattern}. The regular expression may not be null
     */
    public RegexConstraint(@NonNull final Pattern regex) {
        setRegex(regex);
    }

    /**
     * Returns the regular expression, which is used to verify the texts.
     *
     * @return The regular expression, which is used to verify the texts, as an instance of the
     * class {@link Pattern}
     */
    public final Pattern getRegex() {
        return regex;
    }

    /**
     * Sets the regular expression, which should be used to verify the texts.
     *
     * @param regex
     *         The regular expression, which should be set, as an instance of the class {@link
     *         Pattern}. The regular expression may not be null
     */
    public final void setRegex(@NonNull final Pattern regex) {
        Condition.INSTANCE.ensureNotNull(regex, "The regular expression may not be null");
// Path: library/src/main/java/de/mrapp/android/validation/Constraint.java
// public interface Constraint<Type> {
// 
//     /**
//      * Returns, whether a specific value satisfies the constraint, or not.
//      *
//      * @param value
//      *         The value, which should be verified, as an instance of the generic type Type
//      * @return True, if the given value satisfies the constraint, false otherwise
//      */
//     boolean isSatisfied(Type value);
// 
// }


// Path: library/src/main/java/de/mrapp/android/validation/constraints/text/RegexConstraint.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.annotation.NonNull;
import de.mrapp.android.validation.Constraint;
import de.mrapp.util.Condition;

/*
 * Copyright 2015 - 2019 Michael Rapp
 *
 * 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 de.mrapp.android.validation.constraints.text;



/**
 * A constraint, which allows to verify a text in order to check, if it matches a certain regular
 * expression.
 *
 * @author Michael Rapp
 * @since 1.0.0
 */
public class RegexConstraint implements Constraint<CharSequence> {

    /**
     * The regular expression, which is used to verify the texts.
     */
    private Pattern regex;

    /**
     * Creates a new constraint, which allows to verify a text in order to check, if it matches a
     * certain regular expression.
     *
     * @param regex
     *         The regular expression, which should be used to verify the texts, as an instance of
     *         the class {@link Pattern}. The regular expression may not be null
     */
    public RegexConstraint(@NonNull final Pattern regex) {
        setRegex(regex);
    }

    /**
     * Returns the regular expression, which is used to verify the texts.
     *
     * @return The regular expression, which is used to verify the texts, as an instance of the
     * class {@link Pattern}
     */
    public final Pattern getRegex() {
        return regex;
    }

    /**
     * Sets the regular expression, which should be used to verify the texts.
     *
     * @param regex
     *         The regular expression, which should be set, as an instance of the class {@link
     *         Pattern}. The regular expression may not be null
     */
    public final void setRegex(@NonNull final Pattern regex) {
        Condition.INSTANCE.ensureNotNull(regex, "The regular expression may not be null");
        this.regex = regex;