sparqlGraphLibrary/src/main/java/com/ge/research/semtk/sparqlX/dispatch/FdcServiceManager.java
public boolean nextFdcNode() throws Exception {
		
		if (this.unprocessedFdcNodes.size() == 0) {
			return false;
		}

		// loop through looking for an easy answer
		for (String sparqlId : this.unprocessedFdcNodes) {
			Node fdcNode = this.nodegroup.getNodeBySparqlID(sparqlId);

			// does it have no unprocessed dependencies
			if (! this.hasUnresolvedDependencies(sparqlId)) {

				// mark this node as processed
				this.unprocessedFdcNodes.remove(sparqlId);

				// return it
				this.currFdcDataNode = fdcNode;
				this.currFdcTypeCache = FdcServiceManager.getFdcTypeCache().getSubsetWhereMatches("fdcClass", this.currFdcDataNode.getFullUriName());
				return true;
			} 

		}
		

		// Didn't find one with no dependencies
		// so loop through again and try removing some dependencies
		for (String sparqlId : this.unprocessedFdcNodes) {
			Node fdcNode = this.nodegroup.getNodeBySparqlID(sparqlId);

			HashMap<String, NodeGroup> ngHashEntryCopy = new HashMap<String, NodeGroup>();
			boolean failFlag = false;

			// loop through paramsets
			for (String paramSet : this.paramNodegroups.get(sparqlId).keySet()) {

				// copy the param nodegroup
				NodeGroup paramNg = this.paramNodegroups.get(sparqlId).get(paramSet);
				NodeGroup paramNgCopy = NodeGroup.deepCopy(paramNg);
				ngHashEntryCopy.put(paramSet, paramNgCopy);

				// delete all unresolved Fdc nodes and their subgraphs
				for (Node unresolvedNode : this.getUnresolvedNodes(paramNg)) {
					Node unresolvedCopy = paramNgCopy.getNodeBySparqlID(unresolvedNode.getSparqlID());
					// if deleting a previous subgraph didn't already delete this unresolved fdc node
					if (unresolvedCopy != null) {
						paramNgCopy.deleteNode(unresolvedCopy, paramHeadNodes.get(sparqlId).get(paramSet));  
					}
				}

				// check to see if new param nodegroup still has all the necessary returns
				ArrayList<String> remainingSparqlIDs = paramNgCopy.getReturnedSparqlIDs();
				String [] columnNames = this.getInputColumnNames(fdcNode.getFullUriName(), paramSet);
				for (String col : columnNames) {
					if (! remainingSparqlIDs.contains("?" + col)) {
						failFlag = true;
					}
				}

			}

			// dependent fdc nodes were removed from all param nodegroups and they still contain all necessary returns
			if (! failFlag) {
				// replace param nodegroups with whittled down copies
				this.paramNodegroups.put(sparqlId, ngHashEntryCopy);

				// mark this node as processed
				this.unprocessedFdcNodes.remove(sparqlId);

				// return it
				this.currFdcDataNode = fdcNode;
				this.currFdcTypeCache = FdcServiceManager.getFdcTypeCache().getSubsetWhereMatches("fdcClass", this.currFdcDataNode.getFullUriName());
				return true;
			}

		}
		
			
		if (this.unprocessedFdcNodes.size() != 0) {
			throw new Exception("Can't untangle FDC dependencies: " + this.unprocessedFdcNodes);
		} else {
			return false;
		}
	}
/**
	 * Set proccessing to the next Fdc node in the nodegroup
	 * @return boolean success (false means done; no more)
	 */
Set proccessing to the next Fdc node in the nodegroup
@return boolean success (false means done; no more)
Set proccessing to the next Fdc node in the nodegroup @return boolean success ( false means done ; no more )
public boolean nextFdcNode() throws Exception {
		if (this.unprocessedFdcNodes.size() == 0) {
			return false;
		}
		for (String sparqlId : this.unprocessedFdcNodes) {
			Node fdcNode = this.nodegroup.getNodeBySparqlID(sparqlId);
			if (! this.hasUnresolvedDependencies(sparqlId)) {
				this.unprocessedFdcNodes.remove(sparqlId);
				this.currFdcDataNode = fdcNode;
				this.currFdcTypeCache = FdcServiceManager.getFdcTypeCache().getSubsetWhereMatches("fdcClass", this.currFdcDataNode.getFullUriName());
				return true;
			} 
		}
		for (String sparqlId : this.unprocessedFdcNodes) {
			Node fdcNode = this.nodegroup.getNodeBySparqlID(sparqlId);
			HashMap<String, NodeGroup> ngHashEntryCopy = new HashMap<String, NodeGroup>();
			boolean failFlag = false;
			for (String paramSet : this.paramNodegroups.get(sparqlId).keySet()) {
				NodeGroup paramNg = this.paramNodegroups.get(sparqlId).get(paramSet);
				NodeGroup paramNgCopy = NodeGroup.deepCopy(paramNg);
				ngHashEntryCopy.put(paramSet, paramNgCopy);
				for (Node unresolvedNode : this.getUnresolvedNodes(paramNg)) {
					Node unresolvedCopy = paramNgCopy.getNodeBySparqlID(unresolvedNode.getSparqlID());
					if (unresolvedCopy != null) {
						paramNgCopy.deleteNode(unresolvedCopy, paramHeadNodes.get(sparqlId).get(paramSet));  
					}
				}
				ArrayList<String> remainingSparqlIDs = paramNgCopy.getReturnedSparqlIDs();
				String [] columnNames = this.getInputColumnNames(fdcNode.getFullUriName(), paramSet);
				for (String col : columnNames) {
					if (! remainingSparqlIDs.contains("?" + col)) {
						failFlag = true;
					}
				}
			}
			if (! failFlag) {
				this.paramNodegroups.put(sparqlId, ngHashEntryCopy);
				this.unprocessedFdcNodes.remove(sparqlId);
				this.currFdcDataNode = fdcNode;
				this.currFdcTypeCache = FdcServiceManager.getFdcTypeCache().getSubsetWhereMatches("fdcClass", this.currFdcDataNode.getFullUriName());
				return true;
			}
		}
		if (this.unprocessedFdcNodes.size() != 0) {
			throw new Exception("Can't untangle FDC dependencies: " + this.unprocessedFdcNodes);
		} else {
			return false;
		}
	}
