X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Finternal%2Fqueries%2FConnectedTo.java;h=0ee4f1dd7798570bbc98748b2419514a0c22b7b5;hp=a0362d72d86a890a20a44d3918961177bfd74a71;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/internal/queries/ConnectedTo.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/internal/queries/ConnectedTo.java index a0362d72d..0ee4f1dd7 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/internal/queries/ConnectedTo.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/internal/queries/ConnectedTo.java @@ -1,66 +1,66 @@ -package org.simantics.structural2.internal.queries; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.common.request.ResourceRead2; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.structural2.queries.Terminal; -import org.simantics.structural2.utils.StructuralUtils; - -/** - * @author Tuukka Lehtonen - */ -public class ConnectedTo extends ResourceRead2> { - - private static final boolean DEBUG = false; - - public ConnectedTo(Resource component, Resource connectionPoint) { - super(component, connectionPoint); - } - - @Override - public Set perform(ReadGraph graph) throws DatabaseException { - if (DEBUG) - System.out.println("connectedTo(" + NameUtils.getSafeName(graph, resource) + ", " + NameUtils.getSafeName(graph, resource2) + ")"); - - Collection connections = graph.getObjects(resource, resource2); - if (connections.isEmpty()) - return Collections.emptySet(); - - Set reachableConnections = new HashSet(); - for (Resource connection : connections) { - reachableConnections.addAll(StructuralUtils.getRelatedConnections(graph, connection)); - } - - StructuralResource2 sr = StructuralResource2.getInstance(graph); - - Set connectedTo = new HashSet(); - - for (Resource connection : reachableConnections) { - if (DEBUG) - System.out.println(" checking connection: " + NameUtils.getSafeName(graph, connection)); - - for (Statement stm : graph.getStatements(connection, sr.Connects)) { - Resource connectionPoint2 = graph.getInverse(stm.getPredicate()); - if (resource2.equals(connectionPoint2) && resource.equals(stm.getObject())) - continue; - - if (DEBUG) - System.out.println(" connected to (" + NameUtils.getSafeName(graph, stm.getObject()) + ", " + NameUtils.getSafeName(graph, connectionPoint2) + ")"); - - connectedTo.add(new Terminal(stm.getObject(), connectionPoint2)); - } - } - - return connectedTo; - } - -} +package org.simantics.structural2.internal.queries; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.queries.Terminal; +import org.simantics.structural2.utils.StructuralUtils; + +/** + * @author Tuukka Lehtonen + */ +public class ConnectedTo extends ResourceRead2> { + + private static final boolean DEBUG = false; + + public ConnectedTo(Resource component, Resource connectionPoint) { + super(component, connectionPoint); + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + if (DEBUG) + System.out.println("connectedTo(" + NameUtils.getSafeName(graph, resource) + ", " + NameUtils.getSafeName(graph, resource2) + ")"); + + Collection connections = graph.getObjects(resource, resource2); + if (connections.isEmpty()) + return Collections.emptySet(); + + Set reachableConnections = new HashSet(); + for (Resource connection : connections) { + reachableConnections.addAll(StructuralUtils.getRelatedConnections(graph, connection)); + } + + StructuralResource2 sr = StructuralResource2.getInstance(graph); + + Set connectedTo = new HashSet(); + + for (Resource connection : reachableConnections) { + if (DEBUG) + System.out.println(" checking connection: " + NameUtils.getSafeName(graph, connection)); + + for (Statement stm : graph.getStatements(connection, sr.Connects)) { + Resource connectionPoint2 = graph.getInverse(stm.getPredicate()); + if (resource2.equals(connectionPoint2) && resource.equals(stm.getObject())) + continue; + + if (DEBUG) + System.out.println(" connected to (" + NameUtils.getSafeName(graph, stm.getObject()) + ", " + NameUtils.getSafeName(graph, connectionPoint2) + ")"); + + connectedTo.add(new Terminal(stm.getObject(), connectionPoint2)); + } + } + + return connectedTo; + } + +}