-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectionPerformance.hint
472 lines (408 loc) · 21.5 KB
/
CollectionPerformance.hint
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<?
import org.netbeans.modules.java.hints.declarative.APIAccessor;
import com.sun.source.tree.*;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.tree.*;
?>
<!description="Refactor to modern Collection APIs and idioms.">
// replace old collections
java.util.Stack =>
java.util.ArrayDeque;;
java.util.Vector =>
java.util.ArrayList;;
/*
java.util.LinkedList =>
java.util.ArrayList;;
*/
java.util.Hashtable =>
java.util.HashMap;;
$modifiers$ java.util.Stack<$g> $name = new java.util.Stack<$g$>(); =>
$modifiers$ java.util.Deque<$g> $name = new java.util.ArrayDeque<$g$>();
;;
/*
$modifiers$ java.util.Stack<$g> $name = $initializer; =>
$modifiers$ java.util.Deque<$g> $name = $initializer;
;;
$modifiers$ java.util.Stack<$g> $name; =>
$modifiers$ java.util.Deque<$g> $name;
;;
new java.util.Stack<$g$>() =>
new java.util.Deque<$g$>()
;;
*/
// maps to Collection interface post refactoring
$stack.empty() :: $stack instanceof java.util.Stack =>
$stack.isEmpty()
;;
// avoid raw type warnings
java.util.Collections.EMPTY_LIST =>
java.util.Collections.emptyList();;
java.util.Collections.EMPTY_SET =>
java.util.Collections.emptySet();;
java.util.Collections.EMPTY_MAP =>
java.util.Collections.emptyMap();;
// more descriptive
java.util.Arrays.asList() =>
java.util.Collections.emptyList();;
// prefer immutable collection for small arrays
// not recommended for large arrays in inner loops due to the null check
// todo: add check for $a not being an array + remove $b
java.util.Arrays.asList($a, $b, $more$) :: !parentMatches("java.util.Collections.unmodifiableList($_)") && sourceVersionGE(9) =>
java.util.List.of($a, $b, $more$);;
// shorter 9+
java.util.Collections.singletonList($a) :: sourceVersionGE(9) =>
java.util.List.of($a);;
java.util.Collections.singleton($a) :: sourceVersionGE(9) =>
java.util.Set.of($a);;
java.util.Collections.singletonMap($k, $v) :: sourceVersionGE(9) =>
java.util.Map.of($k, $v);;
// 9+
java.util.Collections.unmodifiableList(java.util.Arrays.asList($a$)) :: sourceVersionGE(9) =>
java.util.List.of($a$);;
java.util.Collections.unmodifiableList(java.util.List.of($a$)) :: sourceVersionGE(9) =>
java.util.List.of($a$);;
java.util.Collections.unmodifiableSet(java.util.Set.of($a$)) :: sourceVersionGE(9) =>
java.util.Set.of($a$);;
java.util.Collections.unmodifiableSet(new $Set<$T$>(java.util.Arrays.asList($a$))) :: $Set instanceof java.util.Set && sourceVersionGE(9) =>
java.util.Set.of($a$);;
java.util.Collections.unmodifiableSet(new $Set<$T$>(java.util.List.of($a$))) :: $Set instanceof java.util.Set && sourceVersionGE(9) =>
java.util.Set.of($a$);;
// todo: needs read only check
"could be potentially replaced with Set.of(..) - if immutable.":
new $Set<$T$>(java.util.Arrays.asList($a, $b, $more$)) :: $Set instanceof java.util.Set && !parentMatches("java.util.Collections.unmodifiableSet($_)") && sourceVersionGE(9) =>
java.util.Set.of($a, $b, $more$)
;;
"could be potentially replaced with Set.of(..) - if immutable.":
new $Set<$T$>(java.util.List.of($a, $b, $more$)) :: $Set instanceof java.util.Set && !parentMatches("java.util.Collections.unmodifiableSet($_)") && sourceVersionGE(9) =>
java.util.Set.of($a, $b, $more$)
;;
// unmodifiable view -> immutable copy; 10+
/*
"unmodifiable view can be potentially replaced with immutable copy.":
java.util.Collections.unmodifiableList($list) :: $list instanceof java.util.List && sourceVersionGE(10) =>
java.util.List.copyOf($list);;
"unmodifiable view can be potentially replaced with immutable copy.":
java.util.Collections.unmodifiableCollection($col) :: $col instanceof java.util.Collection && sourceVersionGE(10) =>
java.util.List.copyOf($col);;
"unmodifiable view can be potentially replaced with immutable copy.":
java.util.Collections.unmodifiableSet($set) :: $set instanceof java.util.Set && sourceVersionGE(10) =>
java.util.Set.copyOf($set);;
"unmodifiable view can be potentially replaced with immutable copy.":
java.util.Collections.unmodifiableMap($map) :: $map instanceof java.util.Map && sourceVersionGE(10) =>
java.util.Map.copyOf($map);;
*/
// prefer list.sort()
// less readable
//java.util.Collections.sort($list) :: $list instanceof java.util.List =>
//$list.sort(null);;
java.util.Collections.sort($list, $comp) :: $list instanceof java.util.List =>
$list.sort($comp);;
// collections have faster bulk add opperations than the sequential loop of Collections.addAll()
java.util.Collections.addAll($col, $array$) :: $col instanceof java.util.Collection =>
$col.addAll(java.util.Arrays.asList($array$));;
// prefer copy constructor over addAll()
$more$ $col = new $Col();
$col.addAll($other); :: $Col instanceof java.util.Collection =>
$more$ $col = new $Col($other);
;;
$more$ $map = new $Map();
$map.putAll($other); :: $Map instanceof java.util.Map =>
$more$ $map = new $Map($other);
;;
// avoid inefficient map traversal
for ($K $k : $map.keySet()) {
$preamble$;
$V $v = $map.get($k);
$body$;
} :: $map instanceof java.util.Map && !referencedIn($k, $preamble$)
=>
for ($V $v : $map.values()) {
$preamble$;
$body$;
}
:: !referencedIn($k, $body$)
=>
for (java.util.Map.Entry<$K, $V> entry : $map.entrySet()) {
$preamble$;
$K $k = entry.getKey();
$V $v = entry.getValue();
$body$;
}
:: otherwise
;;
// contains + get in succession
"could be potentially replaced with a single get(key) if the map does not contain null values":
if ($map.containsKey($key)) {
$preamble$;
$V $v = $map.get($key);
$body$;
} :: $map instanceof java.util.Map && !referencedIn($key, $preamble$)
=>
$V $v = $map.get($key);
if ($v != null) {
$preamble$;
$body$;
}
;;
// todo: figure out how to get val type
"could be potentially replaced with a single get(key) if the map does not contain null values":
if ($map.containsKey($key)) {
return $map.get($key);
} :: $map instanceof java.util.Map
=>
Object val = $map.get($key);
if (val != null) {
return val;
}
;;
// contains + remove in succession
if ($col.contains($v)) {
$col.remove($v);
} :: $col instanceof java.util.Collection
=>
$col.remove($v);
;;
if ($map.containsKey($k)) {
$map.remove($k);
$rest$;
} :: $map instanceof java.util.Map
=>
$map.remove($k);
:: isEmpty($rest$)
=>
"could be potentially replaced with a single remove(key) if the map does not contain null values":
if ($map.remove($k) == null) {
$rest$;
}
:: otherwise
;;
// contains + put
"could be potentially replaced with putIfAbsent(key, value) if the map does not contain null values":
if (!$map.containsKey($k)) {
$map.put($k, $v);
} :: $map instanceof java.util.Map
=>
$map.putIfAbsent($k, $v);
;;
// add to sub-collection
"could be replaced with putIfAbsent(key, new SubCollection()).add(toAdd)":
$Col $subcol = $map.get($key);
if ($subcol == null) {
$subcol = $subColInit;
$map.put($key, $subcol);
}
$subcol.add($item);
:: $map instanceof java.util.Map && $subcol instanceof java.util.Collection
=>
$map.putIfAbsent($key, $subColInit).add($item);
;;
// get instead contains (dangerous! values can be null)
/*
$map.get($k) == null :: $map instanceof java.util.Map =>
!$map.containsKey($k)
;;
$map.get($k) != null :: $map instanceof java.util.Map =>
$map.containsKey($k)
;;
*/
// concise map population
for ($O $o : $col) {
$map.put($key, $value);
} :: $col instanceof java.util.Collection && $map instanceof java.util.Map
=>
$col.forEach($o -> $map.put($key, $value));
;;
// removeIf() 8+
java.util.Iterator<$T> $it = $col.iterator();
while ($it.hasNext()) {
$T $t = $it.next();
if ($condition) {
$it.remove();
}
} :: $col instanceof java.util.Collection
=>
$col.removeIf($t -> $condition);
;;
// this one gonna be tricky
/*
java.util.Iterator<$T> $it = $col.iterator();
while ($it.hasNext()) {
if ($it.next().$foo() {
$it.remove();
}
} :: $col instanceof java.util.Collection
=>
$col.removeIf($T::$foo)
;;
*/
for (java.util.Iterator<$T> $it = $col.iterator(); $it.hasNext(); ) {
$T $t = $it.next();
if ($condition) {
$it.remove();
}
} :: $col instanceof java.util.Collection
=>
$col.removeIf($t -> $condition);
;;
// URLs as keys can caue performance problems
// set + URL
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
new $SET<java.net.URL>($args$) :: $SET instanceof java.util.Set =>
new $SET<java.net.URI>($args$)
;;
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
$SET<java.net.URL> $set = $init$; :: $set instanceof java.util.Set =>
$SET<java.net.URI> $set = $init$;
;;
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
$set.add($key) :: $set instanceof java.util.Set<java.net.URL> && $key instanceof java.net.URL =>
$set.add($key.toURI())
;;
// map + URL
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
new $MAP<java.net.URL, $V>($args$) :: $MAP instanceof java.util.Map =>
new $MAP<java.net.URI, $V>($args$)
;;
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
$MAP<java.net.URL, $V> $map = $init$; :: $MAP instanceof java.util.Map =>
$MAP<java.net.URI, $V> $map = $init$;
;;
"URLs used as keys in collections can cause performance problems, since equals() and hashCode() trigger blocking domain lookup operations. Try using java.net.URI instead.":
$map.put($key, $value) :: $map instanceof java.util.Map<java.net.URL, ?> && $key instanceof java.net.URL =>
$map.put($key.toURI(), $value)
;;
// <19
"suboptimal capacity computation":
new $Col<$T$>($cap) :: sourceVersionLE(18) && $cap instanceof int
&& matchesAny($Col, "java.util.HashMap", "java.util.LinkedHashMap", "java.util.HashSet", "java.util.LinkedHashSet", "java.util.WeakHashMap")
&& !matchesAny($cap, "(int) Math.ceil($n / 0.75)")
&& !isIntLiteral($cap)
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) Math.ceil($n / 0.75f)")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) ($n / $fac) + $one") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "($n * 4) / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(4 * $n) / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "$n * 4 / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "4 * $n / 3")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> new $Col<$T$>((int) Math.ceil($n / 0.75)) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> new $Col<$T$>((int) Math.ceil($cap / 0.75)) :: otherwise
;;
// 19+ Map/Set factory methods
"convert to factory method for creating pre-sized Maps using initial number of entries instead of table capacity.":
new java.util.HashMap<$T$>($cap) :: $cap instanceof int && sourceVersionGE(19)
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) Math.ceil($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac) + $one") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "4 * $n / 3")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> java.util.HashMap.newHashMap($n) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> java.util.HashMap.newHashMap($cap) :: otherwise
;;
"convert to factory method for creating pre-sized Maps using initial number of entries instead of table capacity.":
new java.util.LinkedHashMap<$T$>($cap) :: $cap instanceof int && sourceVersionGE(19)
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) Math.ceil($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "4 * $n / 3")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> java.util.LinkedHashMap.newLinkedHashMap($n) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> java.util.LinkedHashMap.newLinkedHashMap($cap) :: otherwise
;;
"convert to factory method for creating pre-sized Maps using initial number of entries instead of table capacity.":
new java.util.WeakHashMap<$T$>($cap) :: $cap instanceof int && sourceVersionGE(19)
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) Math.ceil($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "($n * 4) / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(4 * $n) / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "$n * 4 / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "4 * $n / 3")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> java.util.WeakHashMap.newWeakHashMap($n) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> java.util.WeakHashMap.newWeakHashMap($cap) :: otherwise
;;
"convert to factory method for creating pre-sized Sets using initial number of entries instead of table capacity.":
new java.util.HashSet<$T$>($cap) :: $cap instanceof int && sourceVersionGE(19)
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) Math.ceil($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "($n * 4) / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(4 * $n) / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "$n * 4 / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "4 * $n / 3")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> java.util.HashSet.newHashSet($n) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> java.util.HashSet.newHashSet($cap) :: otherwise
;;
"convert to factory method for creating pre-sized Sets using initial number of entries instead of table capacity.":
new java.util.LinkedHashSet<$T$>($cap) :: $cap instanceof int && sourceVersionGE(19)
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) Math.ceil($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac)") && matchesAny($fac, "0.75", "0.75f")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) ($n / $fac + $one)") && matchesAny($fac, "0.75", "0.75f") && matchesAny($one, "1", "1.0", "1.0f")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "($n * 4 + 2) / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(4 * $n + 2) / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "($n * 4) / 3 + 1")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "($n * 4) / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(4 * $n) / 3 + 1")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(4 * $n) / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "$n * 4 / 3 + 1")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "$n * 4 / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "4 * $n / 3 + 1")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "4 * $n / 3")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) (($n * 4L + 2L) / 3L)")
=> java.util.LinkedHashSet.newLinkedHashSet($n) :: matchesWithBind($cap, "(int) ((4L * $n + 2L) / 3L)")
=> java.util.LinkedHashSet.newLinkedHashSet($cap) :: otherwise
;;
<?
public boolean isEmpty(Variable var) throws Throwable {
return !context.getIndexedVariables(var).iterator().hasNext();
}
public boolean isIntLiteral(Variable var) throws Throwable {
TreePath tp = APIAccessor.IMPL.getSingleVariable(context, var);
return tp != null && tp.getLeaf().getKind() == Kind.INT_LITERAL;
}
?>