com.hfg.units.SI_ScalingFactor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.units;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.hfg.util.CompareUtil;
import com.hfg.util.collection.OrderedMap;
//------------------------------------------------------------------------------
/**
Standard SI / Metric scaling factors.
@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 SI_ScalingFactor implements Comparable
{
private static Map sInstanceMap = new OrderedMap<>();
private static Set sInstances = new HashSet<>();
private String mPrefix;
private String mSymbol;
private String mAlternateSymbol;
private double mScalingFactor;
public static final SI_ScalingFactor yocto = new SI_ScalingFactor("yocto", "y", 1E-24);
public static final SI_ScalingFactor zepto = new SI_ScalingFactor("zepto", "z", 1E-21);
public static final SI_ScalingFactor atto = new SI_ScalingFactor("atto", "a", 1E-18);
public static final SI_ScalingFactor femto = new SI_ScalingFactor("femto", "f", 1E-15);
public static final SI_ScalingFactor pico = new SI_ScalingFactor("pico", "p", 1E-12);
public static final SI_ScalingFactor nano = new SI_ScalingFactor("nano", "n", 1E-9);
public static final SI_ScalingFactor micro = new SI_ScalingFactor("micro", "μ", 1E-6).setAlternateSymbol("µ"); // There are 2 different unicode characters for 'µ'
public static final SI_ScalingFactor milli = new SI_ScalingFactor("milli", "m", 1E-3);
public static final SI_ScalingFactor centi = new SI_ScalingFactor("centi", "c", 1E-2);
public static final SI_ScalingFactor deci = new SI_ScalingFactor("deci", "d", 1E-1);
public static final SI_ScalingFactor one = new SI_ScalingFactor("", "", 1);
public static final SI_ScalingFactor deca = new SI_ScalingFactor("deca", "da", 10);
public static final SI_ScalingFactor hecto = new SI_ScalingFactor("hecto", "h", 1E2);
public static final SI_ScalingFactor kilo = new SI_ScalingFactor("kilo", "k", 1E3);
public static final SI_ScalingFactor mega = new SI_ScalingFactor("mega", "M", 1E6);
public static final SI_ScalingFactor giga = new SI_ScalingFactor("giga", "G", 1E9);
public static final SI_ScalingFactor tera = new SI_ScalingFactor("tera", "T", 1E12);
public static final SI_ScalingFactor peta = new SI_ScalingFactor("peta", "P", 1E15);
public static final SI_ScalingFactor exa = new SI_ScalingFactor("exa", "E", 1E18);
public static final SI_ScalingFactor zetta = new SI_ScalingFactor("zetta", "Z", 1E21);
public static final SI_ScalingFactor yotta = new SI_ScalingFactor("yotta", "Y", 1E24);
//---------------------------------------------------------------------------
private SI_ScalingFactor(String inPrefix, String inSymbol, double inScalingFactor)
{
mPrefix = inPrefix;
mSymbol = inSymbol;
mScalingFactor = inScalingFactor;
sInstances.add(this);
sInstanceMap.put(mSymbol, this);
sInstanceMap.put(mPrefix, this);
}
//---------------------------------------------------------------------------
public static SI_ScalingFactor valueOf(String inString)
{
return sInstanceMap.get(inString);
}
//---------------------------------------------------------------------------
public static SI_ScalingFactor[] values()
{
return sInstances.toArray(new SI_ScalingFactor[] {});
}
//---------------------------------------------------------------------------
public String getPrefix()
{
return mPrefix;
}
//---------------------------------------------------------------------------
public String getSymbol()
{
return mSymbol;
}
//---------------------------------------------------------------------------
private SI_ScalingFactor setAlternateSymbol(String inValue)
{
mAlternateSymbol = inValue;
sInstanceMap.put(mAlternateSymbol, this);
return this;
}
//---------------------------------------------------------------------------
public String getAlternateSymbol()
{
return mAlternateSymbol;
}
//---------------------------------------------------------------------------
public double getScalingFactor()
{
return mScalingFactor;
}
//---------------------------------------------------------------------------
@Override
public String toString()
{
return getPrefix();
}
//---------------------------------------------------------------------------
@Override
public boolean equals(Object inObj2)
{
return (inObj2 != null
&& inObj2 instanceof SI_ScalingFactor
&& 0 == compareTo((SI_ScalingFactor) inObj2));
}
//---------------------------------------------------------------------------
@Override
public int hashCode()
{
int hashCode = getPrefix().hashCode();
hashCode += 31 * getSymbol().hashCode();
hashCode += 31 * getScalingFactor();
return hashCode;
}
//---------------------------------------------------------------------------
public int compareTo(Object inObj2)
{
int result = -1;
if (inObj2 != null)
{
if (inObj2 instanceof SI_ScalingFactor)
{
SI_ScalingFactor scalingFactor2 = (SI_ScalingFactor) inObj2;
result = CompareUtil.compare(getPrefix(), scalingFactor2.getPrefix());
if (0 == result)
{
result = CompareUtil.compare(getSymbol(), scalingFactor2.getSymbol());
}
if (0 == result)
{
result = CompareUtil.compare(getScalingFactor(), scalingFactor2.getScalingFactor());
}
}
}
return result;
}
}