-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingMachineConfig.pde
More file actions
203 lines (164 loc) · 4.38 KB
/
SortingMachineConfig.pde
File metadata and controls
203 lines (164 loc) · 4.38 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
class SortingMachineConfig {
private String renderer;
private int noteHeight;
private float stepWidth;
private WindowConfig window;
private SortJobConfig[] sortJobConfigs;
private Map<String, DataConfig> dataById;
public SortingMachineConfig(Map<String, Object> in) {
this.renderer = in.get("renderer").toString();
this.window = new WindowConfig((Map<String, Object>)in.get("window"));
List<Object> list = (List<Object>)in.get("jobs");
sortJobConfigs = new SortJobConfig[list.size()];
for(int i = 0; i < list.size(); i++) {
Map<String, Object> m = (Map<String, Object>)list.get(i);
sortJobConfigs[i] = new SortJobConfig(m);
}
dataById = new HashMap<String, DataConfig>();
Map<String, Object> datamap = (Map<String, Object>)in.get("data");
for(String id : datamap.keySet()) {
dataById.put(id, new DataConfig((Map<String, Object>)datamap.get(id)));
}
noteHeight = (Integer)in.get("noteheight");
stepWidth = ((Double)in.get("stepwidth")).floatValue();
}
public String getRenderer() {
return this.renderer;
}
public int getNoteHeight() {
return this.noteHeight;
}
public float getStepWidth() {
return this.stepWidth;
}
public WindowConfig getWindow() {
return this.window;
}
public SortJobConfig[] getSortJobConfigs() {
return this.sortJobConfigs;
}
public DataConfig getDataConfig(String id) {
return dataById.get(id);
}
public String toString() {
return Objects.toStringHelper(this)
.add("renderer", renderer)
.add("noteHeight", noteHeight)
.add("stepWidth", stepWidth)
.add("window", window)
.add("jobs", sortJobConfigs)
.add("dataById", dataById)
.toString();
}
}
class SortJobConfig {
private String label;
private String sort;
private String dataRef;
SortJobConfig(Map<String, Object> in) {
this.label = (String)in.get("label");
this.sort = (String)in.get("sort");
this.dataRef = (String)in.get("data");
}
public String getLabel() {
return this.label;
}
public String getSort() {
return sort;
}
public String getDataRef() {
return dataRef;
}
}
class DataConfig {
private String label;
private int[] values;
private RandomDataConfig randomData;
private String[] steps;
DataConfig(Map<String, Object> in) {
this.label = (String)in.get("label");
if(in.containsKey("values")) {
this.values = asIntArray(in, "values");
}
else if(in.containsKey("random")) {
randomData = new RandomDataConfig((Map<String, Object>)in.get("random"));
}
else {
throw new RuntimeException("no data specified in data set");
}
if(in.containsKey("steps")) {
this.steps = asStringArray(in, "steps");
}
else {
this.steps = new String[0];
}
}
public String getLabel() {
return this.label;
}
public boolean valuesInlined() {
return this.values != null;
}
public int[] getValues() {
return this.values;
}
public RandomDataConfig getRandomDataConfig() {
return this.randomData;
}
public String[] getSteps() {
return this.steps;
}
}
class RandomDataConfig {
private int size;
private int[] uniqueValues;
RandomDataConfig(Map<String, Object> in) {
this.size = (Integer)in.get("size");
this.uniqueValues = asIntArray(in, "values");
}
public int getSize() {
return this.size;
}
public int[] getUniqueValues() {
return copy(this.uniqueValues);
}
}
class WindowConfig {
private int width;
private int height;
private float leftMargin;
private float rightMargin;
private float topMargin;
private float bottomMargin;
public WindowConfig(Map<String, Object> in) {
this.width = (Integer)in.get("width");
this.height = (Integer)in.get("height");
int[] margins = asIntArray(in, "margins");
setMargins(asIntArray(in, "margins"));
}
public int getWidth() { return this.width; }
public void setWidth(int width) { this.width = width; }
public int getHeight() { return this.height; }
public void setHeight(int height) { this.height = height; }
public float getLeftMargin() {
return this.leftMargin;
}
public float getRightMargin() {
return this.rightMargin;
}
public float getTopMargin() {
return this.topMargin;
}
public float getBottomMargin() {
return this.bottomMargin;
}
public void setMargins(int[] margins) {
if(margins.length != 4) {
throw new RuntimeException("margin should be size = 4");
}
this.topMargin = (float)margins[0];
this.rightMargin = (float)margins[1];
this.bottomMargin = (float)margins[2];
this.leftMargin = (float)margins[3];
}
}