-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathType.java
More file actions
68 lines (60 loc) · 1.69 KB
/
Copy pathType.java
File metadata and controls
68 lines (60 loc) · 1.69 KB
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
package io.cloudevents.sql;
import java.util.Objects;
/**
* Type represents any of the types supported by the CloudEvents Expression Language and their relative Java classes.
*/
public enum Type {
/**
* The <i>Integer</i> type
*/
INTEGER(Integer.class),
/**
* The <i>String</i> type
*/
STRING(String.class),
/**
* The <i>Boolean</i> type
*/
BOOLEAN(Boolean.class),
/**
* Any is a catch-all type that can be used to represent any of the above types in a function signature.
*/
ANY(Object.class);
private final Class<?> clazz;
Type(Class<?> clazz) {
this.clazz = clazz;
}
/**
* @return the Java class corresponding to the CloudEvents Expression Language type.
*/
public Class<?> valueClass() {
return clazz;
}
/**
* Compute the CloudEvents Expression Language type from a value.
*
* @param value the value to use
* @return the type, or any if the value class is unrecognized.
*/
public static Type fromValue(Object value) {
Objects.requireNonNull(value);
return fromClass(value.getClass());
}
/**
* Compute the CloudEvents Expression Language type from a Java class.
*
* @param clazz the class to use
* @return the type, or any if the class is unrecognized.
*/
public static Type fromClass(Class<?> clazz) {
Objects.requireNonNull(clazz);
if (Integer.class.equals(clazz)) {
return INTEGER;
} else if (String.class.equals(clazz)) {
return STRING;
} else if (Boolean.class.equals(clazz)) {
return BOOLEAN;
}
return ANY;
}
}