/
DataActionHelper.java
77 lines (73 loc) · 2.76 KB
/
DataActionHelper.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
package net.aufdemrand.denizencore.utilities.data;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import java.util.List;
public class DataActionHelper {
public static DataAction parse(ActionableDataProvider provider, String actionArgument) {
DataAction toReturn = new DataAction();
toReturn.provider = provider;
List<String> split = CoreUtilities.split(actionArgument, ':', 3);
toReturn.key = split.get(0);
int bracketIndex = toReturn.key.indexOf('[');
if (bracketIndex >= 0) {
String index = toReturn.key.substring(bracketIndex + 1, toReturn.key.lastIndexOf(']'));
toReturn.key = toReturn.key.substring(bracketIndex);
toReturn.index = aH.getIntegerFrom(index);
}
if (split.size() == 1) {
toReturn.type = DataActionType.AUTO_SET;
return toReturn;
}
String action = split.get(1);
if (split.size() == 2) {
if (action.equals("++")) {
toReturn.type = DataActionType.INCREMENT;
}
else if (action.equals("--")) {
toReturn.type = DataActionType.DECREMENT;
}
else if (action.equals("!")) {
toReturn.type = DataActionType.CLEAR;
}
else if (action.equals("<-")) {
toReturn.type = DataActionType.REMOVE;
}
else {
toReturn.type = DataActionType.SET;
toReturn.inputValue = new Element(action);
}
return toReturn;
}
toReturn.inputValue = new Element(split.get(2));
if (action.equals("->")) {
toReturn.type = DataActionType.INSERT;
}
else if (action.equals("<-")) {
toReturn.type = DataActionType.REMOVE;
}
else if (action.equals("|")) {
toReturn.type = DataActionType.SPLIT;
}
else if (action.equals("!|")) {
toReturn.type = DataActionType.SPLIT_NEW;
}
else if (action.equals("+")) {
toReturn.type = DataActionType.ADD;
}
else if (action.equals("-")) {
toReturn.type = DataActionType.SUBTRACT;
}
else if (action.equals("*")) {
toReturn.type = DataActionType.MULTIPLY;
}
else if (action.equals("/")) {
toReturn.type = DataActionType.DIVIDE;
}
else {
toReturn.type = DataActionType.SET;
toReturn.inputValue = new Element(split.get(1) + ":" + split.get(2));
}
return toReturn;
}
}