1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.accessor.reference;
14 import org.simantics.databoard.util.URIUtil;
\r
18 * Reference by name to a record field.
21 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23 public class NameReference extends ChildReference {
27 public NameReference(String name) {
31 public NameReference(String name, ChildReference child) {
36 public String getName() {
41 public String toString(boolean labelReference) {
\r
42 if (labelReference && (name.equals("uv") || name.equals("o") || name.equals("v"))) labelReference = false;
\r
43 String encoded = URIUtil.encodeURI(name);
\r
44 return labelReference ? encoded : "n-"+encoded;
\r
48 public ChildReference clone() {
49 return new NameReference(name, childReference==null ? null : childReference.clone());
53 public boolean equals(Object obj) {
\r
54 if (obj instanceof NameReference == false) return false;
\r
55 NameReference other = (NameReference) obj;
\r
56 if (!other.name.equals(name)) return false;
\r
57 if (other.hasChildReference() != hasChildReference()) return false;
\r
58 if (hasChildReference() && !other.childReference.equals(childReference)) return false;
\r
63 public int hashCode() {
\r
64 int hash = 4665456 + 37 * name.hashCode();
\r
65 if (hasChildReference()) hash = 31*hash + childReference.hashCode();
\r