All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.units.VolumeUnit Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.units;


import java.util.HashMap;
import java.util.Map;

import com.hfg.units.length.LengthUnit;
import com.hfg.util.StringUtil;

//------------------------------------------------------------------------------
/**
 Enumeration of standard volume units.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class VolumeUnit extends Unit { private static Map sInstanceMap = new HashMap<>(); public static final VolumeUnit liter = new VolumeUnit(MeasurementSystem.Metric, "liter", "L", new SubUnit(LengthUnit.meter, SI_ScalingFactor.deci, 3)).addAlternateName("l"); public static final VolumeUnit milliliter = new VolumeUnit(MeasurementSystem.Metric, "milliliter", "mL", new SubUnit(liter, SI_ScalingFactor.milli)); public static final VolumeUnit microliter = new VolumeUnit(MeasurementSystem.Metric, "microliter", "μL", new SubUnit(liter, SI_ScalingFactor.micro)); // British Imperial units public static final VolumeUnit fluid_ounce = new VolumeUnit(MeasurementSystem.BritishImperial, "fluid ounce", "fl oz", new BaseSIUnitConverter(0.0284130625)); public static final VolumeUnit pint = new VolumeUnit(MeasurementSystem.BritishImperial, "pint", "pt", new BaseSIUnitConverter(0.56826125)); public static final VolumeUnit quart = new VolumeUnit(MeasurementSystem.BritishImperial, "quart", "qt", new BaseSIUnitConverter(1.1365225)); public static final VolumeUnit gallon = new VolumeUnit(MeasurementSystem.BritishImperial, "gallon", "gal", new BaseSIUnitConverter(4.54609)); //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- private VolumeUnit(MeasurementSystem inSystem, SubUnit inSubUnit) { super(inSystem, QuantityType.VOLUME, inSubUnit); } //--------------------------------------------------------------------------- private VolumeUnit(MeasurementSystem inSystem, String inName, String inAbbrev, BaseSIUnitConverter inConversionToBaseSIUnit) { this(inSystem, inName, inAbbrev, null, inConversionToBaseSIUnit); } //--------------------------------------------------------------------------- private VolumeUnit(MeasurementSystem inSystem, String inName, String inAbbrev, Integer inPow, BaseSIUnitConverter inConversionToBaseSIUnit) { super(inSystem, QuantityType.VOLUME, inName, inAbbrev, inPow, inConversionToBaseSIUnit); sInstanceMap.put(name(), this); sInstanceMap.put(getAbbrev(), this); } //--------------------------------------------------------------------------- private VolumeUnit(MeasurementSystem inSystem, String inName, String inAbbrev, SubUnit inSubUnit) { super(inSystem, QuantityType.VOLUME, inName, inAbbrev, inSubUnit); sInstanceMap.put(name(), this); sInstanceMap.put(getAbbrev(), this); } //--------------------------------------------------------------------------- private VolumeUnit(MeasurementSystem inSystem, String inName, String inAbbrev, Integer inPow) { super(inSystem, QuantityType.VOLUME, inName, inAbbrev, inPow); sInstanceMap.put(name(), this); sInstanceMap.put(getAbbrev(), this); } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public static VolumeUnit valueOf(String inString) { return StringUtil.isSet(inString) ? sInstanceMap.get(inString) : null; } //--------------------------------------------------------------------------- @Override public VolumeUnit addAlternateName(String inValue) { return (VolumeUnit) super.addAlternateName(inValue); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy