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

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

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

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

//------------------------------------------------------------------------------
/**
 Enumeration of concentration types.
 
@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] //------------------------------------------------------------------------------ // https://en.wikipedia.org/wiki/Concentration public class ConcentrationUnit extends Unit { private static Set sInstances = new HashSet<>(10); private static final Map sInstanceMap = new HashMap<>(10); public static final ConcentrationUnit molarity = new ConcentrationUnit(MeasurementSystem.SI, "molarity", "M", new SubUnit(AmountOfSubstanceUnit.mole), new SubUnit(VolumeUnit.liter, -1)); public static final ConcentrationUnit molality = new ConcentrationUnit(MeasurementSystem.SI, "molality", "", new SubUnit(AmountOfSubstanceUnit.mole), new SubUnit(MassUnit.gram, SI_ScalingFactor.kilo, -1)); /** * Normality is used for acid or base and is defined as the mole equivalents of H+ or OH- ions per liter. */ public static final ConcentrationUnit normality = new ConcentrationUnit(MeasurementSystem.SI, "normality", "N", new SubUnit(AmountOfSubstanceUnit.mole_equivalent), new SubUnit(VolumeUnit.liter, -1)); /** Volume fraction is the volume of a substance divided by the volume of the total mixture */ public static final ConcentrationUnit volume_fraction = new ConcentrationUnit(MeasurementSystem.SI, "volume fraction", "", new SubUnit(VolumeUnit.liter), new SubUnit(VolumeUnit.liter, -1)); /** Percent by volume is the percent ratio of the volume to the volume of the total mixture */ public static final ConcentrationUnit pct_by_volume = new ConcentrationUnit(MeasurementSystem.SI, "% by volume", "%(v/v)", new SubUnit(VolumeUnit.liter, SI_ScalingFactor.centi), new SubUnit(VolumeUnit.liter, -1)) .addAlternateName("% v/v"); /** Mass fraction is the mass of a substance divided by the mass of the total mixture */ public static final ConcentrationUnit mass_fraction = new ConcentrationUnit(MeasurementSystem.SI, "mass fraction", "", new SubUnit(MassUnit.gram, SI_ScalingFactor.kilo), new SubUnit(MassUnit.gram, SI_ScalingFactor.kilo, -1)); /** Percent by weight is the percent ratio of the volume to the volume of the total mixture */ public static final ConcentrationUnit pct_by_weight = new ConcentrationUnit(MeasurementSystem.SI, "% by weight", "%(w/w)", new SubUnit(MassUnit.gram, SI_ScalingFactor.centi), new SubUnit(MassUnit.gram, SI_ScalingFactor.kilo, -1)) .addAlternateName("% w/w"); //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- private ConcentrationUnit(MeasurementSystem inSystem, String inName, String inAbbrev, SubUnit... inSubUnits) { this(inSystem, inName, inAbbrev, null, null, inSubUnits); } //--------------------------------------------------------------------------- private ConcentrationUnit(MeasurementSystem inSystem, String inName, String inAbbrev, Integer inPow, BaseSIUnitConverter inConversionToBaseSIUnit, SubUnit[] inSubUnits) { super(inSystem, QuantityType.CONCENTRATION, inName, inAbbrev, inPow, inConversionToBaseSIUnit, inSubUnits); sInstances.add(this); sInstanceMap.put(name(), this); sInstanceMap.put(getAbbrev(), this); } //--------------------------------------------------------------------------- protected ConcentrationUnit(List inSubUnits) { super(inSubUnits); // Sanity check that we were give subunits of type 'concentration'. for (SubUnit subUnit : inSubUnits) { if (! subUnit.getUnit().getQuantityType().equals(QuantityType.CONCENTRATION)) { throw new RuntimeException("Cannot construct a " + getClass().getSimpleName() + " for a subunit of type " + subUnit.getUnit().getQuantityType() + "!"); } } } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public static Collection values() { return Collections.unmodifiableCollection(sInstances); } //--------------------------------------------------------------------------- @Override public ConcentrationUnit addAlternateName(String inValue) { return (ConcentrationUnit) super.addAlternateName(inValue); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy