]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/reference/IndexReference.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / reference / IndexReference.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
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         
30         @Override
31         public String toString(boolean labelReference) {
32                 return labelReference ? ""+index : "i-"+index;
33         }
34         
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         }
47
48         @Override
49         public boolean equals(Object obj) {
50                 if (obj instanceof IndexReference == false) return false;
51                 IndexReference other = (IndexReference) obj;
52                 if (other.index != index) return false;
53                 if (other.hasChildReference() != hasChildReference()) return false;
54                 if (hasChildReference() && !other.childReference.equals(childReference)) return false;
55                 return true;
56         }
57         
58         @Override
59         public int hashCode() {
60                 int hash = 423423 + 37 * index;
61                 if (hasChildReference()) hash = 31*hash + childReference.hashCode();            
62                 return hash;
63         }
64         
65 }
66