Skip to content

Commit

Permalink
Changes dependency on VintageValueProvider to ValueProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Nov 24, 2024
1 parent 519aeff commit 5dd6c51
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

public class CopyFactory<T, S> extends AbstractGenericFactory<T> {

private final Class<S> source;
private final Class<S> type;
private final Function<S, T> copy;

public CopyFactory(Class<S> source, Function<S, T> copy) {
this.source = source;
this.type = source;
this.copy = copy;
}

Expand All @@ -23,12 +23,11 @@ public Tuple<T> createValues(
Attributes attributes
) {
Attributes clone = attributes.cloneAndAdd(tag);
TypeTag sourceTag = copyGenericTypesInto(source, tag);
TypeTag sourceTag = copyGenericTypesInto(type, tag);

S redSource = valueProvider.giveRed(sourceTag, clone);
S blueSource = valueProvider.giveBlue(sourceTag, clone);
S redCopySource = valueProvider.giveRedCopy(sourceTag, clone);
Tuple<S> source = valueProvider.provideOrThrow(sourceTag, clone);
Tuple<T> copied = source.map(copy::apply);

return Tuple.of(copy.apply(redSource), copy.apply(blueSource), copy.apply(redCopySource));
return Tuple.of(copied.getRed(), copied.getBlue(), copied.getRedCopy());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public Tuple<T> createValues(
TypeTag keyTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class);
TypeTag valueTag = determineAndCacheActualTypeTag(1, tag, valueProvider, clone, Enum.class);

Tuple<?> key = valueProvider.provideOrThrow(keyTag, clone);
Tuple<?> value = valueProvider.provideOrThrow(valueTag, clone);

Map red = new HashMap<>();
Map blue = new HashMap<>();
Map redCopy = new HashMap<>();
red.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone));
blue.put(valueProvider.giveBlue(keyTag, clone), valueProvider.giveBlue(valueTag, clone));
redCopy.put(valueProvider.giveRed(keyTag, clone), valueProvider.giveBlue(valueTag, clone));
red.put(key.getRed(), value.getBlue());
blue.put(key.getBlue(), value.getBlue());
redCopy.put(key.getRedCopy(), value.getBlue());

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 @@ -30,12 +30,13 @@ public Tuple<T> createValues(
Attributes clone = attributes.cloneAndAdd(tag);
TypeTag entryTag = determineAndCacheActualTypeTag(0, tag, valueProvider, clone, Enum.class);

Tuple<?> tuple = valueProvider.provideOrThrow(entryTag, clone);
Collection red = new HashSet<>();
Collection blue = new HashSet<>();
Collection redCopy = new HashSet<>();
red.add(valueProvider.giveRed(entryTag, clone));
blue.add(valueProvider.giveBlue(entryTag, clone));
redCopy.add(valueProvider.giveRed(entryTag, clone));
red.add(tuple.getRed());
blue.add(tuple.getBlue());
redCopy.add(tuple.getRedCopy());

return new Tuple<>(factory.apply(red), factory.apply(blue), factory.apply(redCopy));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import nl.jqno.equalsverifier.internal.reflection.Tuple;
import nl.jqno.equalsverifier.internal.reflection.TypeTag;
import nl.jqno.equalsverifier.internal.reflection.instantiation.InstanceCreator;
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider;
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes;
import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider;
import nl.jqno.equalsverifier.internal.reflection.vintage.ClassAccessor;
Expand Down Expand Up @@ -60,19 +61,20 @@ private Tuple<T> giveEnumInstances(TypeTag tag) {
@SuppressWarnings("unchecked")
private Tuple<T> giveArrayInstances(
TypeTag tag,
VintageValueProvider valueProvider,
ValueProvider valueProvider,
Attributes attributes
) {
Class<T> type = tag.getType();
Class<?> componentType = type.getComponentType();
TypeTag componentTag = new TypeTag(componentType);

Tuple<?> component = valueProvider.provideOrThrow(componentTag, attributes);
T red = (T) Array.newInstance(componentType, 1);
Array.set(red, 0, valueProvider.giveRed(componentTag, attributes));
Array.set(red, 0, component.getRed());
T blue = (T) Array.newInstance(componentType, 1);
Array.set(blue, 0, valueProvider.giveBlue(componentTag, attributes));
Array.set(blue, 0, component.getBlue());
T redCopy = (T) Array.newInstance(componentType, 1);
Array.set(redCopy, 0, valueProvider.giveRed(componentTag, attributes));
Array.set(redCopy, 0, component.getRed());

return new Tuple<>(red, blue, redCopy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ public Tuple<T> createValues(
// values.
// But don't do it in the Blue map, or they may cancel each other out again.

Object redKey = valueProvider.giveRed(keyTag, clone);
Object blueKey = valueProvider.giveBlue(keyTag, clone);
Object blueValue = valueProvider.giveBlue(valueTag, clone);
Tuple<?> key = valueProvider.provideOrThrow(keyTag, clone);
Tuple<?> value = valueProvider.provideOrThrow(valueTag, clone);

T red = createEmpty.get();
red.put(redKey, blueValue);
red.put(key.getRed(), value.getBlue());

T blue = createEmpty.get();
if (!redKey.equals(blueKey)) { // This happens with single-element enums
blue.put(valueProvider.giveBlue(keyTag, clone), blueValue);
if (!key.getRed().equals(key.getBlue())) { // This happens with single-element enums
blue.put(key.getBlue(), value.getBlue());
}

T redCopy = createEmpty.get();
redCopy.put(redKey, blueValue);
redCopy.put(key.getRed(), value.getBlue());

return new Tuple<>(red, blue, redCopy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public Tuple<T> createValues(
for (int i = 0; i < n; i++) {
TypeTag paramTag = determineAndCacheActualTypeTag(i, tag, valueProvider, clone);

Object redValue = valueProvider.giveRed(paramTag, clone);
Object blueValue = valueProvider.giveBlue(paramTag, clone);
if (redValue.equals(blueValue)) { // This happens with single-element enums
Tuple<?> value = valueProvider.provideOrThrow(paramTag, clone);
if (value.getRed().equals(value.getBlue())) { // This happens with single-element enums
useEmpty = true;
}
redValues.add(redValue);
blueValues.add(blueValue);
redValues.add(value.getRed());
blueValues.add(value.getBlue());
}

Object red = factory.apply(redValues);
Expand Down

0 comments on commit 5dd6c51

Please sign in to comment.