]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java
Sync git svn branch with SVN repository r33324.
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / modelingRules / CPTerminal.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.structural2.modelingRules;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.request.SafeName;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 \r
19 public class CPTerminal implements IConnectionPoint {\r
20 \r
21     public final Resource component; // may be null for reference elements\r
22     public final Resource relation;\r
23 \r
24     public CPTerminal(Resource component, Resource relation) {\r
25         if (relation == null)\r
26             throw new NullPointerException("null relation");\r
27         this.component = component;\r
28         this.relation = relation;\r
29     }\r
30 \r
31     @Override\r
32     public String toString(ReadGraph g) throws DatabaseException {\r
33         return "CPTerminal(" + \r
34             g.syncRequest(new SafeName(component)) + ", " +\r
35             g.syncRequest(new SafeName(relation)) + ")";\r
36     }\r
37 \r
38     @Override\r
39     public int hashCode() {\r
40         final int prime = 31;\r
41         int result = 1;\r
42         result = prime * result + (component == null ? 0 : component.hashCode());\r
43         result = prime * result + relation.hashCode();\r
44         return result;\r
45     }\r
46 \r
47     @Override\r
48     public boolean equals(Object obj) {\r
49         if (this == obj)\r
50             return true;\r
51         if (obj == null)\r
52             return false;\r
53         if (getClass() != obj.getClass())\r
54             return false;\r
55         CPTerminal other = (CPTerminal) obj;\r
56         return (component == null ? other.component == null : component.equals(other.component)) && relation.equals(other.relation);\r
57     }\r
58 \r
59 }\r