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 electric current 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 ElectricCurrentUnit extends Unit
039{
040   private static Map<String, ElectricCurrentUnit> sLookupMap = new HashMap<>(3);
041
042   public static final ElectricCurrentUnit ampere     = new ElectricCurrentUnit(MeasurementSystem.SI, "ampere", "A");
043
044
045   //###########################################################################
046   // CONSTRUCTORS
047   //###########################################################################
048
049   //---------------------------------------------------------------------------
050   private ElectricCurrentUnit(MeasurementSystem inSystem, String inName, String inAbbrev)
051   {
052      super(inSystem, QuantityType.ELECTRIC_CURRENT, inName, inAbbrev);
053
054      sLookupMap.put(name(), this);
055      sLookupMap.put(getAbbrev(), this);
056   }
057
058   //---------------------------------------------------------------------------
059   protected ElectricCurrentUnit(List<SubUnit> inSubUnits)
060   {
061      super(inSubUnits);
062
063      // Sanity check that we were give subunits of type 'electric current'.
064      for (SubUnit subUnit : inSubUnits)
065      {
066         if (! subUnit.getUnit().getQuantityType().equals(QuantityType.ELECTRIC_CURRENT))
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 ElectricCurrentUnit valueOf(String inString)
079   {
080      return StringUtil.isSet(inString) ? sLookupMap.get(inString) : null;
081   }
082
083}