]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/reference/NameReference.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / reference / NameReference.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  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.databoard.accessor.reference;
13
14 import org.simantics.databoard.util.URIUtil;
15
16
17 /**
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         
40         @Override
41         public String toString(boolean labelReference) {
42                 if (labelReference && (name.equals("uv") || name.equals("o") || name.equals("v"))) labelReference = false;
43                 String encoded = URIUtil.encodeURI(name);
44                 return labelReference ? encoded : "n-"+encoded; 
45         }
46         
47         @Override
48         public ChildReference clone() {
49                 return new NameReference(name, childReference==null ? null : childReference.clone());
50         }       
51
52         @Override
53         public boolean equals(Object obj) {
54                 if (obj instanceof NameReference == false) return false;
55                 NameReference other = (NameReference) obj;
56                 if (!other.name.equals(name)) return false;
57                 if (other.hasChildReference() != hasChildReference()) return false;
58                 if (hasChildReference() && !other.childReference.equals(childReference)) return false;
59                 return true;
60         }
61         
62         @Override
63         public int hashCode() {
64                 int hash = 4665456 + 37 * name.hashCode();
65                 if (hasChildReference()) hash = 31*hash + childReference.hashCode();            
66                 return hash;
67         }       
68         
69 }
70