int argCount = commandLine.parse(args, 2, 3, "Usage: " + Update.class.getName() + " [options] <historyData> <newData> [<mergedData>] ");
int argCount = commandLine.parse(args, 2, Integer.MAX_VALUE, USAGE);
	public static void main(String[] args) throws IOException, DocumentException {				DetectorFactoryCollection.instance();		UpdateCommandLine commandLine = new UpdateCommandLine();		int argCount = commandLine.parse(args, 2, 3, "Usage: " + Update.class.getName()				+ " [options] <historyData> <newData> [<mergedData>] ");		String origFileName = args[argCount++];		String newFileName = args[argCount++];		boolean verbose = argCount < args.length;		origCollection = new SortedBugCollection(				SortedBugCollection.MultiversionBugInstanceComparator.instance);		BugCollection oCollection = origCollection;		origCollection.readXML(origFileName, new Project());		for (BugInstance bug : origCollection.getCollection())			if (bug.getLastVersion() >= 0 && bug.getFirstVersion() > bug.getLastVersion())				throw new IllegalStateException("Illegal Version range: " + bug.getFirstVersion()						+ ".." + bug.getLastVersion());		Project currentProject = new Project();		newCollection = new SortedBugCollection(				SortedBugCollection.MultiversionBugInstanceComparator.instance);		BugCollection nCollection = newCollection;		newCollection.readXML(newFileName, currentProject);				if (commandLine.revisionName != null)			newCollection.setReleaseName(commandLine.revisionName);		if (commandLine.revisionTimestamp != 0)			newCollection.setTimestamp(commandLine.revisionTimestamp);				if (verbose)			System.out.println(origCollection.getCollection().size() + " orig bugs, "				+ newCollection.getCollection().size() + " new bugs");		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().getSequenceNumber());		origCollectionVersion.setReleaseName(origCollection.getCurrentAppVersion().getReleaseName());		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(new SortedBugCollection.BugInstanceComparator());		matchBugs(VersionInsensitiveBugComparator.instance());		matchBugs(new SloppyBugComparator());		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 (verbose) {			resultCollection.writeXML(args[argCount++], currentProject);			System.out.println("Bugs: " + oldBugs + " old, " + deadBugInDeadCode + " in removed code, "					+ (newlyDeadBugs - deadBugInDeadCode) + " died, " + persistantBugs + " persist, "					+ addedInNewCode + " in new code, " + (addedBugs - addedInNewCode) + " added");		} else 	resultCollection.writeXML(System.out, currentProject);	}