Use modernized java.util APIs
MSALCertain java util APIs have been introduced and are favored over previous APIs.
org. openrewrite. java. migrate. util. JavaUtilAPIsmod run . --recipe= org. openrewrite. java. migrate. util. JavaUtilAPIsInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Replace
iterator().next()withgetFirst() - Replace
List.get(int),add(int, Object), andremove(int)withSequencedCollection*Firstand*Lastmethods - Prefer
List.of() - Prefer
Map.of() - Prefer
Set.of() - Prefer
List.of(..) - Prefer
Map.of(..) - Prefer
Set.of(..) - Prefer
List.of(..) - Prefer
Set.of(..) - Use
Reader.of(CharSequence)for non-synchronized readers - Prefer
Optional.isPresent() - Prefer
Optional.isEmpty() - Replace
filter(Optional::isPresent).map(Optional::get)withflatMap(Optional::stream) - Remove
finalize()invocations onDeflater,InflaterandZipFile - Replace
Math.random()withThreadLocalRandom.current().nextDouble() - Replace
Stream.collect(Collectors.toUnmodifiableList())withStream.toList() - Use
getFirst()instead ofstream().findFirst().orElseThrow() - Prefer
EnumSet.of(..) - Prefer
List.of(..) - Prefer
Locale.of(..)overnew Locale(..) - Prefer
Map.of(..) - Prefer
Predicate.not(..)over casting toPredicateand callingnegate() - Prefer
Set.of(..)