blob: efbfd4b204d0c28f0a40fb41fc0f235011d2bea8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package org.traccar.web;
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();
}
}
|