Skip to content

Commit

Permalink
Fix some component equality checking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 1, 2024
1 parent f0b15c3 commit e3734c2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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

0 comments on commit e3734c2

Please sign in to comment.