Java Code Examples for org.jgrapht.Graphs#successorListOf()

The following examples show how to use org.jgrapht.Graphs#successorListOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FIPAProtocol.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the node corresponding to a performative after the current node of the protocol.
 */
protected ProtocolNode getNode(final IScope scope, final FIPAMessage message, final ProtocolNode currentNode,
		final Performative performative, final boolean initiator) throws GamaRuntimeException {
	if (currentNode == null) {
		if (root != null && root.getPerformative() == performative)
			return root;
		return null;
	}
	final List<ProtocolNode> followingNodes = Graphs.successorListOf(this, currentNode);
	if (followingNodes.size() == 0) {
		throw GamaRuntimeException.warning("Message received in a conversation which has already ended!", scope);
	}
	final List<ProtocolNode> potentialMatchingNodes = new ArrayList<>();
	for (final ProtocolNode followingNode : followingNodes) {
		if (performative == followingNode.getPerformative()) {
			potentialMatchingNodes.add(followingNode);
		}
	}
	if (potentialMatchingNodes.isEmpty()) {
		throw GamaRuntimeException.warning("Protocol : " + this.getName()
				+ ". Unexpected message received of performative : " + message.getPerformativeName(), scope);
	}
	ProtocolNode matchingNode = null;
	for (final ProtocolNode potentialMatchingNode : potentialMatchingNodes) {
		if (initiator == potentialMatchingNode.isSentByInitiator()) {
			matchingNode = potentialMatchingNode;
			break;
		}
	}

	if (matchingNode == null) {
		throw GamaRuntimeException.warning("Couldn't match expected message types and participant", scope);
	}
	return matchingNode;

}
 
Example 2
Source File: GamlResourceIndexer.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see msi.gama.lang.gaml.indexer.IModelIndexer#directImportsOf(org.eclipse.emf.common.util.URI)
 */
public static Set<URI> directImportsOf(final URI uri) {
	final URI newURI = GamlResourceServices.properlyEncodedURI(uri);
	if (index.containsVertex(newURI)) { return new HashSet(Graphs.successorListOf(index, newURI)); }
	return Collections.EMPTY_SET;
}