pass.addDetectorFactory(factory);
if (factory.isFirstInPass()) pass.prependDetectorFactory(factory); else pass.addDetectorFactory(factory);
	private void sortPass(			List<DetectorOrderingConstraint> constraintList,			Map<String, DetectorFactory> factoryMap,			AnalysisPass pass)		throws OrderingConstraintException {		// Preserve original order of detectors in pass		List<DetectorFactory> origDetectorList = new LinkedList<DetectorFactory>();		origDetectorList.addAll(pass.getDetectorFactoryList());		// Build set of all detectors in pass		Set<String> detectorSet = new HashSet<String>();		for (Iterator<DetectorFactory> i = pass.detectorFactoryIterator();			i.hasNext(); ) {			DetectorFactory factory = i.next();			detectorSet.add(factory.getFullName());		}		// Build list of ordering constraints in this pass only		List<DetectorOrderingConstraint> passConstraintList =			new LinkedList<DetectorOrderingConstraint>();		for (Iterator<DetectorOrderingConstraint> i = constraintList.iterator(); i.hasNext(); ) {			DetectorOrderingConstraint constraint = i.next();			if (detectorSet.contains(constraint.getEarlierDetector()) ||				detectorSet.contains(constraint.getLaterDetector())) {				// Make sure that both detectors are in this pass				if (!(detectorSet.contains(constraint.getEarlierDetector()) &&						detectorSet.contains(constraint.getLaterDetector()))) {					throw new OrderingConstraintException("Intra-pass constraint " +						constraint.getEarlierDetector() + " earlier than " +						constraint.getLaterDetector() + " involves detectors in " +						"different passes");				}				passConstraintList.add(constraint);			}		}		// Build intra-pass constraint graph		Map<String, DetectorNode> nodeMap = new HashMap<String, DetectorNode>();		ConstraintGraph constraintGraph = buildConstraintGraph(			nodeMap, factoryMap, passConstraintList);		if (DEBUG) {			System.out.println("Pass constraint graph:");			dumpGraph(constraintGraph);		}		// Perform DFS, check for cycles		DepthFirstSearch<ConstraintGraph, ConstraintEdge, DetectorNode> dfs =			new DepthFirstSearch<ConstraintGraph, ConstraintEdge, DetectorNode>(constraintGraph);		dfs.search();		if (dfs.containsCycle())			throw new OrderingConstraintException("Cycle in intra-pass ordering constraints!");		// Do a topological sort to put the detectors in the pass		// in the right order.		pass.clear();		for (Iterator<DetectorNode> i = dfs.topologicalSortIterator(); i.hasNext(); ) {			DetectorNode node = i.next();			pass.addDetectorFactory(node.getFactory());		}		// Add back detectors that aren't involved in any intra-pass		// ordering constraints.		for (Iterator<DetectorFactory> i = origDetectorList.iterator(); i.hasNext(); ) {			DetectorFactory factory = i.next();			if (nodeMap.get(factory.getFullName()) == null) {				pass.addDetectorFactory(factory);			}		}	}