Skip to content

Commit 5538581

Browse files
committed
refactor(GLConstants): leverage Optional java class
1 parent 73a1fa4 commit 5538581

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

src/main/java/org/mcphackers/mcp/tools/injector/GLConstants.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package org.mcphackers.mcp.tools.injector;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.HashMap;
6-
import java.util.Iterator;
7-
import java.util.List;
8-
import java.util.Map;
3+
import java.io.InputStream;
4+
import java.util.*;
95
import java.util.Map.Entry;
106

117
import org.json.JSONArray;
@@ -15,14 +11,7 @@
1511
import org.mcphackers.rdi.util.IdentifyCall;
1612
import org.mcphackers.rdi.util.Pair;
1713
import org.objectweb.asm.Opcodes;
18-
import org.objectweb.asm.tree.AbstractInsnNode;
19-
import org.objectweb.asm.tree.FieldInsnNode;
20-
import org.objectweb.asm.tree.InsnList;
21-
import org.objectweb.asm.tree.InsnNode;
22-
import org.objectweb.asm.tree.IntInsnNode;
23-
import org.objectweb.asm.tree.LdcInsnNode;
24-
import org.objectweb.asm.tree.MethodInsnNode;
25-
import org.objectweb.asm.tree.MethodNode;
14+
import org.objectweb.asm.tree.*;
2615

2716
public final class GLConstants extends ClassVisitor {
2817

@@ -33,18 +22,14 @@ public final class GLConstants extends ClassVisitor {
3322
private static final char[] OPERATORS = {'|', '&', '^'};
3423

3524
static {
36-
JSONObject json = JSONUtil.getJSON(GLConstants.class.getClassLoader().getResourceAsStream("gl_constants.json"));
37-
if (json != null) {
38-
CONSTANTS = getConstants(json.optJSONArray("CONSTANTS"));
39-
CONSTANTS_KEYBOARD = JSONUtil.toMap(json.optJSONObject("CONSTANTS_KEYBOARD"));
40-
PACKAGES = getPackages(CONSTANTS);
41-
INIT = true;
42-
} else {
43-
CONSTANTS = null;
44-
CONSTANTS_KEYBOARD = null;
45-
PACKAGES = null;
46-
INIT = false;
47-
}
25+
final Optional<InputStream> jsonStream = Optional
26+
.ofNullable(GLConstants.class.getClassLoader().getResourceAsStream("gl_constants.json"));
27+
28+
final Optional<JSONObject> json = Optional.ofNullable(JSONUtil.getJSON(jsonStream.get()));
29+
CONSTANTS = json.map(js -> getConstants(js.optJSONArray("CONSTANTS"))).orElse(null);
30+
CONSTANTS_KEYBOARD = json.map(js -> JSONUtil.toMap(js.optJSONObject("CONSTANTS_KEYBOARD"))).orElse(null);
31+
PACKAGES = json.map(js -> getPackages(CONSTANTS)).orElse(null);
32+
INIT = json.isPresent();
4833
}
4934

5035
public GLConstants(ClassVisitor classVisitor) {

0 commit comments

Comments
 (0)