| /** |
| * Copyright (c) 2005, 2014, Werner Keil and others. |
| * 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: |
| * Werner Keil, Martin Desruisseaux - initial API and implementation |
| */ |
| package org.eclipse.osbp.xtext.functionlibrary.common.uomo.test; |
| |
| import static org.eclipse.uomo.units.SI.*; |
| import static org.eclipse.uomo.units.SI.Prefix.*; |
| import static org.eclipse.uomo.units.impl.system.USCustomary.FOOT; |
| import static org.eclipse.uomo.units.impl.system.USCustomary.INCH; |
| import static org.eclipse.uomo.units.impl.system.USCustomary.POUND; |
| import static org.eclipse.osbp.xtext.functionlibrary.common.uomo.test.PolishObsolete.*; |
| |
| import java.math.BigInteger; |
| |
| import org.eclipse.uomo.units.IMeasure; |
| import org.eclipse.uomo.units.SI; |
| import org.eclipse.uomo.units.impl.quantity.LengthAmount; |
| import org.eclipse.uomo.units.impl.quantity.MassAmount; |
| import org.eclipse.uomo.units.impl.quantity.TimeAmount; |
| import org.unitsofmeasurement.quantity.Length; |
| import org.unitsofmeasurement.quantity.Mass; |
| import org.unitsofmeasurement.quantity.Time; |
| import org.unitsofmeasurement.unit.Unit; |
| |
| /** |
| * @author <a href="mailto:desruisseaux@users.sourceforge.net">Martin Desruisseaux</a> |
| * @author <a href="mailto:uomo@catmedia.us">Werner Keil</a> |
| * @version 0.8.1, $Date: 2014-04-03 $ |
| */ |
| public class Demo { |
| |
| private static IMeasure<Length> getSomeLength() { |
| return new LengthAmount(20, METRE); |
| } |
| |
| private static IMeasure<Length> getMoreLength() { |
| return new LengthAmount(30, INCH); |
| } |
| |
| private static IMeasure<Mass> getSomeMass() { |
| return new MassAmount(40, KILOGRAM); |
| } |
| |
| private static IMeasure<Mass> getMoreMass() { |
| return new MassAmount(50, POUND); |
| } |
| |
| private static IMeasure<Time> getTime() { |
| return new TimeAmount(10, SECOND); |
| } |
| |
| public static void main(String[] args) { |
| IMeasure<Length> someLength = getSomeLength(); |
| System.out.println(someLength); |
| IMeasure<Length> moreLength = getMoreLength(); |
| System.out.println(moreLength); |
| System.out.println(); |
| |
| IMeasure<Mass> someMass = getSomeMass(); |
| System.out.println(someMass); |
| IMeasure<Mass> moreMass = getMoreMass(); |
| System.out.println(moreMass); |
| System.out.println(); |
| |
| IMeasure<Time> time = getTime(); |
| System.out.println(time); |
| |
| IMeasure<?> result = someLength.divide(time); |
| System.out.println(result); |
| result = moreLength.divide(time); |
| System.out.println(result); |
| System.out.println(); |
| |
| IMeasure<Length> convertedLength = moreLength.to(FOOT); |
| System.out.println(convertedLength); |
| |
| IMeasure<Length> convertedLengthPL = moreLength.to(ELL); |
| System.out.println(convertedLengthPL); |
| |
| |
| System.out.println(); |
| someLength = new LengthAmount(1, MILLI(METRE)); |
| System.out.println(someLength); |
| IMeasure<Length> someMoreLength = new LengthAmount(400, KILO(METRE)); |
| someMass = new MassAmount(60, MILLI(GRAM)); |
| System.out.println(someMass); |
| System.out.println(someMoreLength); |
| |
| System.out.println(); |
| |
| someMass = new MassAmount(60, MILLI(GRAM)); |
| System.out.println(someMass); |
| |
| someMass = new MassAmount(60, GRAM); |
| System.out.println(someMass); |
| |
| someMass = someMass.to(KILOGRAM); |
| System.out.println(someMass); |
| |
| someMass = new MassAmount(60, KILOGRAM); |
| System.out.println(someMass); |
| |
| System.out.println(); |
| |
| someLength = new LengthAmount(10, CENTI(METRE)); |
| System.out.println(someLength); |
| |
| System.out.println(someLength.to(MILLI(METRE))); |
| System.out.println(someLength.to(METRE)); |
| System.out.println(someLength.to(KILO(METRE))); |
| System.out.println(someLength.to(INCH)); |
| System.out.println(someLength.to(FOOT)); |
| |
| System.out.println(); |
| |
| someLength = new LengthAmount(10, METRE.divide(100d)); |
| System.out.println(someLength); |
| |
| System.out.println(someLength.to(MILLI(METRE))); |
| System.out.println(someLength.to(METRE)); |
| System.out.println(someLength.to(KILO(METRE))); |
| System.out.println(someLength.to(INCH)); |
| System.out.println(someLength.to(FOOT)); |
| |
| System.out.println(); |
| |
| someLength = new LengthAmount(10, METRE.divide(100d)); |
| System.out.println(someLength); |
| System.out.println(someLength.to(METRE.divide(1000d))); |
| System.out.println(someLength.to(METRE)); |
| System.out.println(someLength.to(METRE.multiply(1000d))); |
| System.out.println(someLength.to(INCH)); |
| System.out.println(someLength.to(FOOT)); |
| |
| |
| Integer value = new Integer(10); |
| BigInteger dividend = new BigInteger("1"); |
| BigInteger divisor = new BigInteger("100"); |
| long resultValue = (value.longValue() * dividend.longValue()) |
| / (divisor.longValue()); |
| System.out.println(resultValue); |
| } |
| } |