private boolean validateDuplicates() { boolean returnGood = true; for (CaseInsensitiveString second : duplicates.getKeySet()) { List<T> list = duplicates.getListFor(second); T good = active.get(second.toString()); /* * CONSIDER Should get CDOMObject reference out of here :( */ if (good instanceof CDOMObject) { CDOMObject cdo = (CDOMObject) good; for (int i = 0; i < list.size(); i++) { T dupe = list.get(i); if (cdo.isCDOMEqual((CDOMObject) dupe)) { for (Iterator<WeakReference<T>> it = manufactured.iterator(); it.hasNext(); ) { WeakReference<T> wr = it.next(); T mfg = wr.get(); if (mfg == null) { it.remove(); } // Yes this is instance equality, not .equals else if (mfg == good) { forgetObject(good); break; } } } } } if (duplicates.containsListFor(second)) { Logging.errorPrint( "More than one " + factory.getReferenceDescription() + " with key/name " + good.getKeyName() + " was built"); List<T> dupes = duplicates.getListFor(second); StringBuilder sb = new StringBuilder(1000); sb.append("Sources: "); sb.append(good.isInternal() ? "<internal>" : good.getSourceURI()); for (T dupe : dupes) { sb.append(", ").append(dupe.isInternal() ? "<internal>" : dupe.getSourceURI()); if (!dupe.getKeyName().equals(good.getKeyName())) { Logging.errorPrint("Key case differed for " + dupe.getKeyName()); } } Logging.errorPrint(sb.toString()); returnGood = false; } } return returnGood; }
/** * Injects all objects from the given ReferenceManufacturer into this * AbstractReferenceManufacturer. Effectively this is a bulk addObject for all of the objects * contained in the given ReferenceManufacturer. * * <p>Note that this imports only the objects, and NOT references. This * AbstractReferenceManufacturer does inherit any deferred objects (triggered through * constructIfNecessary) from the given ReferenceManufacturer. * * @param arm The ReferenceManufacturer from which the objects should be imported into this * AbstractReferenceManufacturer */ @Override public void injectConstructed(ReferenceManufacturer<T> arm) { // Must maintain order for (T value : active.insertOrderValues()) { arm.addObject(value, active.getKeyFor(value)); } for (CaseInsensitiveString cis : duplicates.getKeySet()) { for (T obj : duplicates.getListFor(cis)) { arm.addObject(obj, cis.toString()); } } for (String s : deferred) { arm.constructIfNecessary(s); } }