Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / elements / constraints / InRange.java
index 32719fa..4edf021 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,7 @@ package org.onap.sdc.toscaparser.api.elements.constraints;
 import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
 import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
 
+import java.util.Arrays;
 import java.util.Date;
 
 import java.util.ArrayList;
@@ -34,95 +35,89 @@ public class InRange extends Constraint {
     //the two values declared.
 
     private static final String UNBOUNDED = "UNBOUNDED";
-    
-    private Object min,max;
-
-       protected void _setValues() {
-
-               constraintKey = IN_RANGE;
-
-               validTypes.add("Integer");
-               validTypes.add("Double");
-               validTypes.add("Float");
-               validTypes.add("String");
-               // timestamps are loaded as Date objects
-               validTypes.add("Date");
-               //validTypes.add("datetime.date");
-               //validTypes.add("datetime.time");
-               //validTypes.add("datetime.datetime");
-               
-               validPropTypes.add(Schema.INTEGER);
-               validPropTypes.add(Schema.FLOAT);
-               validPropTypes.add(Schema.TIMESTAMP);
-               validPropTypes.add(Schema.SCALAR_UNIT_SIZE);
-               validPropTypes.add(Schema.SCALAR_UNIT_FREQUENCY);
-               validPropTypes.add(Schema.SCALAR_UNIT_TIME);
-               validPropTypes.add(Schema.RANGE);
-               
-       }
-       
-       @SuppressWarnings("unchecked")
-       public InRange(String name,String type,Object c) {
-               super(name,type,c);
-
-               if(!(constraintValue instanceof ArrayList) || ((ArrayList<Object>)constraintValue).size() != 2) {
+
+    private Object min, max;
+
+    protected void setValues() {
+
+        setConstraintKey(IN_RANGE);
+
+        // timestamps are loaded as Date objects
+        addValidTypes(Arrays.asList("Integer", "Double", "Float", "String", "Date"));
+        //validTypes.add("datetime.date");
+        //validTypes.add("datetime.time");
+        //validTypes.add("datetime.datetime");
+
+        validPropTypes.add(Schema.INTEGER);
+        validPropTypes.add(Schema.FLOAT);
+        validPropTypes.add(Schema.TIMESTAMP);
+        validPropTypes.add(Schema.SCALAR_UNIT_SIZE);
+        validPropTypes.add(Schema.SCALAR_UNIT_FREQUENCY);
+        validPropTypes.add(Schema.SCALAR_UNIT_TIME);
+        validPropTypes.add(Schema.RANGE);
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public InRange(String name, String type, Object c) {
+        super(name, type, c);
+
+        if (!(constraintValue instanceof ArrayList) || ((ArrayList<Object>) constraintValue).size() != 2) {
             ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE106", "InvalidSchemaError: The property \"in_range\" expects a list"));
-                       
-               }
 
-               ArrayList<Object> alcv = (ArrayList<Object>)constraintValue;
+        }
+
+        ArrayList<Object> alcv = (ArrayList<Object>) constraintValue;
         String msg = "The property \"in_range\" expects comparable values";
-        for(Object vo: alcv) {
-               if(!validTypes.contains(vo.getClass().getSimpleName())) {
-               ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE107", "InvalidSchemaError: " + msg)); 
-               }
+        for (Object vo : alcv) {
+            if (!validTypes.contains(vo.getClass().getSimpleName())) {
+                ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE107", "InvalidSchemaError: " + msg));
+            }
             // The only string we allow for range is the special value 'UNBOUNDED'
-            if((vo instanceof String) && !((String)vo).equals(UNBOUNDED)) { 
-                               ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE108", "InvalidSchemaError: " + msg)); 
+            if ((vo instanceof String) && !((String) vo).equals(UNBOUNDED)) {
+                ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE108", "InvalidSchemaError: " + msg));
             }
         }
         min = alcv.get(0);
         max = alcv.get(1);
-        
-       }
-
-       @Override
-       protected boolean _isValid(Object value) {
-               
-               // timestamps
-               if(value instanceof Date) {
-                       if(min instanceof Date && max instanceof Date) {
-                               return !((Date)value).before((Date)min) &&
-                                          !((Date)value).after((Date)max);
-                       }
-                       return false;
-               }
-
-               Double dvalue = new Double(value.toString());
-        if(!(min instanceof String)) {
-            if(dvalue < new Double(min.toString())) {
-                return false;
+
+    }
+
+    @Override
+    protected boolean isValid(Object value) {
+
+        // timestamps
+        if (value instanceof Date) {
+            if (min instanceof Date && max instanceof Date) {
+                return !((Date) value).before((Date) min)
+                        && !((Date) value).after((Date) max);
             }
-        }
-        else if(!((String)min).equals(UNBOUNDED)) {
             return false;
         }
-        if(!(max instanceof String)) {
-            if(dvalue > new Double(max.toString())) {
+
+        Double dvalue = new Double(value.toString());
+        if (!(min instanceof String)) {
+            if (dvalue < new Double(min.toString())) {
                 return false;
             }
+        } else if (!((String) min).equals(UNBOUNDED)) {
+            return false;
         }
-        else if(!((String)max).equals(UNBOUNDED)) {
+        if (!(max instanceof String)) {
+            if (dvalue > new Double(max.toString())) {
+                return false;
+            }
+        } else if (!((String) max).equals(UNBOUNDED)) {
             return false;
         }
         return true;
-       }
+    }
 
-       @Override
-       protected String _errMsg(Object value) {
+    @Override
+    protected String errMsg(Object value) {
         return String.format("The value \"%s\" of property \"%s\" is out of range \"(min:%s, max:%s)\"",
-                                               valueMsg,propertyName,min.toString(),max.toString());
-       }
+                valueMsg, propertyName, min.toString(), max.toString());
+    }
 
 }