]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample1.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / old / AdaptionExample1.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.example.old;
13
14 import org.simantics.databoard.Bindings;
15 import org.simantics.databoard.binding.Binding;
16 import org.simantics.databoard.parser.repository.DataValueRepository;
17
18
19 /**
20  * In this DuckTyping example, one input is deserialized to three classes 
21  * that look about the same.  
22  *
23  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
24  */
25 public class AdaptionExample1 {
26         
27         static final String INPUT = "(3, 6, 9)";
28
29         static class DoubleVector {
30                 public DoubleVector() {}
31                 public double x, y, z;
32         }
33         static final Binding DoubleVectorBinding = Bindings.getBindingUnchecked( DoubleVector.class );
34                 
35         static class FloatVector {
36                 public FloatVector() {}
37                 public float x, y, z;
38         }
39         static final Binding FloatVectorBinding = Bindings.getBindingUnchecked( FloatVector.class );
40         
41         static class IntVector {
42                 public IntVector() {}
43                 public int x, y, z;
44         }
45         static final Binding IntVectorBinding = Bindings.getBindingUnchecked( IntVector.class );
46         
47         public static void main(String[] args) throws Exception {
48                 
49                 // Read to DoubleVector         
50                 DataValueRepository repo = new DataValueRepository(); 
51                 DoubleVector doubleVector = (DoubleVector) DoubleVectorBinding.parseValue( INPUT, repo );
52                 System.out.printf("DoubleVector: %f, %f, %f\n", doubleVector.x, doubleVector.y, doubleVector.z);
53                                 
54                 // Read to FloatVector
55                 FloatVector floatVector = (FloatVector) FloatVectorBinding.parseValue( INPUT, repo );
56                 System.out.printf("FloatVector: %f, %f, %f\n", floatVector.x, floatVector.y, floatVector.z);
57
58                 // Read to IntVector
59                 IntVector intVector = (IntVector) IntVectorBinding.parseValue( INPUT, repo );
60                 System.out.printf("IntVector: %d, %d, %d\n", intVector.x, intVector.y, intVector.z);
61         }
62         
63 }
64