package au.id.zancanaro.javacheck.object; import java.util.*; public class SubObject { public final Map> obj; public SubObject(Map> obj) { this.obj = obj; } 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)); } @Override public String toString() { return obj.toString(); } @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); } @Override public int hashCode() { return obj.hashCode(); } }