X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Ftype%2FOptionalType.java;h=6a69316b82cb19f268bf93850be4521e990f9d12;hb=c69064f9e740eb4abe8448a63d306a085e036e1c;hp=d704e86b36012468a2d2c4329b22a17b84c7e504;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/OptionalType.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/OptionalType.java index d704e86b3..6a69316b8 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/OptionalType.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/OptionalType.java @@ -1,26 +1,26 @@ -/******************************************************************************* - * 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.ComponentReference; -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 java.util.Set; + +import org.simantics.databoard.accessor.error.ReferenceException; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.accessor.reference.ComponentReference; +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; public class OptionalType extends Datatype { public Datatype componentType; @@ -34,27 +34,27 @@ public class OptionalType extends Datatype { public Datatype getComponentType() { return componentType; - } - - @Override - public int getComponentCount() { - return 1; - } - - @Override - public Datatype getComponentType(int index) { - if (index!=0) throw new IllegalArgumentException(); - return componentType; - } - - @Override - public Datatype getComponentType(ChildReference path) { - if (path==null) return this; - if (path instanceof KeyReference) throw new IllegalArgumentException("KeyReference is not supported in OptionalType"); - if (path instanceof NameReference) throw new IllegalArgumentException("NameReference is not supported in OptionalType"); - if (path instanceof IndexReference && ((IndexReference) path).index!=0) throw new IllegalArgumentException("Index out of bounds"); - if (path instanceof LabelReference && !((LabelReference) path).label.equals("v")) throw new IllegalArgumentException("Unknown label"); - return componentType.getComponentType(path.childReference); + } + + @Override + public int getComponentCount() { + return 1; + } + + @Override + public Datatype getComponentType(int index) { + if (index!=0) throw new IllegalArgumentException(); + return componentType; + } + + @Override + public Datatype getComponentType(ChildReference path) { + if (path==null) return this; + if (path instanceof KeyReference) throw new IllegalArgumentException("KeyReference is not supported in OptionalType"); + if (path instanceof NameReference) throw new IllegalArgumentException("NameReference is not supported in OptionalType"); + if (path instanceof IndexReference && ((IndexReference) path).index!=0) throw new IllegalArgumentException("Index out of bounds"); + if (path instanceof LabelReference && !((LabelReference) path).label.equals("v")) throw new IllegalArgumentException("Unknown label"); + return componentType.getComponentType(path.childReference); } @Override @@ -63,16 +63,16 @@ public class OptionalType extends Datatype { componentType.collectSubtypes(subtypes, recursiveSubtypes); } - @Override - public int hashCode() { - return componentType.hashCode() + metadataHashCode(); - } - + @Override + public int hashCode() { + return componentType.hashCode() + metadataHashCode(); + } + @Override protected boolean deepEquals(Object obj, Set> compareHistory) { - if (this==obj) return true; - if (obj instanceof OptionalType == false) return false; - if ( !hasEqualMetadata(obj) ) return false; + if (this==obj) return true; + if (obj instanceof OptionalType == false) return false; + if ( !hasEqualMetadata(obj) ) return false; OptionalType other = (OptionalType) obj; return componentType.deepEquals(other.componentType, compareHistory); } @@ -86,24 +86,24 @@ public class OptionalType extends Datatype { public T accept(Visitor v) { return v.visit(this); } - - @SuppressWarnings("unchecked") - @Override - public T getChildType(ChildReference reference) throws ReferenceException { - if (reference==null) return (T) this; - - if (reference instanceof LabelReference) { - LabelReference lr = (LabelReference) reference; - if (lr.label.equals("o")) { - return componentType.getChildType(reference.getChildReference()); - } - } - - if (reference instanceof ComponentReference) { - return componentType.getChildType(reference.getChildReference()); - } - - throw new ReferenceException(reference.getClass()+" is not a reference of OptionalType"); - } + + @SuppressWarnings("unchecked") + @Override + public T getChildType(ChildReference reference) throws ReferenceException { + if (reference==null) return (T) this; + + if (reference instanceof LabelReference) { + LabelReference lr = (LabelReference) reference; + if (lr.label.equals("o")) { + return componentType.getChildType(reference.getChildReference()); + } + } + + if (reference instanceof ComponentReference) { + return componentType.getChildType(reference.getChildReference()); + } + + throw new ReferenceException(reference.getClass()+" is not a reference of OptionalType"); + } }