X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FConnectionSet.java;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fqueries%2FConnectionSet.java;h=a965fb2032ef3773b0cad6b151b23f6f9e7cbf3f;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=9591d8d30dfd4ed283941a9b0244222d1596ab23;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionSet.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionSet.java index 9591d8d30..a965fb203 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionSet.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionSet.java @@ -1,102 +1,102 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.structural2.queries; - -import gnu.trove.set.hash.THashSet; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.service.CollectionSupport; -import org.simantics.structural.stubs.StructuralResource2; - -public class ConnectionSet { - - final Set connections; - THashSet joins; - THashSet excluded; - THashSet excludedJoins; - - StructuralResource2 sr; - -// public ConnectionSet() { -// -// } - - public ConnectionSet(ReadGraph graph) { - sr = StructuralResource2.getInstance(graph); - connections = graph.getService(CollectionSupport.class).createSet(); - } - - public boolean excludeConnection(Resource connection) { - if (excluded == null) - excluded = new THashSet(); - return excluded.add(connection); - } - - public boolean excludeJoin(Resource join) { - if (excludedJoins == null) - excludedJoins = new THashSet(); - return excludedJoins.add(join); - } - - public boolean excludeConnections(Collection connections) { - if (connections.isEmpty()) - return false; - if (excluded == null) - excluded = new THashSet(); - return excluded.addAll(connections); - } - - public boolean isExcluded(Resource connection) { - return excluded != null && excluded.contains(connection); - } - - public boolean isJoinExcluded(Resource join) { - return excludedJoins != null && excludedJoins.contains(join); - } - - public void addConnection(ReadGraph g, Resource connection) throws DatabaseException { - if(isExcluded(connection)) - return; - if(connections.add(connection)) { - if(sr == null) sr = StructuralResource2.getInstance(g); - for(Resource join : g.getObjects(connection, sr.IsJoinedBy)) - addJoin(g, join); - } - } - - public void addJoin(ReadGraph g, Resource join) throws DatabaseException { - if(isJoinExcluded(join)) - return; - if (joins == null) - joins = new THashSet(); - if(joins.add(join)) { - if(sr == null) sr = StructuralResource2.getInstance(g); - for(Resource connection : g.getObjects(join, sr.Joins)) - addConnection(g, connection); - } - } - - public Set getConnections() { - return connections; - } - - public Set getJoins() { - if(joins == null) return Collections.emptySet(); - return joins; - } -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.structural2.queries; + +import gnu.trove.set.hash.THashSet; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.CollectionSupport; +import org.simantics.structural.stubs.StructuralResource2; + +public class ConnectionSet { + + final Set connections; + THashSet joins; + THashSet excluded; + THashSet excludedJoins; + + StructuralResource2 sr; + +// public ConnectionSet() { +// +// } + + public ConnectionSet(ReadGraph graph) { + sr = StructuralResource2.getInstance(graph); + connections = graph.getService(CollectionSupport.class).createSet(); + } + + public boolean excludeConnection(Resource connection) { + if (excluded == null) + excluded = new THashSet(); + return excluded.add(connection); + } + + public boolean excludeJoin(Resource join) { + if (excludedJoins == null) + excludedJoins = new THashSet(); + return excludedJoins.add(join); + } + + public boolean excludeConnections(Collection connections) { + if (connections.isEmpty()) + return false; + if (excluded == null) + excluded = new THashSet(); + return excluded.addAll(connections); + } + + public boolean isExcluded(Resource connection) { + return excluded != null && excluded.contains(connection); + } + + public boolean isJoinExcluded(Resource join) { + return excludedJoins != null && excludedJoins.contains(join); + } + + public void addConnection(ReadGraph g, Resource connection) throws DatabaseException { + if(isExcluded(connection)) + return; + if(connections.add(connection)) { + if(sr == null) sr = StructuralResource2.getInstance(g); + for(Resource join : g.getObjects(connection, sr.IsJoinedBy)) + addJoin(g, join); + } + } + + public void addJoin(ReadGraph g, Resource join) throws DatabaseException { + if(isJoinExcluded(join)) + return; + if (joins == null) + joins = new THashSet(); + if(joins.add(join)) { + if(sr == null) sr = StructuralResource2.getInstance(g); + for(Resource connection : g.getObjects(join, sr.Joins)) + addConnection(g, connection); + } + } + + public Set getConnections() { + return connections; + } + + public Set getJoins() { + if(joins == null) return Collections.emptySet(); + return joins; + } +}