X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FAdaptionExample2.java;fp=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FAdaptionExample2.java;h=9a707a6b760303ba8f0b2a03b9f9f8eb942d2922;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample2.java b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample2.java new file mode 100644 index 000000000..9a707a6b7 --- /dev/null +++ b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/AdaptionExample2.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.adapter.AdaptException; +import org.simantics.databoard.adapter.Adapter; +import org.simantics.databoard.adapter.AdapterConstructionException; +import org.simantics.databoard.annotations.Unit; +import org.simantics.databoard.binding.error.BindingConstructionException; + +public class AdaptionExample2 { + + static public class CarSI { + public String modelName; + public @Unit("km/h") double maxVelocity; + public @Unit("kg") double mass; + public @Unit("cm") double length; + public @Unit("kW") double power; + + @Override + public String toString() { + 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); + } + } + + static public class CarIm { + public String modelName; + public @Unit("mph") float maxVelocity; + public @Unit("lbs") float mass; + public @Unit("ft") float length; + public @Unit("hp(M)") float power; + + @Override + public String toString() { + 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); + } + } + + public static void main(String[] args) throws AdapterConstructionException, AdaptException, BindingConstructionException { + + Adapter si2imAdapter = Bindings.getTypeAdapter( + Bindings.getBinding(CarSI.class), + Bindings.getBinding(CarIm.class)); + + CarSI fiatSi = new CarSI(); + fiatSi.modelName = "Fiat 500"; + fiatSi.mass = 1035.; + fiatSi.length = 355.; + fiatSi.maxVelocity = 205.; + fiatSi.power = 75.; + + CarIm fiatIm = (CarIm) si2imAdapter.adapt( fiatSi ); + + System.out.println(fiatSi); + System.out.println(fiatIm); + } + +} +