001package com.hfg.units; 002 003 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import com.hfg.util.StringUtil; 009 010//------------------------------------------------------------------------------ 011/** 012 Enumeration of biological potency units. 013 <div> 014 @author J. Alex Taylor, hairyfatguy.com 015 </div> 016 */ 017//------------------------------------------------------------------------------ 018// com.hfg XML/HTML Coding Library 019// 020// This library is free software; you can redistribute it and/or 021// modify it under the terms of the GNU Lesser General Public 022// License as published by the Free Software Foundation; either 023// version 2.1 of the License, or (at your option) any later version. 024// 025// This library is distributed in the hope that it will be useful, 026// but WITHOUT ANY WARRANTY; without even the implied warranty of 027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028// Lesser General Public License for more details. 029// 030// You should have received a copy of the GNU Lesser General Public 031// License along with this library; if not, write to the Free Software 032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 033// 034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 035// jataylor@hairyfatguy.com 036//------------------------------------------------------------------------------ 037 038public class BiologicalPotencyUnit extends Unit 039{ 040 private static Map<String, BiologicalPotencyUnit> sLookupMap = new HashMap<>(3); 041 042 public static final BiologicalPotencyUnit USP_unit = new BiologicalPotencyUnit(MeasurementSystem.BritishImperial, "USP units", "units"); 043 public static final BiologicalPotencyUnit international_unit = new BiologicalPotencyUnit(MeasurementSystem.SI, "international units", "IU"); 044 045 //########################################################################### 046 // CONSTRUCTORS 047 //########################################################################### 048 049 //--------------------------------------------------------------------------- 050 private BiologicalPotencyUnit(MeasurementSystem inSystem, String inName, String inAbbrev, SubUnit... inSubUnits) 051 { 052 super(inSystem, QuantityType.BIOLOGICAL_POTENCY, inName, inAbbrev, inSubUnits); 053 054 sLookupMap.put(name(), this); 055 sLookupMap.put(getAbbrev(), this); 056 } 057 058 //--------------------------------------------------------------------------- 059 protected BiologicalPotencyUnit(List<SubUnit> inSubUnits) 060 { 061 super(inSubUnits); 062 063 // Sanity check that we were give subunits of type 'biological potency'. 064 for (SubUnit subUnit : inSubUnits) 065 { 066 if (! subUnit.getUnit().getQuantityType().equals(QuantityType.BIOLOGICAL_POTENCY)) 067 { 068 throw new RuntimeException("Cannot construct a " + getClass().getSimpleName() + " for a subunit of type " + subUnit.getUnit().getQuantityType() + "!"); 069 } 070 } 071 } 072 073 //########################################################################### 074 // PUBLIC METHODS 075 //########################################################################### 076 077 //--------------------------------------------------------------------------- 078 public static BiologicalPotencyUnit valueOf(String inString) 079 { 080 return StringUtil.isSet(inString) ? sLookupMap.get(inString) : null; 081 } 082 083 //--------------------------------------------------------------------------- 084 @Override 085 public BiologicalPotencyUnit addAlternateName(String inValue) 086 { 087 return (BiologicalPotencyUnit) super.addAlternateName(inValue); 088 } 089 090}