]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/reference/IndexReference.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / reference / IndexReference.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
14
15 /**
16  * Array element
17  * "i-<index>/"
18  */
19 public class IndexReference extends ChildReference {
20         
21         public int index;
22         
23         public IndexReference(int index) { this.index = index; }
24
25         public IndexReference(int index, ChildReference child) {
26                 super(child);
27                 this.index = index;             
28         }
29         \r
30         @Override\r
31         public String toString(boolean labelReference) {\r
32                 return labelReference ? ""+index : "i-"+index;\r
33         }\r
34         \r
35         public int getIndex() {
36                 return index;
37         }
38
39         public void setIndex(int index) {
40                 this.index = index;
41         }
42
43         @Override
44         public ChildReference clone() {
45                 return new IndexReference(index, childReference==null ? null : childReference.clone());
46         }\r
47 \r
48         @Override\r
49         public boolean equals(Object obj) {\r
50                 if (obj instanceof IndexReference == false) return false;\r
51                 IndexReference other = (IndexReference) obj;\r
52                 if (other.index != index) return false;\r
53                 if (other.hasChildReference() != hasChildReference()) return false;\r
54                 if (hasChildReference() && !other.childReference.equals(childReference)) return false;\r
55                 return true;\r
56         }\r
57         \r
58         @Override\r
59         public int hashCode() {\r
60                 int hash = 423423 + 37 * index;\r
61                 if (hasChildReference()) hash = 31*hash + childReference.hashCode();            \r
62                 return hash;\r
63         }\r
64         \r
65 }
66