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
|
package org.openecomp.sdc.toscaparser.utils;
import static java.util.stream.Collectors.toMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public enum PythonType {
INT("int", Integer.class),
FLOAT("float", Double.class),
BOOL("bool", Boolean.class),
STR("str", String.class),
LIST("list", List.class),
DICT("dict", Map.class),
UNKNOWN("", Object.class);
private static final Map<String, PythonType> NAME_TO_TYPE;
private final String typeName;
private final Class<?> javaClass;
static {
NAME_TO_TYPE = Arrays.stream(values())
.filter(type -> type != UNKNOWN)
.collect(toMap(PythonType::getTypeName, Function.identity()));
}
private PythonType(String typeName, Class<?> javaClass) {
this.typeName = typeName;
this.javaClass = javaClass;
}
public static PythonType fromName(String name) {
PythonType pythonType = NAME_TO_TYPE.get(name);
return pythonType != null ? pythonType : UNKNOWN;
}
public String getTypeName() {
return typeName;
}
public Class<?> getJavaClass() {
return javaClass;
}
}
|