]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/ConnectionImpl2.java
Support for creating shared ontology dump to git
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / ConnectionImpl2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 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.Collections;
16 import java.util.Set;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.variable.Variable;
22 import org.simantics.structural2.variables.Connection;
23 import org.simantics.structural2.variables.Connection2;
24 import org.simantics.structural2.variables.ConnectionBrowser;
25 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
26
27 import gnu.trove.set.hash.THashSet;
28
29 public class ConnectionImpl2 implements Connection, Connection2 {
30
31     private final Resource predicate;
32
33     public ConnectionImpl2(Resource predicate) {
34         this.predicate = predicate;
35     }
36
37     @Override
38     public int hashCode() {
39         final int prime = 31;
40         int result = 1;
41         result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
42         return result;
43     }
44
45     @Override
46     public boolean equals(Object obj) {
47         if (this == obj)
48             return true;
49         if (obj == null)
50             return false;
51         if (getClass() != obj.getClass())
52             return false;
53         ConnectionImpl2 other = (ConnectionImpl2) obj;
54         if (predicate == null) {
55             if (other.predicate != null)
56                 return false;
57         } else if (!predicate.equals(other.predicate))
58             return false;
59         return true;
60     }
61
62     @Override
63     public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
64             throws DatabaseException {
65         Set<String> result = new THashSet<String>();
66         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
67             result.add(desc.getURI(graph));
68         }
69         return result;
70     }
71
72     @Override
73     public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
74             throws DatabaseException {
75         Set<Variable> result = new THashSet<Variable>();
76         for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
77             result.add(desc.getVariable(graph));
78         }
79         return result;
80     }
81
82     @Override
83     public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
84             Variable component, Resource relationType) throws DatabaseException {
85         return ConnectionBrowser.flatten(graph, component, predicate, relationType);
86     }
87
88     @Override
89     public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
90         throw new IllegalStateException();
91     }
92
93     @Override
94     public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
95         throw new IllegalStateException();
96     }
97
98     @Override
99     public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
100             Resource relationType) throws DatabaseException {
101         return Collections.emptyList();
102         //throw new IllegalStateException();
103     }
104
105     @Override
106     public Connection2 getConnection2() {
107         return this;
108     }
109
110 }