package au.id.zancanaro.javacheck.object; import java.util.*; public class SubObject { public final Map> obj; public final EnumValues value; public SubObject(Map> obj, EnumValues value) { this.obj = obj; this.value = value; } public SubObject add(SubObject other) { Map> values = new HashMap<>(obj); for (Map.Entry> entry : other.obj.entrySet()) { String key = entry.getKey(); if (values.containsKey(key)) { List result = new ArrayList<>(values.get(key)); result.addAll(entry.getValue()); values.put(key, Collections.unmodifiableList(result)); } else { values.put(key, entry.getValue()); } } return new SubObject<>(Collections.unmodifiableMap(values), this.value); } @Override public String toString() { return "{" + obj.toString() + ", " + this.value + "}"; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SubObject subObject = (SubObject) o; return obj.equals(subObject.obj) && value.equals(subObject.value); } @Override public int hashCode() { return obj.hashCode() + 37 * value.hashCode(); } public static enum EnumValues { A, B, C } }