}
}
void append(ReplacementMap next) {
for (Map.Entry<Component,HashSet<Component>> e : next.map.entrySet()) {
Component b = e.getKey();
HashSet<Component> cs = e.getValue(); // what b is replaced by
HashSet<Component> as = this.inverse.remove(b); // what was replaced to get b
if (as == null) { // b pre-existed replacements so
as = new HashSet<Component>(3); // we say it replaces itself.
as.add(b);
}
for (Component a : as) {
HashSet<Component> aDst = this.map.get(a);
if (aDst == null) { // should happen when b pre-existed only
aDst = new HashSet<Component>(cs.size());
this.map.put(a, aDst);
}
aDst.remove(b);
aDst.addAll(cs);
}
for (Component c : cs) {
HashSet<Component> cSrc = this.inverse.get(c); // should always be null
if (cSrc == null) {
cSrc = new HashSet<Component>(as.size());
this.inverse.put(c, cSrc);
}
cSrc.addAll(as);
}
}
for (Map.Entry<Component,HashSet<Component>> e : next.inverse.entrySet()) {
Component c = e.getKey();
if (!inverse.containsKey(c)) {
HashSet<Component> bs = e.getValue();
if (!bs.isEmpty()) {
System.err.println("internal error: component replaced but not represented"); //OK
}