]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl.java
Work in progress
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / ConnectionImpl.java
1 package org.simantics.structural2;
2
3 import java.util.Collection;
4 import java.util.Set;
5
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.variable.Variable;
10 import org.simantics.structural2.variables.Connection;
11 import org.simantics.structural2.variables.ConnectionBrowser;
12 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
13
14 import gnu.trove.set.hash.THashSet;
15
16 public class ConnectionImpl implements Connection {
17
18         @Override
19         public int hashCode() {
20                 final int prime = 31;
21                 int result = 1;
22                 result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
23                 return result;
24         }
25
26         @Override
27         public boolean equals(Object obj) {
28                 if (this == obj)
29                         return true;
30                 if (obj == null)
31                         return false;
32                 if (getClass() != obj.getClass())
33                         return false;
34                 ConnectionImpl other = (ConnectionImpl) obj;
35                 if (predicate == null) {
36                         if (other.predicate != null)
37                                 return false;
38                 } else if (!predicate.equals(other.predicate))
39                         return false;
40                 return true;
41         }
42
43         final private Resource predicate;
44         
45         public ConnectionImpl(Resource predicate) {
46                 this.predicate = predicate;
47         }
48         
49         @Override
50         public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException {
51             Set<Variable> result = new THashSet<Variable>();
52             for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
53                 result.add(desc.getVariable(graph));
54             }
55             return result;
56         }
57         
58         @Override
59         public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException {
60             Set<String> result = new THashSet<String>();
61             for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
62                 result.add(desc.getURI(graph));
63             }
64             return result;
65         }
66
67         @Override
68         public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException {
69                 System.err.println("getConnectionPointDescriptors " + component.getURI(graph));
70             return ConnectionBrowser.flatten(graph, component, predicate, relationType);
71         }
72
73 }