From e16bac8537d8bea5299768e88920aa34cb56ecc9 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Fri, 27 Dec 2024 21:49:41 +0100 Subject: [PATCH] Some more simplifications --- .../prefabvalues/factories/EnumMapFactory.java | 12 ++++-------- .../prefabvalues/factories/EnumSetFactory.java | 13 +++++-------- .../vintage/VintageValueProviderTest.java | 12 +++--------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java index c1efbaec6..210882aed 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumMapFactory.java @@ -1,6 +1,5 @@ package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.function.Function; @@ -9,7 +8,7 @@ import nl.jqno.equalsverifier.internal.reflection.Tuple; import nl.jqno.equalsverifier.internal.reflection.TypeTag; -@SuppressWarnings({ "unchecked", "rawtypes" }) +@SuppressWarnings("rawtypes") public final class EnumMapFactory extends AbstractGenericFactory { private final Function factory; @@ -24,12 +23,9 @@ public Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, Li TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone, Enum.class); - Map red = new HashMap<>(); - Map blue = new HashMap<>(); - Map redCopy = new HashMap<>(); - red.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); - blue.put(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); - redCopy.put(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + Map red = Map.of(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); + Map blue = Map.of(valueProvider.giveBlue(keyTag), valueProvider.giveBlue(valueTag)); + Map redCopy = Map.of(valueProvider.giveRed(keyTag), valueProvider.giveBlue(valueTag)); return Tuple.of(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java index f43145c0c..c7b23c7ed 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/prefabvalues/factories/EnumSetFactory.java @@ -1,8 +1,8 @@ package nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.Set; import java.util.function.Function; import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; @@ -13,7 +13,7 @@ * Implementation of {@link PrefabValueFactory} that instantiates EnumSets using reflection, while taking generics into * account. */ -@SuppressWarnings({ "unchecked", "rawtypes" }) +@SuppressWarnings("rawtypes") public class EnumSetFactory extends AbstractGenericFactory { private final Function factory; @@ -27,12 +27,9 @@ public Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, Li LinkedHashSet clone = cloneWith(typeStack, tag); TypeTag entryTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class); - Collection red = new HashSet<>(); - Collection blue = new HashSet<>(); - Collection redCopy = new HashSet<>(); - red.add(valueProvider.giveRed(entryTag)); - blue.add(valueProvider.giveBlue(entryTag)); - redCopy.add(valueProvider.giveRed(entryTag)); + Collection red = Set.of(valueProvider.giveRed(entryTag)); + Collection blue = Set.of(valueProvider.giveBlue(entryTag)); + Collection redCopy = Set.of(valueProvider.giveRed(entryTag)); return Tuple.of(factory.apply(red), factory.apply(blue), factory.apply(redCopy)); } diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java index 15a8a49cd..ea5b9fae7 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/VintageValueProviderTest.java @@ -212,21 +212,15 @@ public Tuple createValues( private static final class ListTestFactory implements PrefabValueFactory { @Override - @SuppressWarnings("unchecked") public Tuple createValues( TypeTag tag, VintageValueProvider valueProvider, LinkedHashSet typeStack) { TypeTag subtag = tag.getGenericTypes().get(0); - List red = new ArrayList<>(); - red.add(valueProvider.giveRed(subtag)); - - List blue = new ArrayList<>(); - blue.add(valueProvider.giveBlue(subtag)); - - List redCopy = new ArrayList<>(); - redCopy.add(valueProvider.giveRed(subtag)); + List red = List.of(valueProvider.giveRed(subtag)); + List blue = List.of(valueProvider.giveBlue(subtag)); + List redCopy = List.of(valueProvider.giveRed(subtag)); return Tuple.of(red, blue, redCopy); }