| /** |
| * |
| * 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 java.util.ArrayList; |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import org.eclipse.uomo.units.AbstractSystemOfUnits; |
| import org.eclipse.uomo.units.impl.BaseAmount; |
| import org.unitsofmeasurement.quantity.Quantity; |
| import org.unitsofmeasurement.unit.Unit; |
| |
| |
| /** |
| * All available systems of units <code>ISystemOfQuantityUnits</code>, combining SystemOfMetrics and Quantity.<br> |
| * @see {@link http://www.ptb.de/cms/fileadmin/internet/publikationen/Einheiten_deutsch.pdf} |
| */ |
| public class SystemsOfQuantityUnits { |
| |
| public final static MetricLengthUnit METRIC_LENGTH_UNIT = MetricLengthUnit.getInstance(); |
| public final static MetricAreaUnit METRIC_AREA_UNIT = MetricAreaUnit.getInstance(); |
| public final static MetricVolumeUnit METRIC_VOLUME_UNIT = MetricVolumeUnit.getInstance(); |
| public final static MetricMassUnit METRIC_MASS_UNIT = MetricMassUnit.getInstance(); |
| public final static ImperialLengthUnit IMPERIAL_LENGTH_UNIT = ImperialLengthUnit.getInstance(); |
| |
| private final static ArrayList<ISystemOfQuantityUnits<?,?>> sSystemsOfQuantityUnits = new ArrayList<ISystemOfQuantityUnits<?,?>> (); |
| |
| static { |
| sSystemsOfQuantityUnits.add(METRIC_LENGTH_UNIT); |
| sSystemsOfQuantityUnits.add(METRIC_AREA_UNIT); |
| sSystemsOfQuantityUnits.add(METRIC_VOLUME_UNIT); |
| sSystemsOfQuantityUnits.add(METRIC_MASS_UNIT); |
| sSystemsOfQuantityUnits.add(IMPERIAL_LENGTH_UNIT); |
| } |
| |
| // public static BaseAmount<?> amount(Number number, Unit unit) { |
| // if (unit instanceof Unit<Length>) { |
| // } |
| // else { |
| // return null; |
| // } |
| // } |
| |
| /** |
| * @return set of all available quantities |
| */ |
| public static Set<Class<?>> getQuantities() { |
| HashSet<Class<?>> retcode = new HashSet<Class<?>>(); |
| for (ISystemOfQuantityUnits<?,?> unit : sSystemsOfQuantityUnits) { |
| retcode.add(unit.getQuantityClass()); |
| } |
| return retcode; |
| } |
| |
| /** |
| * @return set of all available system of quantity units |
| */ |
| public static Set<ISystemOfQuantityUnits<?,?>> elements() { |
| return new HashSet<ISystemOfQuantityUnits<?,?>>(sSystemsOfQuantityUnits); |
| } |
| |
| /** |
| * @param systemOfUnits |
| * @param quantity |
| * @return set of all available system of quantity units available for systemOfUnits and quantity |
| */ |
| public static ArrayList<ISystemOfQuantityUnits<?,?>> elements(Class<AbstractSystemOfUnits> systemOfUnits, Class<Quantity<?>> quantity) { |
| ArrayList<ISystemOfQuantityUnits<?,?>> retcode = new ArrayList<ISystemOfQuantityUnits<?,?>>(); |
| for (ISystemOfQuantityUnits<?,?> unit : sSystemsOfQuantityUnits) { |
| if (unit.handles(systemOfUnits) && unit.handles(quantity)) { |
| retcode.add(unit); |
| } |
| } |
| return retcode; |
| } |
| |
| /** |
| * @param findUnit |
| * @return set of all available system of quantity units compatible to findUnit |
| */ |
| public static ArrayList<ISystemOfQuantityUnits<?,?>> elements(BaseAmount<?> amount) { |
| return elements(amount.unit()); |
| } |
| |
| /** |
| * @param findUnit |
| * @return set of all available system of quantity units compatible to findUnit |
| */ |
| public static ArrayList<ISystemOfQuantityUnits<?,?>> elements(Unit<?> findUnit) { |
| ArrayList<ISystemOfQuantityUnits<?,?>> retcode = new ArrayList<ISystemOfQuantityUnits<?,?>>(); |
| for (ISystemOfQuantityUnits<?,?> unit : sSystemsOfQuantityUnits) { |
| if (unit.getUnits().iterator().next().isCompatible(findUnit)) { |
| retcode.add(unit); |
| } |
| } |
| return retcode; |
| } |
| |
| /** |
| * @param systemOfUnitsOrQuantity |
| * @return set of all available system of quantity units available for systemOfUnits or quantity |
| */ |
| public static ArrayList<ISystemOfQuantityUnits<?,?>> elements(Class<?> systemOfUnitsOrQuantity) { |
| ArrayList<ISystemOfQuantityUnits<?,?>> retcode = new ArrayList<ISystemOfQuantityUnits<?,?>>(); |
| for (ISystemOfQuantityUnits<?,?> unit : sSystemsOfQuantityUnits) { |
| if (unit.handles(systemOfUnitsOrQuantity)) { |
| retcode.add(unit); |
| } |
| } |
| return retcode; |
| } |
| } |