]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/reference/NameReference.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / reference / NameReference.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  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.databoard.accessor.reference;
13 \r
14 import org.simantics.databoard.util.URIUtil;\r
15
16
17 /**\r
18  * Reference by name to a record field.
19  * Format: "n-<name>"
20  *
21  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
22  */
23 public class NameReference extends ChildReference {
24
25         public String name;
26         
27         public NameReference(String name) {
28                 this.name = name;
29         }
30         
31         public NameReference(String name, ChildReference child) {
32                 super(child);
33                 this.name = name;
34         }
35         
36         public String getName() {
37                 return name;
38         }
39         \r
40         @Override\r
41         public String toString(boolean labelReference) {\r
42                 if (labelReference && (name.equals("uv") || name.equals("o") || name.equals("v"))) labelReference = false;\r
43                 String encoded = URIUtil.encodeURI(name);\r
44                 return labelReference ? encoded : "n-"+encoded; \r
45         }\r
46         
47         @Override
48         public ChildReference clone() {
49                 return new NameReference(name, childReference==null ? null : childReference.clone());
50         }       \r
51 \r
52         @Override\r
53         public boolean equals(Object obj) {\r
54                 if (obj instanceof NameReference == false) return false;\r
55                 NameReference other = (NameReference) obj;\r
56                 if (!other.name.equals(name)) return false;\r
57                 if (other.hasChildReference() != hasChildReference()) return false;\r
58                 if (hasChildReference() && !other.childReference.equals(childReference)) return false;\r
59                 return true;\r
60         }\r
61         \r
62         @Override\r
63         public int hashCode() {\r
64                 int hash = 4665456 + 37 * name.hashCode();\r
65                 if (hasChildReference()) hash = 31*hash + childReference.hashCode();            \r
66                 return hash;\r
67         }       \r
68         
69 }
70