diff options
author | vasraz <vasyl.razinkov@est.tech> | 2019-11-14 11:24:56 +0000 |
---|---|---|
committer | vasraz <vasyl.razinkov@est.tech> | 2019-11-18 09:56:55 +0000 |
commit | 134bed676f01745969408d522ca9ac6c482ba549 (patch) | |
tree | 03454c5d7f899ed67653c590ad190cac4a78718f /sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java | |
parent | f5bde6a64eaaa32fd4cfebfd7589c066962c7ddf (diff) |
Move jTosca contents to sdc-tosca
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I5c47a8fd7d4ff295149d1d9b29aea71ae56cbcd4
Issue-ID: SDC-2457
Diffstat (limited to 'sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java')
-rw-r--r-- | sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java b/sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java new file mode 100644 index 0000000..656f3ce --- /dev/null +++ b/sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-tosca + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.enums; + + +import java.util.Arrays; +import java.util.NoSuchElementException; + +import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.Complex; +import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.DataType; +import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.Simple; + +public enum PropertySchemaType { + + STRING(Simple, "string"), + INTEGER(Simple, "integer"), + BOOLEAN(Simple, "boolean"), + FLOAT(Simple, "float"), + NUMBER(Simple, "number"), + TIMESTAMP(Simple, "timestamp"), + RANGE(Simple, "range"), + VERSION(Simple, "version"), + SCALAR_UNIT_SIZE(Simple, "scalar-unit.size"), + SCALAR_UNIT_TIME(Simple, "scalar-unit.time"), + SCALAR_UNIT_FREQUENCY(Simple, "scalar-unit.frequency"), + LIST(Complex, "list"), + MAP(Complex, "map"), + DATATYPE(DataType, "datatypes"); + + private PropertySchemaComplexity complexity; + private String schemaType; + + PropertySchemaType(PropertySchemaComplexity complexity, String schemaType) { + this.complexity = complexity; + this.schemaType = schemaType; + } + + public PropertySchemaComplexity getSchemaTypeComplexity() { + return complexity; + } + + public String getSchemaTypeName() { + return schemaType; + } + + public enum PropertySchemaComplexity { + Simple, Complex, DataType + } + + public static PropertySchemaType getEnumByValue(String type){ + if (type == null) { + throwNoSuchElementException(null); + } + + if (type.contains(DATATYPE.getSchemaTypeName())) { + return DATATYPE; + } + PropertySchemaType propertySchemaType = Arrays.stream(PropertySchemaType.values()) + .filter(v->v.getSchemaTypeName().equals(type)) + .findFirst().orElse(null); + if (propertySchemaType == null) { + throwNoSuchElementException(type); + } + return propertySchemaType; + } + + private static void throwNoSuchElementException(String type) { + throw new NoSuchElementException(String.format("Value %s is not defined in %s", type, PropertySchemaType.class.getName())); + } + +} |