--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.databoard.accessor.reference;
+
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.adapter.Adapter;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.util.URIUtil;\r
+
+/**
+ * Map Value
+ * "<key>/"
+ */
+public class KeyReference extends ChildReference {
+\r
+ static Adapter VARIANT_TO_STRING_ADAPTER = Bindings.getAdapterUnchecked(Bindings.VARIANT, Bindings.STR_VARIANT);\r
+
+ public Variant key;
+ \r
+ public KeyReference() {\r
+ }\r
+
+ public KeyReference(Binding keyBinding, Object key) {
+ this.key = new Variant(keyBinding, key);
+ }
+
+ public KeyReference(Variant key) {
+ this.key = key.clone();
+ }
+
+ public KeyReference(Variant key, ChildReference child) {
+ super(child);
+ this.key = key.clone();
+ }
+
+ @Override\r
+ public String toString(boolean labelReference) {\r
+ String strKey = (String) VARIANT_TO_STRING_ADAPTER.adaptUnchecked(key);\r
+ return labelReference ? URIUtil.encodeURI( strKey ) : "k-"+strKey;\r
+ }\r
+
+ @Override
+ public ChildReference clone() {
+ return new KeyReference(key.clone(), childReference==null ? null : childReference.clone());
+ }
+ \r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj instanceof KeyReference == false) return false;\r
+ KeyReference other = (KeyReference) obj;\r
+ if (!other.key.equals(key)) return false;\r
+ if (other.hasChildReference() != hasChildReference()) return false;\r
+ if (hasChildReference() && !other.childReference.equals(childReference)) return false;\r
+ return true;\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode() {\r
+ int hash = 61468996 + 37 * key.hashCode();\r
+ if (hasChildReference()) hash = 31*hash + childReference.hashCode(); \r
+ return hash;\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "["+key+"]";\r
+ }\r
+
+}
+