movedBugComparator.setClassNameRewriter(new MovedClassMap(origCollection,newCollection));
movedBugComparator.setClassNameRewriter(new MovedClassMap(origCollection,newCollection).execute());
	public static BugCollection mergeCollections(BugCollection origCollection,			BugCollection newCollection) {				mapFromNewToOldBug.clear();		matchedOldBugs.clear();		BugCollection resultCollection = newCollection				.createEmptyCollectionWithMetadata();		// Previous sequence number		long lastSequence = origCollection.getSequenceNumber();		// The AppVersion history is retained from the orig collection,		// adding an entry for the sequence/timestamp of the current state		// of the orig collection.		resultCollection.clearAppVersions();		for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i				.hasNext();) {			AppVersion appVersion = i.next();			resultCollection.addAppVersion((AppVersion) appVersion.clone());		}		AppVersion origCollectionVersion = new AppVersion(lastSequence);		origCollectionVersion.setTimestamp(origCollection				.getCurrentAppVersion().getTimestamp());		origCollectionVersion.setReleaseName(origCollection				.getCurrentAppVersion().getReleaseName());		origCollectionVersion.setNumClasses(origCollection.getProjectStats().getNumClasses());		origCollectionVersion.setCodeSize(origCollection.getProjectStats().getCodeSize());				resultCollection.addAppVersion(origCollectionVersion);		// We assign a sequence number to the new collection as one greater than		// the		// original collection.		long currentSequence = origCollection.getSequenceNumber() + 1;		resultCollection.setSequenceNumber(currentSequence);		matchBugs(SortedBugCollection.BugInstanceComparator.instance,				origCollection, newCollection);		matchBugs(versionInsensitiveBugComparator, origCollection,				newCollection);		VersionInsensitiveBugComparator movedBugComparator = new VersionInsensitiveBugComparator();		movedBugComparator.setClassNameRewriter(new MovedClassMap(origCollection,newCollection));		matchBugs(movedBugComparator, origCollection,				newCollection);		// matchBugs(new SloppyBugComparator(), origCollection, newCollection);		int oldBugs = 0;		int newlyDeadBugs = 0;		int persistantBugs = 0;		int addedBugs = 0;		int addedInNewCode = 0;		int deadBugInDeadCode = 0;		// Copy unmatched bugs		for (BugInstance bug : origCollection.getCollection())			if (!matchedOldBugs.contains(bug)) {				if (bug.getLastVersion() == -1)					newlyDeadBugs++;				else					oldBugs++;				BugInstance newBug = (BugInstance) bug.clone();				if (newBug.getLastVersion() == -1) {					newBug.setLastVersion(lastSequence);					ClassAnnotation classBugFoundIn = bug.getPrimaryClass();					String className = classBugFoundIn.getClassName();					if (newCollection.getProjectStats()							.getClassStats(className) != null)						newBug.setRemovedByChangeOfPersistingClass(true);					else						deadBugInDeadCode++;				}				if (newBug.getFirstVersion() > newBug.getLastVersion())					throw new IllegalStateException("Illegal Version range: "							+ newBug.getFirstVersion() + ".."							+ newBug.getLastVersion());				resultCollection.add(newBug, false);			}		// Copy matched bugs		for (BugInstance bug : newCollection.getCollection()) {			BugInstance newBug = (BugInstance) bug.clone();			if (mapFromNewToOldBug.containsKey(bug)) {				BugInstance origWarning = mapFromNewToOldBug.get(bug);				assert origWarning.getLastVersion() == -1;				newBug.setUniqueId(origWarning.getUniqueId());				copyBugHistory(origWarning, newBug);				String annotation = newBug.getAnnotationText();				if (annotation.length() == 0)					newBug.setAnnotationText(origWarning.getAnnotationText());				persistantBugs++;			} else {				newBug.setFirstVersion(lastSequence + 1);				addedBugs++;				ClassAnnotation classBugFoundIn = bug.getPrimaryClass();				String className = classBugFoundIn.getClassName();				if (origCollection.getProjectStats().getClassStats(className) != null) {					newBug.setIntroducedByChangeOfExistingClass(true);					// System.out.println("added bug to existing code " +					// newBug.getUniqueId() + " : " + newBug.getAbbrev() + " in					// " + classBugFoundIn);				} else					addedInNewCode++;			}			assert newBug.getLastVersion() == -1;			if (newBug.getLastVersion() != -1)				throw new IllegalStateException("Illegal Version range: "						+ newBug.getFirstVersion() + ".."						+ newBug.getLastVersion());			int oldSize = resultCollection.getCollection().size();			resultCollection.add(newBug, false);			int newSize = resultCollection.getCollection().size();			if (newSize != oldSize + 1) {				System.out.println("Failed to add bug #" + newBug.getUniqueId()						+ " : " + newBug.getMessage());			}		}		if (false && verbose) {			System.out.println(origCollection.getCollection().size()					+ " orig bugs, " + newCollection.getCollection().size()					+ " new bugs");			System.out.println("Bugs: " + oldBugs + " old, "					+ deadBugInDeadCode + " in removed code, "					+ (newlyDeadBugs - deadBugInDeadCode) + " died, "					+ persistantBugs + " persist, " + addedInNewCode					+ " in new code, " + (addedBugs - addedInNewCode)					+ " added");		}		return resultCollection;	}