JsonMethods.java
1.92 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
69
70
71
72
73
74
75
76
77
78
79
80
package com.mumfrey.liteloader.transformers.event.json;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.mumfrey.liteloader.transformers.event.MethodInfo;
/**
* A simple registry of MethodInfo objects parsed from the JSON, objects which
* consume the specified MethodInfo objects will be passed an instance of this
* object at parse time.
*
* @author Adam Mummery-Smith
*/
public class JsonMethods
{
/**
* Serialised obfusctation entries
*/
private final JsonObfuscationTable obfuscation;
/**
* Method descriptors
*/
private final List<JsonDescriptor> descriptors;
/**
* Method descriptors which have been parsed from the descriptors collection
*/
private Map<String, MethodInfo> methods = new HashMap<String, MethodInfo>();
/**
* @param obfuscation
* @param descriptors
*/
public JsonMethods(JsonObfuscationTable obfuscation, List<JsonDescriptor> descriptors)
{
this.obfuscation = obfuscation;
this.descriptors = descriptors;
this.parse();
}
/**
*
*/
private void parse()
{
if (this.descriptors != null)
{
for (JsonDescriptor descriptor : this.descriptors)
{
this.methods.put(descriptor.getKey(), descriptor.parse(this.obfuscation));
}
}
}
/**
* Fetches a method descriptor by token
*
* @param token
*/
public MethodInfo get(String token)
{
String key = JsonEvents.parseToken(token);
if (key == null)
{
throw new InvalidEventJsonException("\"" + token + "\" is not a valid token");
}
MethodInfo method = this.methods.get(key);
if (method != null)
{
return method;
}
throw new InvalidEventJsonException("Could not locate method descriptor with token " + token);
}
}