blob: 6e9971f716eb5800d8bd63dbf2df846523da4f97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package org.traccar.http;
import org.traccar.model.Factory;
import javax.json.JsonObject;
public class EnumFactory<T extends Enum<T> & Factory> {
private Class<T> commandTypeClass;
private String jsonKey;
public EnumFactory(Class<T> commandTypeClass, String type) {
this.commandTypeClass = commandTypeClass;
jsonKey = type;
}
public <K> K create(JsonObject json) {
Factory factory = Enum.valueOf(commandTypeClass, json.getString(jsonKey));
return (K) factory.create();
}
}
|