resultCollection.clearAppVersions(); for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i.hasNext();) { AppVersion appVersion = i.next(); resultCollection.addAppVersion((AppVersion) appVersion.clone()); } AppVersion origCollectionVersion = new AppVersion(origCollection.getSequenceNumber()); origCollectionVersion.setTimestamp(origCollection.getTimestamp()); origCollectionVersion.setReleaseName(origCollection.getReleaseName()); resultCollection.addAppVersion(origCollectionVersion);
	public UpdateBugCollection execute() {		// Result collection is initialized using new collection's metadata		resultCollection = newCollection.createEmptyCollectionWithMetadata();		// Get Sets with exact contents of orig and new collections		SortedSet<BugInstance> origSetExact = collectionToExactSet(origCollection);		SortedSet<BugInstance> newSetExact = collectionToExactSet(newCollection);				// Get "fuzzy" matching sets of orig and new collections,		// for querying "same" warnings accross the two versions.		SortedSet<BugInstance> origSetFuzzy = collectionToFuzzySet(origCollection);		SortedSet<BugInstance> newSetFuzzy = collectionToFuzzySet(newCollection);		// Previous sequence number		long lastSequence = origCollection.getSequenceNumber();				// We assign a timestamp to the new collection as one greater than the		// original collection.		long currentSequence = origCollection.getSequenceNumber() + 1;		resultCollection.setSequenceNumber(currentSequence);		// Handle removed and retained warnings.		// These must be added using the SAME UNIQUE IDs as were present in the original bug collection.		for (BugInstance origWarning : origSetExact) {			BugInstance matchingNewWarning = findMatching(newSetFuzzy, origWarning);			BugInstance warningToAdd;						if (matchingNewWarning != null) {				// Warning is retained.				//				// From original, keep:				// - unique id				// - BugProperty list (classifications, &c.)				// - annotation text				//				// In all other respects, the warning is a clone of the matching new warning.				warningToAdd = (BugInstance) matchingNewWarning.clone();				warningToAdd.setUniqueId(origWarning.getUniqueId());				copyBugProperties(origWarning, warningToAdd);				warningToAdd.setAnnotationText(origWarning.getAnnotationText());								// Update the warning as being active at the current sequence number.				SequenceIntervalCollection whenActive = origWarning.getActiveIntervalCollection();				updateActiveIntervalCollection(lastSequence, currentSequence, whenActive);				warningToAdd.setActiveIntervalCollection(whenActive);			} else {				// Warning is removed.				// The old warning remains, but its metadata (classifications,				// when it was active) remains exactly the same.				warningToAdd = (BugInstance) origWarning.clone();			}						resultCollection.add(warningToAdd, false);		}				// Handle new warnings.		// These will be assigned new unique ids guaranteed not to conflict		// with any existing unique ids.		for (BugInstance newWarning : newSetExact) {			BugInstance matchingOrigWarning = findMatching(origSetFuzzy, newWarning);						if (matchingOrigWarning == null) {				// Added warning.				// Mark active at current time only, and add to result collection directly								SequenceIntervalCollection activeNow = new SequenceIntervalCollection();				activeNow.add(new SequenceInterval(currentSequence, currentSequence));								BugInstance warningToAdd = (BugInstance) newWarning.clone();				warningToAdd.setActiveIntervalCollection(activeNow);								resultCollection.add(warningToAdd, false);			}		}				return this;	}