generated from srnyx/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MapUtility.java
356 lines (341 loc) · 12.4 KB
/
MapUtility.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package xyz.srnyx.annoyingapi.utility;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A utility class for quickly generating {@link Map maps}
*/
@SuppressWarnings("DuplicatedCode")
public class MapUtility {
/**
* Generates a map from a list of keys and a list of values
*
* @param keys the list of keys
* @param values the list of values
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull List<T> keys, @NotNull List<G> values) {
final Map<T, G> map = new HashMap<>();
for (int i = 0; i < keys.size(); i++) map.put(keys.get(i), values.get(i));
return map;
}
/**
* Generates a map from a key and a value
*
* @param key the key
* @param value the value
*
* @return the generated map
*
* @param <T> the type of the key
* @param <G> the type of the value
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
return map;
}
/**
* Generates a map from two keys and two values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
return map;
}
/**
* Generates a map from three keys and three values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
return map;
}
/**
* Generates a map from four keys and four values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
return map;
}
/**
* Generates a map from five keys and five values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
return map;
}
/**
* Generates a map from six keys and six values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
* @param key6 the sixth key
* @param value6 the sixth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5, @NotNull T key6, @NotNull G value6) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
map.put(key6, value6);
return map;
}
/**
* Generates a map from seven keys and seven values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
* @param key6 the sixth key
* @param value6 the sixth value
* @param key7 the seventh key
* @param value7 the seventh value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5, @NotNull T key6, @NotNull G value6, @NotNull T key7, @NotNull G value7) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
map.put(key6, value6);
map.put(key7, value7);
return map;
}
/**
* Generates a map from eight keys and eight values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
* @param key6 the sixth key
* @param value6 the sixth value
* @param key7 the seventh key
* @param value7 the seventh value
* @param key8 the eighth key
* @param value8 the eighth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5, @NotNull T key6, @NotNull G value6, @NotNull T key7, @NotNull G value7, @NotNull T key8, @NotNull G value8) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
map.put(key6, value6);
map.put(key7, value7);
map.put(key8, value8);
return map;
}
/**
* Generates a map from nine keys and nine values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
* @param key6 the sixth key
* @param value6 the sixth value
* @param key7 the seventh key
* @param value7 the seventh value
* @param key8 the eighth key
* @param value8 the eighth value
* @param key9 the ninth key
* @param value9 the ninth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5, @NotNull T key6, @NotNull G value6, @NotNull T key7, @NotNull G value7, @NotNull T key8, @NotNull G value8, @NotNull T key9, @NotNull G value9) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
map.put(key6, value6);
map.put(key7, value7);
map.put(key8, value8);
map.put(key9, value9);
return map;
}
/**
* Generates a map from ten keys and ten values
*
* @param key the first key
* @param value the first value
* @param key2 the second key
* @param value2 the second value
* @param key3 the third key
* @param value3 the third value
* @param key4 the fourth key
* @param value4 the fourth value
* @param key5 the fifth key
* @param value5 the fifth value
* @param key6 the sixth key
* @param value6 the sixth value
* @param key7 the seventh key
* @param value7 the seventh value
* @param key8 the eighth key
* @param value8 the eighth value
* @param key9 the ninth key
* @param value9 the ninth value
* @param key10 the tenth key
* @param value10 the tenth value
*
* @return the generated map
*
* @param <T> the type of the keys
* @param <G> the type of the values
*/
@NotNull
public static <T, G> Map<T, G> mapOf(@NotNull T key, @NotNull G value, @NotNull T key2, @NotNull G value2, @NotNull T key3, @NotNull G value3, @NotNull T key4, @NotNull G value4, @NotNull T key5, @NotNull G value5, @NotNull T key6, @NotNull G value6, @NotNull T key7, @NotNull G value7, @NotNull T key8, @NotNull G value8, @NotNull T key9, @NotNull G value9, @NotNull T key10, @NotNull G value10) {
final Map<T, G> map = new HashMap<>();
map.put(key, value);
map.put(key2, value2);
map.put(key3, value3);
map.put(key4, value4);
map.put(key5, value5);
map.put(key6, value6);
map.put(key7, value7);
map.put(key8, value8);
map.put(key9, value9);
map.put(key10, value10);
return map;
}
/**
* Constructs a new {@link MapUtility} instance (illegal)
*
* @throws UnsupportedOperationException if this class is instantiated
*/
private MapUtility() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}