Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / elements / constraints / Equal.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.sdc.toscaparser.api.elements.constraints;
22
23 import java.util.Arrays;
24
25 public class Equal extends Constraint {
26
27     protected void setValues() {
28
29         setConstraintKey(EQUAL);
30         validPropTypes.addAll(Arrays.asList(Schema.PROPERTY_TYPES));
31
32     }
33
34     public Equal(String name, String type, Object c) {
35         super(name, type, c);
36
37     }
38
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());
43     }
44
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);
48     }
49
50 }
51
52 /*python
53
54 class Equal(Constraint):
55 """Constraint class for "equal"
56
57 Constrains a property or parameter to a value equal to ('=')
58 the value declared.
59 """
60
61 constraint_key = Constraint.EQUAL
62
63 valid_prop_types = Schema.PROPERTY_TYPES
64
65 def _is_valid(self, value):
66     if value == self.constraint_value:
67         return True
68
69     return False
70
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))
77 */