diff options
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java | 100 |
1 files changed, 44 insertions, 56 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java index 738f5150e3..0b35a9be8e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraint.java @@ -20,73 +20,61 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import java.io.Serializable; -import java.util.List; -import java.util.Set; - -import javax.validation.constraints.NotNull; - +import com.google.common.collect.Sets; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException; -//import com.fasterxml.jackson.annotation.JsonIgnore; -import com.google.common.collect.Sets; - -public class ValidValuesConstraint extends AbstractPropertyConstraint implements Serializable { +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Set; - /** - * - */ - private static final long serialVersionUID = 5906087180079892853L; +public class ValidValuesConstraint extends AbstractPropertyConstraint { - @NotNull - private List<String> validValues; - // @JsonIgnore - private Set<Object> validValuesTyped; + @NotNull + private List<String> validValues; + private Set<Object> validValuesTyped; - public ValidValuesConstraint(List<String> validValues) { - super(); - this.validValues = validValues; - } + public ValidValuesConstraint(List<String> validValues) { + this.validValues = validValues; + } - public ValidValuesConstraint() { - super(); - } + public ValidValuesConstraint() { + } - @Override - public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException { - validValuesTyped = Sets.newHashSet(); - if (validValues == null) { - throw new ConstraintValueDoNotMatchPropertyTypeException( - "validValues constraint has invalid value <> property type is <" + propertyType.toString() + ">"); - } - for (String value : validValues) { - if (!propertyType.isValidValue(value)) { - throw new ConstraintValueDoNotMatchPropertyTypeException("validValues constraint has invalid value <" - + value + "> property type is <" + propertyType.toString() + ">"); - } else { - validValuesTyped.add(propertyType.convert(value)); - } - } - } + @Override + public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException { + validValuesTyped = Sets.newHashSet(); + if (validValues == null) { + throw new ConstraintValueDoNotMatchPropertyTypeException( + "validValues constraint has invalid value <> property type is <" + propertyType.toString() + ">"); + } + for (String value : validValues) { + if (!propertyType.isValidValue(value)) { + throw new ConstraintValueDoNotMatchPropertyTypeException("validValues constraint has invalid value <" + + value + "> property type is <" + propertyType.toString() + ">"); + } else { + validValuesTyped.add(propertyType.convert(value)); + } + } + } - @Override - public void validate(Object propertyValue) throws ConstraintViolationException { - if (propertyValue == null) { - throw new ConstraintViolationException("Value to validate is null"); - } - if (!validValuesTyped.contains(propertyValue)) { - throw new ConstraintViolationException("The value is not in the list of valid values"); - } - } + @Override + public void validate(Object propertyValue) throws ConstraintViolationException { + if (propertyValue == null) { + throw new ConstraintViolationException("Value to validate is null"); + } + if (!validValuesTyped.contains(propertyValue)) { + throw new ConstraintViolationException("The value is not in the list of valid values"); + } + } - public List<String> getValidValues() { - return validValues; - } + public List<String> getValidValues() { + return validValues; + } - public void setValidValues(List<String> validValues) { - this.validValues = validValues; - } + public void setValidValues(List<String> validValues) { + this.validValues = validValues; + } } |