Use modernized java.util APIs
Recipe ID
org.openrewrite.java.migrate.util.JavaUtilAPIsArtifact
org.openrewrite.recipe:rewrite-migrate-javaCertain java util APIs have been introduced and are favored over previous APIs.
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.migrate.util.JavaUtilAPIsIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-java:3.41.0Definition
This recipe runs the following recipes in order.
- Replace
iterator().next()withgetFirst()org.openrewrite.java.migrate.util.IteratorNext - Replace
List.get(int),add(int, Object), andremove(int)withSequencedCollection*Firstand*Lastmethodsorg.openrewrite.java.migrate.util.ListFirstAndLast - Prefer
List.of()org.openrewrite.java.migrate.util.MigrateCollectionsEmptyList - Prefer
Map.of()org.openrewrite.java.migrate.util.MigrateCollectionsEmptyMap - Prefer
Set.of()org.openrewrite.java.migrate.util.MigrateCollectionsEmptySet - Prefer
List.of(..)org.openrewrite.java.migrate.util.MigrateCollectionsSingletonList - Prefer
Map.of(..)org.openrewrite.java.migrate.util.MigrateCollectionsSingletonMap - Prefer
Set.of(..)org.openrewrite.java.migrate.util.MigrateCollectionsSingletonSet - Prefer
List.of(..)org.openrewrite.java.migrate.util.MigrateCollectionsUnmodifiableList - Prefer
Set.of(..)org.openrewrite.java.migrate.util.MigrateCollectionsUnmodifiableSet - Use
Reader.of(CharSequence)for non-synchronized readersorg.openrewrite.java.migrate.util.MigrateStringReaderToReaderOf - Prefer
Optional.isPresent()org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent - Prefer
Optional.isEmpty()org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty Stream<Optional>idiom recipeorg.openrewrite.java.migrate.util.OptionalStreamRecipe- Remove invocations of deprecated invocations from Deflater, Inflater, ZipFile
org.openrewrite.java.migrate.util.RemoveFinalizerFromZip - Replace
java.lang.Math random()withThreadLocalRandom nextDouble()org.openrewrite.java.migrate.util.ReplaceMathRandomWithThreadLocalRandomRecipe - Replace
Stream.collect(Collectors.toUnmodifiableList())withStream.toList()org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList - Use
getFirst()instead ofstream().findFirst().orElseThrow()org.openrewrite.java.migrate.util.StreamFindFirst - Prefer
EnumSet of(..)org.openrewrite.java.migrate.util.UseEnumSetOf - Prefer
List.of(..)org.openrewrite.java.migrate.util.UseListOf - Prefer
Locale.of(..)overnew Locale(..)org.openrewrite.java.migrate.util.UseLocaleOf - Prefer
Map.of(..)org.openrewrite.java.migrate.util.UseMapOf - Prefer
Predicate.not(..)over casting toPredicateand callingnegate()org.openrewrite.java.migrate.util.UsePredicateNot - Prefer
Set.of(..)org.openrewrite.java.migrate.util.UseSetOf
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats