-
Notifications
You must be signed in to change notification settings - Fork 4
/
ResourceFormat.java
32 lines (26 loc) · 1002 Bytes
/
ResourceFormat.java
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
package cz.cvut.spipes.modules;
import cz.cvut.spipes.modules.exception.ValueNotFoundException;
import java.util.Arrays;
import java.util.stream.Collectors;
public enum ResourceFormat {
PLAIN("text/plain"),
CSV("text/csv"),
TSV("text/tab-separated-values"),
HTML("text/html"),
EXCEL("application/vnd.ms-excel");
private final String value;
public String getValue() {
return value;
}
public static ResourceFormat fromString(String value) {
return Arrays.stream(ResourceFormat.values())
.filter(d -> d.getValue().equals(value))
.findAny().orElseThrow(() -> new ValueNotFoundException(
"Value " + value + " not recognized among valid values of this type, i.e. " +
Arrays.stream(ResourceFormat.values()).map(ResourceFormat::getValue).collect(Collectors.toList())
));
}
ResourceFormat(String value) {
this.value = value;
}
}