X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2FByteBinding.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2FByteBinding.java;h=1325155ce3cb420943980e01c9a0b39a9e12fb30;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/ByteBinding.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/ByteBinding.java new file mode 100644 index 000000000..1325155ce --- /dev/null +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/ByteBinding.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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.binding.error.BindingException; +import org.simantics.databoard.binding.error.RuntimeBindingException; +import org.simantics.databoard.type.ByteType; +import org.simantics.databoard.util.IdentityPair; + +/** + * This is a binding of Byte Type and a Java Object. + * + * @see ByteType + * @author Toni Kalajainen + */ +public abstract class ByteBinding extends NumberBinding { + + public ByteBinding(ByteType type) { + this.type = type; + } + + @Override + public ByteType type() { + return (ByteType) type; + } + + public abstract Object create(byte value) throws BindingException; + public abstract Object create(Byte value) throws BindingException; + public abstract Object create(String value) throws BindingException; + public abstract Object create(Number value) throws BindingException; + public abstract Byte getValue(Object obj) throws BindingException; + public abstract byte getValue_(Object obj) throws BindingException; + public abstract void setValue(Object obj, Number value) throws BindingException; + public abstract void setValue(Object obj, byte value) throws BindingException; + public abstract boolean isInstance(Object obj); + + @Override + public void accept(Visitor1 v, Object obj) { + v.visit(this, obj); + } + + @Override + public T accept(Visitor v) { + return v.visit(this); + } + + + @Override + public int deepCompare(Object o1, Object o2, + Set> compareHistory) + throws BindingException { + byte v1 = getValue_(o1); + byte v2 = getValue_(o2); + return (int)v1 - (int)v2; + } + + @Override + public int deepHashValue(Object value, IdentityHashMap hashedObjects) throws BindingException { + byte v = getValue_(value); + return v; + } + + public Object createUnchecked(byte value) throws RuntimeBindingException { + try { + return create(value); + } catch (BindingException e) { + return new RuntimeBindingException(e); + } + } + public Object createUnchecked(Byte value) throws RuntimeBindingException { + try { + return create(value); + } catch (BindingException e) { + return new RuntimeBindingException(e); + } + } + + /* + @Override + public void assertInstaceIsValid(Object obj) + throws BindingException { + if (!isInstance(obj)) throw new BindingException("Not a boolean instance"); + ByteType type = getDataType(); + Byte min = type.getMin(); + Byte max = type.getMax(); + if (min!=null || max!=null) { + Byte value = getValue(obj); + if (min!=null && valuemax) throw new BindingException("The value is("+value+") over the maximum ("+max+")"); + } + } +*/ +} +