re base code
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / tosca / ToscaType.java
index 88642f8..92c564c 100644 (file)
@@ -30,91 +30,75 @@ import java.util.Locale;
  * @author mkv
  */
 public enum ToscaType {
-       STRING, INTEGER, FLOAT, BOOLEAN, TIMESTAMP, VERSION;
+    STRING, INTEGER, FLOAT, BOOLEAN, TIMESTAMP, VERSION;
 
-       // private static final Pattern TIMESTAMP_REGEX = Pattern
-       // .compile("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?([Tt]|[
-       // \\t]+)[0-9][0-9]?:[0-9][0-9]:[0-9][0-9](\\.[0-9]*)?(([ \\t]*)Z|([
-       // \\t]*)[-+][0-9][0-9]?(:[0-9][0-9])?)?");
+    public boolean isValidValue(String value) {
+        switch (this) {
+        case BOOLEAN:
+            return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false");
+        case FLOAT:
+            return isFloat(value);
+        case INTEGER:
+            return isInteger(value);
+        case STRING:
+            return true;
+        case TIMESTAMP:
+            try {
+                DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
+                return true;
+            } catch (ParseException e) {
+                return false;
+            }
+        case VERSION:
+            return VersionUtil.isValid(value);
+        default:
+            return false;
+        }
+    }
 
-       public static ToscaType fromYamlTypeName(String typeName) {
-               if (typeName == null) {
-                       return null;
-               }
-               try {
-                       return ToscaType.valueOf(typeName.toUpperCase());
-               } catch (IllegalArgumentException e) {
-                       return null;
-               }
-       }
+    private boolean isFloat(String value) {
+        try {
+            Float.valueOf(value);
+        } catch (NumberFormatException e) {
+            return false;
+        }
+        return true;
+    }
 
-       public boolean isValidValue(String value) {
-               switch (this) {
-               case BOOLEAN:
-                       return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false");
-               case FLOAT:
-                       return isFloat(value);
-               case INTEGER:
-                       return isInteger(value);
-               case STRING:
-                       return true;
-               case TIMESTAMP:
-                       try {
-                               DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
-                               return true;
-                       } catch (ParseException e) {
-                               return false;
-                       }
-               case VERSION:
-                       return VersionUtil.isValid(value);
-               default:
-                       return false;
-               }
-       }
+    private boolean isInteger(String value) {
+        try {
+            Long.valueOf(value);
+        } catch (NumberFormatException e) {
+            return false;
+        }
+        return true;
+    }
 
-       private boolean isFloat(String value) {
-               try {
-                       Float.valueOf(value);
-               } catch (NumberFormatException e) {
-                       return false;
-               }
-               return true;
-       }
+    public Object convert(String value) {
+        switch (this) {
+        case STRING:
+            return value;
+        case BOOLEAN:
+            return Boolean.valueOf(value);
+        case FLOAT:
+            return Double.valueOf(value);
+        case INTEGER:
+            return Long.valueOf(value);
+        case TIMESTAMP:
+            try {
+                return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
+            } catch (ParseException e) {
+                throw new IllegalArgumentException("Value must be a valid timestamp", e);
+            }
+        case VERSION:
+            return VersionUtil.parseVersion(value);
+        default:
+            return null;
+        }
+    }
 
-       private boolean isInteger(String value) {
-               try {
-                       Long.valueOf(value);
-               } catch (NumberFormatException e) {
-                       return false;
-               }
-               return true;
-       }
-
-       public Object convert(String value) {
-               switch (this) {
-               case STRING:
-                       return value;
-               case BOOLEAN:
-                       return Boolean.valueOf(value);
-               case FLOAT:
-                       return Double.valueOf(value);
-               case INTEGER:
-                       return Long.valueOf(value);
-               case TIMESTAMP:
-                       try {
-                               return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
-                       } catch (ParseException e) {
-                               throw new IllegalArgumentException("Value must be a valid timestamp", e);
-                       }
-               case VERSION:
-                       return VersionUtil.parseVersion(value);
-               default:
-                       return null;
-               }
-       }
-
-       @Override
-       public String toString() {
-               return name().toLowerCase();
-       }
+    @Override
+    public String toString() {
+        return name().toLowerCase();
+    }
 }