2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api.elements.constraints;
23 import java.util.Arrays;
25 public class Equal extends Constraint {
27 protected void setValues() {
29 setConstraintKey(EQUAL);
30 validPropTypes.addAll(Arrays.asList(Schema.PROPERTY_TYPES));
34 public Equal(String name, String type, Object c) {
39 protected boolean isValid(Object val) {
40 // equality of objects is tricky so we're comparing
41 // the toString() representation
42 return val.toString().equals(constraintValue.toString());
45 protected String errMsg(Object value) {
46 return String.format("The value \"%s\" of property \"%s\" is not equal to \"%s\"",
47 valueMsg, propertyName, constraintValueMsg);
54 class Equal(Constraint):
55 """Constraint class for "equal"
57 Constrains a property or parameter to a value equal to ('=')
61 constraint_key = Constraint.EQUAL
63 valid_prop_types = Schema.PROPERTY_TYPES
65 def _is_valid(self, value):
66 if value == self.constraint_value:
71 def _err_msg(self, value):
72 return (_('The value "%(pvalue)s" of property "%(pname)s" is not '
73 'equal to "%(cvalue)s".') %
74 dict(pname=self.property_name,
75 pvalue=self.value_msg,
76 cvalue=self.constraint_value_msg))