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.Bindings;
\r
15 import org.simantics.databoard.adapter.Adapter;
\r
16 import org.simantics.databoard.binding.Binding;
\r
17 import org.simantics.databoard.binding.mutable.Variant;
\r
18 import org.simantics.databoard.util.URIUtil;
\r
24 public class KeyReference extends ChildReference {
26 static Adapter VARIANT_TO_STRING_ADAPTER = Bindings.getAdapterUnchecked(Bindings.VARIANT, Bindings.STR_VARIANT);
\r
30 public KeyReference() {
\r
33 public KeyReference(Binding keyBinding, Object key) {
34 this.key = new Variant(keyBinding, key);
37 public KeyReference(Variant key) {
38 this.key = key.clone();
41 public KeyReference(Variant key, ChildReference child) {
43 this.key = key.clone();
47 public String toString(boolean labelReference) {
\r
48 String strKey = (String) VARIANT_TO_STRING_ADAPTER.adaptUnchecked(key);
\r
49 return labelReference ? URIUtil.encodeURI( strKey ) : "k-"+strKey;
\r
53 public ChildReference clone() {
54 return new KeyReference(key.clone(), childReference==null ? null : childReference.clone());
58 public boolean equals(Object obj) {
\r
59 if (obj instanceof KeyReference == false) return false;
\r
60 KeyReference other = (KeyReference) obj;
\r
61 if (!other.key.equals(key)) return false;
\r
62 if (other.hasChildReference() != hasChildReference()) return false;
\r
63 if (hasChildReference() && !other.childReference.equals(childReference)) return false;
\r
68 public int hashCode() {
\r
69 int hash = 61468996 + 37 * key.hashCode();
\r
70 if (hasChildReference()) hash = 31*hash + childReference.hashCode();
\r
75 public String toString() {
\r