1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.accessor.reference;
14 import org.simantics.databoard.util.URIUtil;
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) {
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;
48 public ChildReference clone() {
49 return new NameReference(name, childReference==null ? null : childReference.clone());
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;
63 public int hashCode() {
64 int hash = 4665456 + 37 * name.hashCode();
65 if (hasChildReference()) hash = 31*hash + childReference.hashCode();