public boolean nextFdcNode ( ) throws Exception { if ( this . unprocessedFdcNodes . size ( ) == 0 ) { return false ; } for ( String sparqlId : this . unprocessedFdcNodes ) { Node fdcNode = this . nodegroup . getNodeBySparqlID ( sparqlId ) ; if ( ! this . hasUnresolvedDependencies ( sparqlId ) ) { this . unprocessedFdcNodes . remove ( sparqlId ) ; this . currFdcDataNode = fdcNode ; this . currFdcTypeCache = FdcServiceManager . getFdcTypeCache ( ) . getSubsetWhereMatches ( "fdcClass" , this . currFdcDataNode . getFullUriName ( ) ) ; return true ; } } for ( String sparqlId : this . unprocessedFdcNodes ) { Node fdcNode = this . nodegroup . getNodeBySparqlID ( sparqlId ) ; HashMap < String , NodeGroup > ngHashEntryCopy = new HashMap < String , NodeGroup > ( ) ; boolean failFlag = false ; for ( String paramSet : this . paramNodegroups . get ( sparqlId ) . keySet ( ) ) { NodeGroup paramNg = this . paramNodegroups . get ( sparqlId ) . get ( paramSet ) ; NodeGroup paramNgCopy = NodeGroup . deepCopy ( paramNg ) ; ngHashEntryCopy . put ( paramSet , paramNgCopy ) ; for ( Node unresolvedNode : this . getUnresolvedNodes ( paramNg ) ) { Node unresolvedCopy = paramNgCopy . getNodeBySparqlID ( unresolvedNode . getSparqlID ( ) ) ; if ( unresolvedCopy != null ) { paramNgCopy . deleteNode ( unresolvedCopy , paramHeadNodes . get ( sparqlId ) . get ( paramSet ) ) ; } } ArrayList < String > remainingSparqlIDs = paramNgCopy . getReturnedSparqlIDs ( ) ; String [ ] columnNames = this . getInputColumnNames ( fdcNode . getFullUriName ( ) , paramSet ) ; for ( String col : columnNames ) { if ( ! remainingSparqlIDs . contains ( "?" + col ) ) { failFlag = true ; } } } if ( ! failFlag ) { this . paramNodegroups . put ( sparqlId , ngHashEntryCopy ) ; this . unprocessedFdcNodes . remove ( sparqlId ) ; this . currFdcDataNode = fdcNode ; this . currFdcTypeCache = FdcServiceManager . getFdcTypeCache ( ) . getSubsetWhereMatches ( "fdcClass" , this . currFdcDataNode . getFullUriName ( ) ) ; return true ; } } if ( this . unprocessedFdcNodes . size ( ) != 0 ) { throw new Exception ( "Can't untangle FDC dependencies: " + this . unprocessedFdcNodes ) ; } else { return false ; } }
Set proccessing to the next Fdc node in the nodegroup
 @return boolean success (false means done; no more)
Set proccessing to the next Fdc node in the nodegroup @return boolean success ( false means done ; no more )
// loop through looking for an easy answer // does it have no unprocessed dependencies // mark this node as processed // return it // Didn't find one with no dependencies // so loop through again and try removing some dependencies // loop through paramsets // copy the param nodegroup // delete all unresolved Fdc nodes and their subgraphs // if deleting a previous subgraph didn't already delete this unresolved fdc node // check to see if new param nodegroup still has all the necessary returns // dependent fdc nodes were removed from all param nodegroups and they still contain all necessary returns // replace param nodegroups with whittled down copies // mark this node as processed // return it