blob: 251e377c859cf776494030249e9632b9e2ef07be [file] [log] [blame]
/**
*
* 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.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.uomo.units.impl.BaseAmount;
import org.eclipse.uomo.units.impl.format.LocalUnitFormatImpl;
import org.eclipse.uomo.units.impl.quantity.LengthAmount;
import org.eclipse.uomo.units.impl.system.USCustomary;
import org.unitsofmeasurement.quantity.Length;
import org.unitsofmeasurement.unit.Unit;
/**
* System of metric length units
* @see https://en.wikipedia.org/wiki/Imperial_units
*/
public class ImperialLengthUnit extends ASystemOfQuantityUnits<USCustomary,Length> implements ISystemOfQuantityUnits<USCustomary,Length> {
protected ImperialLengthUnit() {
super("Imperial Length Units", USCustomary.class, Length.class, LengthAmount.class);
}
protected final static TreeMap<Double,Unit<?>> sUnits = new TreeMap<Double,Unit<?>> ();
private static LocalUnitFormatImpl formatUS = LocalUnitFormatImpl.getInstance(Locale.US);
public final static Unit<Length> IN = USCustomary.addUnit(USCustomary.INCH, formatUS.format(USCustomary.INCH)).asType(Length.class);
// public final static Unit<Length> FT = USCustomary.addUnit(USCustomary.FOOT, "ft").asType(Length.class);
public final static Unit<Length> FT = USCustomary.addUnit(USCustomary.FOOT, formatUS.format(USCustomary.FOOT)).asType(Length.class);
public final static Unit<Length> YD = USCustomary.addUnit(USCustomary.FOOT.multiply(3.0), "yd").asType(Length.class);
public final static Unit<Length> MI = USCustomary.addUnit(USCustomary.MILE, formatUS.format(USCustomary.MILE)).asType(Length.class);
// public final static Unit<Length> IN = USCustomary.addUnit(USCustomary.INCH.multiply(1.0), "in").asType(Length.class);
// public final static Unit<Length> FT = USCustomary.addUnit(USCustomary.FOOT.multiply(1.0), "ft").asType(Length.class);
// public final static Unit<Length> YD = USCustomary.addUnit(FT.multiply(3.0), "yd").asType(Length.class);
// public final static Unit<Length> MI = USCustomary.addUnit(USCustomary.MILE.multiply(1.0), "mi").asType(Length.class);
static {
addUnits(sUnits, IN, FT, YD, MI);
}
private static ImperialLengthUnit INSTANCE;
protected final static ImperialLengthUnit getInstance() {
if (INSTANCE == null) {
INSTANCE = new ImperialLengthUnit();
}
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<Length> amount(Number number, Unit<Length> unit) {
return getInstance().createAmount(number, unit);
}
}