-
Notifications
You must be signed in to change notification settings - Fork 497
/
JavaTools.java
executable file
·89 lines (69 loc) · 2.43 KB
/
JavaTools.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
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
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class JavaTools {
public static <T> T[] concat(T[] first, T[] second) {
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
public static int[] concat(int[] first, int[] second) {
int[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
public static float[] concat(float[] first, float[] second) {
float[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
public <T> T[] concatenate (T[] A, T[] B) {
int aLen = A.length;
int bLen = B.length;
@SuppressWarnings("unchecked")
T[] C = (T[]) Array.newInstance(A.getClass().getComponentType(), aLen+bLen);
System.arraycopy(A, 0, C, 0, aLen);
System.arraycopy(B, 0, C, aLen, bLen);
return C;
}
public static List<Field> getAllFields(Class clas) {
List<Field> result = new ArrayList<Field>();
Class current = clas;
while (current != null && current != Object.class) {
for (Field f : current.getDeclaredFields()) {
result.add(f);
}
current = current.getSuperclass();
}
return result;
}
public static List<Method> getAllMethods(Class clas) {
List<Method> result = new ArrayList<Method>();
Class current = clas;
while (current != null && current != Object.class) {
for (Method m : current.getDeclaredMethods()) {
result.add(m);
}
current = current.getSuperclass();
}
return result;
}
public static String surroundWithQuotes(String stringToSurroundWithQuotes){
return String.format("\"%s\"", stringToSurroundWithQuotes);
}
public static String stripSurroundingQuotes(String stringToStripQuotes) {
return stringToStripQuotes.replaceAll("^\"|\"$", "");
}
}