]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/reference/LabelReference.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / reference / LabelReference.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;\r
13 \r
14 import org.simantics.databoard.util.URIUtil;\r
15 \r
16 /**\r
17  * Label Reference is a reference that can be consumed by any Accessor interface. \r
18  * If contains the reference in string format\r
19  *\r
20  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
21  */\r
22 public class LabelReference extends ChildReference {\r
23         \r
24         public String label;\r
25         \r
26         public LabelReference(String label) {\r
27                 this.label = label;\r
28         }\r
29         \r
30         public LabelReference(String label, ChildReference child) {\r
31                 super(child);\r
32                 this.label = label;\r
33         }\r
34         \r
35         @Override\r
36         public String toString(boolean labelReference) {        \r
37                 return URIUtil.encodeURI(label);\r
38         }\r
39 \r
40         @Override\r
41         public ChildReference clone() {\r
42                 return new LabelReference(label, childReference==null ? null : childReference.clone());\r
43         }\r
44         \r
45         @Override\r
46         public boolean equals(Object obj) {\r
47                 if (obj instanceof LabelReference == false) return false;\r
48                 LabelReference other = (LabelReference) obj;\r
49                 if (!other.label.equals(label)) return false;\r
50                 if (other.hasChildReference() != hasChildReference()) return false;\r
51                 if (hasChildReference() && !other.childReference.equals(childReference)) return false;\r
52                 return true;\r
53         }\r
54         \r
55         @Override\r
56         public int hashCode() {\r
57                 int hash = 4699956 + 37 * label.hashCode();\r
58                 if (hasChildReference()) hash = 31*hash + childReference.hashCode();            \r
59                 return hash;\r
60         }       \r
61         \r
62         \r
63 }\r