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