2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.be.model.tosca;
23 import java.text.DateFormat;
24 import java.text.ParseException;
25 import java.util.Locale;
28 * The primitive type that TOSCA YAML supports.
32 public enum ToscaType {
33 STRING, INTEGER, FLOAT, BOOLEAN, TIMESTAMP, VERSION;
35 public boolean isValidValue(String value) {
38 return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false");
40 return isFloat(value);
42 return isInteger(value);
47 DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
49 } catch (ParseException e) {
53 return VersionUtil.isValid(value);
59 private boolean isFloat(String value) {
62 } catch (NumberFormatException e) {
68 private boolean isInteger(String value) {
71 } catch (NumberFormatException e) {
77 public Object convert(String value) {
82 return Boolean.valueOf(value);
84 return Double.valueOf(value);
86 return Long.valueOf(value);
89 return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).parse(value);
90 } catch (ParseException e) {
91 throw new IllegalArgumentException("Value must be a valid timestamp", e);
94 return VersionUtil.parseVersion(value);
101 public String toString() {
102 return name().toLowerCase();