]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample2.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / old / AdaptionExample2.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.adapter.AdaptException;
16 import org.simantics.databoard.adapter.Adapter;
17 import org.simantics.databoard.adapter.AdapterConstructionException;
18 import org.simantics.databoard.annotations.Unit;
19 import org.simantics.databoard.binding.error.BindingConstructionException;
20
21 public class AdaptionExample2 {
22
23         static public class CarSI {
24                 public String modelName;                
25                 public @Unit("km/h") double maxVelocity;                
26                 public @Unit("kg") double mass;         
27                 public @Unit("cm") double length; 
28                 public @Unit("kW") double power;
29                 
30                 @Override
31                 public String toString() {
32                         return String.format("Name:%s, Mass: %2.0f kg, Power: %2.0f kW, Speed: %2.0f km/h, Length: %2.0f cm", modelName, mass, power, maxVelocity, length);
33                 }
34         }
35
36         static public class CarIm {
37                 public String modelName;                
38                 public @Unit("mph") float maxVelocity;          
39                 public @Unit("lbs") float mass;         
40                 public @Unit("ft") float length; 
41                 public @Unit("hp(M)") float power;
42                 
43                 @Override
44                 public String toString() {
45                         return String.format("Name:%s, Mass: %2.0f lbs, Power: %2.0f hp, Speed: %2.0f mph, Length: %2.0f ft", modelName, mass, power, maxVelocity, length);
46                 }
47         }
48
49         public static void main(String[] args) throws AdapterConstructionException, AdaptException, BindingConstructionException {
50                 
51                 Adapter si2imAdapter = Bindings.getTypeAdapter(
52                                 Bindings.getBinding(CarSI.class), 
53                                 Bindings.getBinding(CarIm.class));
54                 
55                 CarSI fiatSi = new CarSI();
56                 fiatSi.modelName = "Fiat 500";
57                 fiatSi.mass = 1035.;
58                 fiatSi.length = 355.;
59                 fiatSi.maxVelocity = 205.;
60                 fiatSi.power = 75.;
61
62                 CarIm fiatIm = (CarIm) si2imAdapter.adapt( fiatSi );            
63                 
64                 System.out.println(fiatSi);
65                 System.out.println(fiatIm);
66         }
67         
68 }
69