Skip to content

Commit

Permalink
SubjectCreator is more appropriate than ValueProvider here
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Feb 15, 2025
1 parent 9842362 commit 1034aac
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
import java.util.Map;
import java.util.Objects;

import nl.jqno.equalsverifier.internal.instantiation.ValueProvider;
import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
import nl.jqno.equalsverifier.internal.util.Configuration;
import nl.jqno.equalsverifier.internal.util.Context;
import nl.jqno.equalsverifier.internal.util.Formatter;

public class MapEntryHashCodeRequirementChecker<T> implements Checker {

private final Configuration<T> config;
private final ValueProvider valueProvider;
private final SubjectCreator<T> subjectCreator;

public MapEntryHashCodeRequirementChecker(Context<T> context) {
this.config = context.getConfiguration();
this.valueProvider = context.getValueProvider();
this.subjectCreator = context.getSubjectCreator();
}

@Override
public void check() {
if (Map.Entry.class.isAssignableFrom(config.getType())) {
Map.Entry<?, ?> e = valueProvider.<Map.Entry<?, ?>>provideOrThrow(config.getTypeTag(), null).getRed();
Map.Entry<?, ?> e = (Map.Entry<?, ?>) subjectCreator.plain();

int expectedHashCode = Objects.hashCode(e.getKey()) ^ Objects.hashCode(e.getValue());
int actualHashCode = config.getCachedHashCodeInitializer().getInitializedHashCode(e);
Expand Down

0 comments on commit 1034aac

Please sign in to comment.