blob: 51c631bd2ce931b489701c4da7d8af2dde43f85a [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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.xtext.functionlibrary.common.uomo;
import static org.eclipse.uomo.units.SI.SQUARE_METRE;
import java.util.LinkedHashSet;
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.quantity.AreaAmount;
import org.unitsofmeasurement.quantity.Area;
import org.unitsofmeasurement.quantity.Length;
import org.unitsofmeasurement.unit.Unit;
/**
* System of metric area units.<br>
* @see {@link http://de.wikipedia.org/wiki/Quadratmeter}
*/
public class MetricAreaUnit extends ASystemOfQuantityUnits<SI,Area> implements ISystemOfQuantityUnits<SI,Area> {
protected MetricAreaUnit() {
super("Metric Area Units", SI.class, Area.class, AreaAmount.class);
}
protected final static TreeMap<Double,Unit<?>> sUnits = new TreeMap<Double,Unit<?>> ();
protected static MetricAreaUnit INSTANCE = new MetricAreaUnit();
public final static Unit<Area> CM2 = SI.addUnit(SQUARE_METRE.divide(10000.0), "cm²").asType(Area.class);
public final static Unit<Area> DM2 = SI.addUnit(SQUARE_METRE.divide(100.0), "dm²").asType(Area.class);
public final static Unit<Area> M2 = SI.addUnit(SQUARE_METRE, "m²").asType(Area.class);
public final static Unit<Area> A = SI.addUnit(SQUARE_METRE.multiply(100.0), "a").asType(Area.class);
public final static Unit<Area> HA = SI.addUnit(SQUARE_METRE.multiply(10000.0), "ha").asType(Area.class);
static {
addUnits(sUnits, CM2, DM2, M2, A, HA);
}
protected final static MetricAreaUnit getInstance() {
if (INSTANCE == null) {
INSTANCE = new MetricAreaUnit();
}
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<Area> amount(Number number, Unit<Area> unit) {
return getInstance().createAmount(number, unit);
}
/**
* @param side
* @return calculate the area for a quadrat
*/
public static BaseAmount<Area> calculateQuadrat(BaseAmount<Length> side) {
return calculateRectangle(side, side);
}
/**
* @param width
* @param height
* @return calculate the area for a rectangle
*/
@SuppressWarnings("unchecked")
public static BaseAmount<Area> calculateRectangle(BaseAmount<Length> width, BaseAmount<Length> height) {
return ((BaseAmount<Area>)((BaseAmount<?>)(width.multiply(height.to(width.unit()))))).to(M2);
}
}