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

io.rtr.alchemy.models.Named Maven / Gradle / Ivy

There is a newer version: 2.2.16
Show newest version
package io.rtr.alchemy.models;

import java.util.regex.Pattern;

import javax.validation.ValidationException;

public interface Named {
    Pattern NAME_PATTERN = Pattern.compile("^[A-Za-z0-9-_]+$");

    String getName();

    default void validateName() {
        if (getName() == null || !NAME_PATTERN.matcher(getName()).matches()) {
            throw new ValidationException(
                    String.format(
                            "Invalid name %s, must match %s", getName(), NAME_PATTERN.pattern()));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy