1 /*******************************************************************************
2 * Copyright (c) 2018 Association for Decentralized Information Management in
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
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.structural2;
14 import java.util.Collection;
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;
26 import gnu.trove.set.hash.THashSet;
29 * @author Antti Villberg
32 public class ConnectionImpl implements Connection {
34 private final Variable component;
35 private final Resource predicate;
37 public ConnectionImpl(Variable component, Resource predicate) {
38 this.component = component;
39 this.predicate = predicate;
43 public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
44 Set<Variable> result = new THashSet<Variable>();
45 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
46 result.add(desc.getVariable(graph));
52 public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
53 Set<String> result = new THashSet<String>();
54 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, predicate, relationType)) {
55 result.add(desc.getURI(graph));
61 public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
62 Resource relationType) throws DatabaseException {
63 return ConnectionBrowser.flatten(graph, component, predicate, relationType);
67 public Connection2 getConnection2() {
68 return new ConnectionImpl2(predicate);
72 public int hashCode() {
75 result = prime * result + ((component == null) ? 0 : component.hashCode());
76 result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
81 public boolean equals(Object obj) {
86 if (getClass() != obj.getClass())
88 ConnectionImpl other = (ConnectionImpl) obj;
89 if (component == null) {
90 if (other.component != null)
92 } else if (!component.equals(other.component))
94 if (predicate == null) {
95 if (other.predicate != null)
97 } else if (!predicate.equals(other.predicate))