Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some component equality checking issues #906

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

Expand Down Expand Up @@ -88,4 +89,22 @@ public List<ComponentValue<?>> getRequiredComponents() {
public void setRequiredComponents(List<ComponentValue<?>> requiredComponents) {
this.requiredComponents = requiredComponents;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ComponentPredicate)) return false;
ComponentPredicate that = (ComponentPredicate) obj;
return this.requiredComponents.equals(that.requiredComponents);
}

@Override
public int hashCode() {
return Objects.hashCode(this.requiredComponents);
}

@Override
public String toString() {
return "ComponentPredicate{requiredComponents=" + this.requiredComponents + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public Map<ComponentType<?>, Optional<?>> getPatches() {
return this.patches;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof PatchableComponentMap)) return false;
PatchableComponentMap that = (PatchableComponentMap) obj;
if (!this.base.equals(that.base)) return false;
return this.patches.equals(that.patches);
}

@Override
public int hashCode() {
return Objects.hash(this.base, this.patches);
}

@Override
public String toString() {
return "PatchableComponentMap{base=" + this.base + ", patches=" + this.patches + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public class StaticComponentMap implements IComponentMap {
Expand Down Expand Up @@ -82,6 +83,24 @@ public boolean isEmpty() {
return this.empty;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof StaticComponentMap)) return false;
StaticComponentMap that = (StaticComponentMap) obj;
return this.delegate.equals(that.delegate);
}

@Override
public int hashCode() {
return Objects.hashCode(this.delegate);
}

@Override
public String toString() {
return "StaticComponentMap{empty=" + this.empty + ", delegate=" + this.delegate + '}';
}

public static class Builder {

private final Map<ComponentType<?>, Object> map = new HashMap<>();
Expand Down