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