X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Ftype%2FMapType.java;h=7a0ac3dc34010bffdea05a61340b24bd74e888b7;hp=4fede9cf9479d813e4f34ee2fe2595fb5c8aad6c;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/MapType.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/MapType.java index 4fede9cf9..7a0ac3dc3 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/MapType.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/MapType.java @@ -1,34 +1,34 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.databoard.type; -import java.util.Set; - -import org.simantics.databoard.accessor.error.ReferenceException; -import org.simantics.databoard.accessor.reference.ChildReference; -import org.simantics.databoard.accessor.reference.IndexReference; -import org.simantics.databoard.accessor.reference.KeyReference; -import org.simantics.databoard.accessor.reference.LabelReference; -import org.simantics.databoard.accessor.reference.NameReference; -import org.simantics.databoard.util.IdentityPair; -import org.simantics.databoard.util.ObjectUtils; +import java.util.Set; + +import org.simantics.databoard.accessor.error.ReferenceException; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.accessor.reference.IndexReference; +import org.simantics.databoard.accessor.reference.KeyReference; +import org.simantics.databoard.accessor.reference.LabelReference; +import org.simantics.databoard.accessor.reference.NameReference; +import org.simantics.databoard.util.IdentityPair; +import org.simantics.databoard.util.ObjectUtils; public class MapType extends Datatype { - + /** Key to describe if map is to be serialized ordered, the value is boolean value "false"/"true" */ - public static final String KEY_ORDERED = "ordered"; - + public static final String KEY_ORDERED = "ordered"; + public Datatype keyType; - public Datatype valueType; + public Datatype valueType; public MapType() { } @@ -39,38 +39,38 @@ public class MapType extends Datatype { this.keyType = keyType; this.valueType = valueType; } - - @Override - public int getComponentCount() { - return 2; - } - - @Override - public Datatype getComponentType(int index) { - if (index==0) return keyType; - if (index==1) return valueType; - throw new IllegalArgumentException(); - } - - @Override - public Datatype getComponentType(ChildReference path) { - if (path==null) return this; - if (path instanceof IndexReference) { - IndexReference ir = (IndexReference) path; - if (ir.index==0) return keyType.getComponentType(path.childReference); - if (ir.index==1) return valueType.getComponentType(path.childReference); - } - if (path instanceof LabelReference) { - LabelReference lr = (LabelReference) path; - if (lr.label.equals("0") || lr.label.equals("key")) return keyType.getComponentType(path.childReference); - if (lr.label.equals("1") || lr.label.equals("value")) return valueType.getComponentType(path.childReference); - } - if (path instanceof NameReference) { - NameReference nr = (NameReference) path; - if (nr.name.equals("key")) return keyType.getComponentType(path.childReference); - if (nr.name.equals("value")) return valueType.getComponentType(path.childReference); - } - throw new IllegalArgumentException(); + + @Override + public int getComponentCount() { + return 2; + } + + @Override + public Datatype getComponentType(int index) { + if (index==0) return keyType; + if (index==1) return valueType; + throw new IllegalArgumentException(); + } + + @Override + public Datatype getComponentType(ChildReference path) { + if (path==null) return this; + if (path instanceof IndexReference) { + IndexReference ir = (IndexReference) path; + if (ir.index==0) return keyType.getComponentType(path.childReference); + if (ir.index==1) return valueType.getComponentType(path.childReference); + } + if (path instanceof LabelReference) { + LabelReference lr = (LabelReference) path; + if (lr.label.equals("0") || lr.label.equals("key")) return keyType.getComponentType(path.childReference); + if (lr.label.equals("1") || lr.label.equals("value")) return valueType.getComponentType(path.childReference); + } + if (path instanceof NameReference) { + NameReference nr = (NameReference) path; + if (nr.name.equals("key")) return keyType.getComponentType(path.childReference); + if (nr.name.equals("value")) return valueType.getComponentType(path.childReference); + } + throw new IllegalArgumentException(); } @Override public void accept(Visitor1 v, Object obj) { @@ -85,8 +85,8 @@ public class MapType extends Datatype { @Override protected boolean deepEquals(Object obj, Set> compareHistory) { - if (this==obj) return true; - if ( !hasEqualMetadata(obj) ) return false; + if (this==obj) return true; + if ( !hasEqualMetadata(obj) ) return false; if (obj instanceof MapType == false) return false; MapType other = (MapType) obj; @@ -108,21 +108,21 @@ public class MapType extends Datatype { ObjectUtils.hashCode(keyType) * 13 + ObjectUtils.hashCode(valueType) * 17; } - - @SuppressWarnings("unchecked") - @Override - public T getChildType(ChildReference reference) throws ReferenceException { - if (reference==null) return (T) this; - - if (reference instanceof LabelReference) { -// LabelReference lr = (LabelReference) reference; - return keyType.getChildType(reference.getChildReference()); - } else if (reference instanceof KeyReference) { -// KeyReference ref = (KeyReference) reference; - return keyType.getChildType(reference.getChildReference()); - } - throw new ReferenceException(reference.getClass().getName()+" is not a reference of a map"); - } + + @SuppressWarnings("unchecked") + @Override + public T getChildType(ChildReference reference) throws ReferenceException { + if (reference==null) return (T) this; + + if (reference instanceof LabelReference) { +// LabelReference lr = (LabelReference) reference; + return keyType.getChildType(reference.getChildReference()); + } else if (reference instanceof KeyReference) { +// KeyReference ref = (KeyReference) reference; + return keyType.getChildType(reference.getChildReference()); + } + throw new ReferenceException(reference.getClass().getName()+" is not a reference of a map"); + } }