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

com.netflix.conductor.common.constraints.NoSemiColonConstraint Maven / Gradle / Ivy

There is a newer version: 3.15.0
Show newest version
package com.netflix.conductor.common.constraints;

import com.google.common.base.Strings;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;

/**
 *  This constraint checks semi-colon is not allowed in a given string.
 */
@Documented
@Constraint(validatedBy = NoSemiColonConstraint.NoSemiColonValidator.class)
@Target({FIELD, PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface NoSemiColonConstraint {
    String message() default "String: cannot contain the following set of characters: ':'";

    Class[] groups() default {};

    Class[] payload() default {};

    class NoSemiColonValidator implements ConstraintValidator {

        @Override
        public void initialize(NoSemiColonConstraint constraintAnnotation) {
        }

        @Override
        public boolean isValid(String value, ConstraintValidatorContext context) {
            boolean valid = true;

            if (!Strings.isNullOrEmpty(value) && value.contains(":")) {
                valid = false;
            }

            return valid;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy