]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java
foobaz
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / ConnectionImpl2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.structural2;
13
14 import java.util.Collection;
15 import java.util.Set;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.layer0.variable.Variable;
21 import org.simantics.structural2.variables.Connection;
22 import org.simantics.structural2.variables.ConnectionBrowser;
23 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
24
25 import gnu.trove.set.hash.THashSet;
26
27 public class ConnectionImpl2 implements Connection {
28
29     private final Resource predicate;
30     
31     public ConnectionImpl2(Resource predicate) {
32         this.predicate = predicate;
33     }
34     
35     @Override
36     public int hashCode() {
37         final int prime = 31;
38         int result = 1;
39         result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
40         return result;
41     }
42
43     @Override
44     public boolean equals(Object obj) {
45         if (this == obj)
46             return true;
47         if (obj == null)
48             return false;
49         if (getClass() != obj.getClass())
50             return false;
51         ConnectionImpl2 other = (ConnectionImpl2) obj;
52         if (predicate == null) {
53             if (other.predicate != null)
54                 return false;
55         } else if (!predicate.equals(other.predicate))
56             return false;
57         return true;
58     }
59
60     @Override
61     public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
62         throw new UnsupportedOperationException();
63     }
64     
65     @Override
66     public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
67         throw new UnsupportedOperationException();
68     }
69
70     @Override
71     public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
72         throw new UnsupportedOperationException();
73     }
74
75     @Override
76     public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
77             throws DatabaseException {
78         Set<String> result = new THashSet<String>();
79         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
80             result.add(desc.getURI(graph));
81         }
82         return result;
83     }
84
85     @Override
86     public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
87             throws DatabaseException {
88         Set<Variable> result = new THashSet<Variable>();
89         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
90             result.add(desc.getVariable(graph));
91         }
92         return result;
93     }
94
95     @Override
96     public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
97             Variable component, Resource relationType) throws DatabaseException {
98         return ConnectionBrowser.flatten(graph, component, predicate, relationType);
99     }
100
101 }