X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2FOptionalBinding.java;h=0c45ef01a734c742a05bede7b8a4b43fe1184353;hb=refs%2Fchanges%2F38%2F238%2F2;hp=b94a5fb7674b03c70fb297899d2c790fb5f3ff02;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/OptionalBinding.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/OptionalBinding.java index b94a5fb76..0c45ef01a 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/OptionalBinding.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/OptionalBinding.java @@ -1,31 +1,31 @@ -/******************************************************************************* - * 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.binding; -import java.util.IdentityHashMap; -import java.util.Set; - -import org.simantics.databoard.Bindings; -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.adapter.AdaptException; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.binding.error.RuntimeBindingException; -import org.simantics.databoard.binding.impl.BindingPrintContext; -import org.simantics.databoard.type.OptionalType; -import org.simantics.databoard.util.IdentityPair; +import java.util.IdentityHashMap; +import java.util.Set; + +import org.simantics.databoard.Bindings; +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.adapter.AdaptException; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.binding.error.RuntimeBindingException; +import org.simantics.databoard.binding.impl.BindingPrintContext; +import org.simantics.databoard.type.OptionalType; +import org.simantics.databoard.util.IdentityPair; /** @@ -96,32 +96,32 @@ public abstract class OptionalBinding extends Binding { public Binding getComponentBinding() { return componentBinding; } - - @Override - public void readFrom(Binding srcBinding, Object src, Object dst) - throws BindingException { - OptionalBinding sb = (OptionalBinding) srcBinding; - if (sb.hasValue(src)) { - Binding dcb = getComponentBinding(); - Binding scb = sb.getComponentBinding(); - Object scv = sb.getValue(src); - if (dcb.isImmutable() || !hasValue(dst)) { - try { - Object v = Bindings.clone(scv, scb, dcb); - v = dcb.readFromTry(scb, scv, v); - setValue(dst, v); - } catch (AdaptException e) { - throw new BindingException(e); - } - } else { - Object v = getValue(src); - v = dcb.readFromTry(scb, scv, v); - setValue(dst, v); - } - } else { - setNoValue(dst); - } - } + + @Override + public void readFrom(Binding srcBinding, Object src, Object dst) + throws BindingException { + OptionalBinding sb = (OptionalBinding) srcBinding; + if (sb.hasValue(src)) { + Binding dcb = getComponentBinding(); + Binding scb = sb.getComponentBinding(); + Object scv = sb.getValue(src); + if (dcb.isImmutable() || !hasValue(dst)) { + try { + Object v = Bindings.clone(scv, scb, dcb); + v = dcb.readFromTry(scb, scv, v); + setValue(dst, v); + } catch (AdaptException e) { + throw new BindingException(e); + } + } else { + Object v = getValue(src); + v = dcb.readFromTry(scb, scv, v); + setValue(dst, v); + } + } else { + setNoValue(dst); + } + } @Override public void accept(Visitor1 v, Object obj) { @@ -150,7 +150,7 @@ public abstract class OptionalBinding extends Binding { } @Override - public int deepCompare(Object o1, Object o2, Set> compareHistory) throws BindingException + public int deepCompare(Object o1, Object o2, Set> compareHistory) throws BindingException { Boolean h1 = hasValue(o1); Boolean h2 = hasValue(o2); @@ -188,45 +188,45 @@ public abstract class OptionalBinding extends Binding { throw new RuntimeBindingException(e); } } - - @Override - protected void toString(Object value, BindingPrintContext ctx) throws BindingException { - if(hasValue(value)) { - getComponentBinding().toString(getValue(value), ctx); - } else { - ctx.b.append("null"); - } - } - - @Override - public Binding getComponentBinding(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 componentBinding.getComponentBinding(path.childReference); - } - - @Override - public int getComponentCount() { - return 1; - } - - @Override - public Binding getComponentBinding(int index) { - if (index==0) return componentBinding; - throw new IllegalArgumentException(); - } - - @Override - protected boolean deepEquals(Object obj, - Set> compareHistory) { - return super.deepEquals( obj, compareHistory ) && componentBinding.equals(((OptionalBinding) obj).componentBinding, compareHistory); - } - - @Override - public int deepHashCode(IdentityHashMap hashedObjects) { - return super.deepHashCode( hashedObjects ) + componentBinding.hashCode(hashedObjects); + + @Override + protected void toString(Object value, BindingPrintContext ctx) throws BindingException { + if(hasValue(value)) { + getComponentBinding().toString(getValue(value), ctx); + } else { + ctx.b.append("null"); + } + } + + @Override + public Binding getComponentBinding(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 componentBinding.getComponentBinding(path.childReference); + } + + @Override + public int getComponentCount() { + return 1; + } + + @Override + public Binding getComponentBinding(int index) { + if (index==0) return componentBinding; + throw new IllegalArgumentException(); + } + + @Override + protected boolean deepEquals(Object obj, + Set> compareHistory) { + return super.deepEquals( obj, compareHistory ) && componentBinding.equals(((OptionalBinding) obj).componentBinding, compareHistory); + } + + @Override + public int deepHashCode(IdentityHashMap hashedObjects) { + return super.deepHashCode( hashedObjects ) + componentBinding.hashCode(hashedObjects); } }