Skip to content

Commit

Permalink
Some more simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jan 9, 2025
1 parent 7133199 commit e16bac8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T> extends AbstractGenericFactory<T> {

private final Function<Map, T> factory;
Expand All @@ -24,12 +23,9 @@ public Tuple<T> 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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T> extends AbstractGenericFactory<T> {

private final Function<Collection, T> factory;
Expand All @@ -27,12 +27,9 @@ public Tuple<T> createValues(TypeTag tag, VintageValueProvider valueProvider, Li
LinkedHashSet<TypeTag> 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.<T>giveRed(entryTag));
Collection blue = Set.of(valueProvider.<T>giveBlue(entryTag));
Collection redCopy = Set.of(valueProvider.<T>giveRed(entryTag));

return Tuple.of(factory.apply(red), factory.apply(blue), factory.apply(redCopy));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,15 @@ public Tuple<String> createValues(
private static final class ListTestFactory implements PrefabValueFactory<List> {

@Override
@SuppressWarnings("unchecked")
public Tuple<List> createValues(
TypeTag tag,
VintageValueProvider valueProvider,
LinkedHashSet<TypeTag> 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.<Object>giveRed(subtag));
List blue = List.of(valueProvider.<Object>giveBlue(subtag));
List redCopy = List.of(valueProvider.<Object>giveRed(subtag));

return Tuple.of(red, blue, redCopy);
}
Expand Down

0 comments on commit e16bac8

Please sign in to comment.