aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java
blob: 48fc28f85637f03121c15db22e4ec5a8651fd354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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()));
    }

}