| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.xtext.functionlibrary.common.uomo; |
| |
| import static org.eclipse.uomo.units.SI.Prefix.*; |
| import static org.eclipse.uomo.units.SI.GRAM; |
| import static org.eclipse.uomo.units.SI.KILOGRAM; |
| |
| import java.util.LinkedHashSet; |
| import java.util.Locale; |
| import java.util.Set; |
| import java.util.TreeMap; |
| |
| import org.eclipse.uomo.units.SI; |
| import org.eclipse.uomo.units.impl.BaseAmount; |
| import org.eclipse.uomo.units.impl.format.LocalUnitFormatImpl; |
| import org.eclipse.uomo.units.impl.quantity.MassAmount; |
| import org.unitsofmeasurement.quantity.Mass; |
| import org.unitsofmeasurement.unit.Unit; |
| |
| /** |
| * System of metric length units |
| */ |
| public class MetricMassUnit extends ASystemOfQuantityUnits<SI,Mass> implements ISystemOfQuantityUnits<SI,Mass> { |
| |
| protected MetricMassUnit() { |
| super("Metric Length Units", SI.class, Mass.class, MassAmount.class); |
| } |
| |
| protected final static TreeMap<Double,Unit<?>> sUnits = new TreeMap<Double,Unit<?>> (); |
| protected static MetricMassUnit INSTANCE = new MetricMassUnit(); |
| |
| private static LocalUnitFormatImpl formatUS = LocalUnitFormatImpl.getInstance(Locale.US); |
| public final static Unit<Mass> KG = SI.addUnit(KILOGRAM).asType(Mass.class); |
| public final static Unit<Mass> G = SI.addUnit(GRAM, formatUS.format(GRAM)).asType(Mass.class); |
| // public final static Unit<Mass> G = SI.addUnit(MILLI(KILOGRAM)).asType(Mass.class); |
| // public final static Unit<Mass> G = SI.addUnit(GRAM, "g").asType(Mass.class); |
| // public final static Unit<Mass> KG = SI.addUnit(KILOGRAM, "kg").asType(Mass.class); |
| // public final static Unit<Mass> MG = SI.addUnit(MILLI(GRAM)).asType(Mass.class); |
| public final static Unit<Mass> MG = SI.addUnit(GRAM.divide(1000d), "mg").asType(Mass.class); |
| // public final static Unit<Mass> T = SI.addUnit(KILO(KILOGRAM), "t").asType(Mass.class); |
| public final static Unit<Mass> T = SI.addUnit(KILOGRAM.multiply(1000d), "t").asType(Mass.class); |
| |
| static { |
| addUnits(sUnits, G, KG, MG, T); |
| } |
| |
| protected final static MetricMassUnit getInstance() { |
| if (INSTANCE == null) { |
| INSTANCE = new MetricMassUnit(); |
| } |
| return INSTANCE; |
| } |
| |
| @Override |
| public Set<Unit<?>> getUnits() { |
| return units(); |
| } |
| |
| /** |
| * @see #getUnits() |
| */ |
| public static Set<Unit<?>> units() { |
| return new LinkedHashSet<Unit<?>>(sUnits.values()); |
| } |
| |
| /** |
| * @see #createAmount(Number, Unit) |
| */ |
| public static BaseAmount<Mass> amount(Number number, Unit<Mass> unit) { |
| return getInstance().createAmount(number, unit); |
| } |
| } |