X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FAdaptionExample1.java;fp=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FAdaptionExample1.java;h=626be798edb6d62012a2d5fdd6e750781c1830fb;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample1.java b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample1.java new file mode 100644 index 000000000..626be798e --- /dev/null +++ b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample1.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.example.old; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.parser.repository.DataValueRepository; + + +/** + * In this DuckTyping example, one input is deserialized to three classes + * that look about the same. + * + * @author Toni Kalajainen + */ +public class AdaptionExample1 { + + static final String INPUT = "(3, 6, 9)"; + + static class DoubleVector { + public DoubleVector() {} + public double x, y, z; + } + static final Binding DoubleVectorBinding = Bindings.getBindingUnchecked( DoubleVector.class ); + + static class FloatVector { + public FloatVector() {} + public float x, y, z; + } + static final Binding FloatVectorBinding = Bindings.getBindingUnchecked( FloatVector.class ); + + static class IntVector { + public IntVector() {} + public int x, y, z; + } + static final Binding IntVectorBinding = Bindings.getBindingUnchecked( IntVector.class ); + + public static void main(String[] args) throws Exception { + + // Read to DoubleVector + DataValueRepository repo = new DataValueRepository(); + DoubleVector doubleVector = (DoubleVector) DoubleVectorBinding.parseValue( INPUT, repo ); + System.out.printf("DoubleVector: %f, %f, %f\n", doubleVector.x, doubleVector.y, doubleVector.z); + + // Read to FloatVector + FloatVector floatVector = (FloatVector) FloatVectorBinding.parseValue( INPUT, repo ); + System.out.printf("FloatVector: %f, %f, %f\n", floatVector.x, floatVector.y, floatVector.z); + + // Read to IntVector + IntVector intVector = (IntVector) IntVectorBinding.parseValue( INPUT, repo ); + System.out.printf("IntVector: %d, %d, %d\n", intVector.x, intVector.y, intVector.z); + } + +} +