001package com.hfg.units; 002 003 004import com.hfg.util.CompareUtil; 005 006//------------------------------------------------------------------------------ 007/** 008 Basic quantity types. 009 <div> 010 @author J. Alex Taylor, hairyfatguy.com 011 </div> 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg XML/HTML Coding Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class QuantityType implements Comparable 035{ 036 private String mName; 037 private String mAbbrev; 038 private boolean mIsBase; 039 040 // Base quantities 041 public static final QuantityType LENGTH = new QuantityType("length", "L", true); 042 public static final QuantityType MASS = new QuantityType("mass", "", true); 043 public static final QuantityType TIME = new QuantityType("time", "", true); 044 public static final QuantityType TEMPERATURE = new QuantityType("temperature", "", true); 045 public static final QuantityType AMOUNT_OF_SUBSTANCE = new QuantityType("amount of substance", "", true); 046 public static final QuantityType ELECTRIC_CURRENT = new QuantityType("electric current", "", true); 047 public static final QuantityType LUMINOUS_INTENSITY = new QuantityType("luminous intensity", "", true); 048 public static final QuantityType BIOLOGICAL_POTENCY = new QuantityType("biological potency", "", true); 049 050 // Derived quantities 051 public static final QuantityType FREQUENCY = new QuantityType("frequency", ""); 052 public static final QuantityType ENERGY = new QuantityType("energy", ""); 053 public static final QuantityType FORCE = new QuantityType("force", ""); 054 public static final QuantityType PRESSURE = new QuantityType("pressure", ""); 055 public static final QuantityType POWER = new QuantityType("power", ""); 056 public static final QuantityType ELECTRIC_CHARGE = new QuantityType("electric charge", ""); 057 public static final QuantityType ELECTRIC_POTENTIAL_DIFFERENCE = new QuantityType("electric potential difference", ""); 058 public static final QuantityType CATALYTIC_ACTIVITY = new QuantityType("catalytic activity", ""); 059 060 public static final QuantityType AREA = new QuantityType("area", ""); 061 public static final QuantityType VOLUME = new QuantityType("volume", ""); 062 public static final QuantityType DENSITY = new QuantityType("density", ""); 063 public static final QuantityType ABSORBANCE = new QuantityType("absorbance", ""); 064 public static final QuantityType CONCENTRATION = new QuantityType("concentration", ""); 065 066 //--------------------------------------------------------------------------- 067 protected QuantityType(String inName, String inAbbrev) 068 { 069 mName = inName; 070 mAbbrev = inAbbrev; 071 } 072 073 //--------------------------------------------------------------------------- 074 protected QuantityType(String inName, String inAbbrev, boolean isBase) 075 { 076 this(inName, inAbbrev); 077 mIsBase = isBase; 078 } 079 080 //--------------------------------------------------------------------------- 081 @Override 082 public boolean equals(Object inObj2) 083 { 084 return (inObj2 != null 085 && inObj2 instanceof QuantityType 086 && 0 == compareTo(inObj2)); 087 } 088 089 //--------------------------------------------------------------------------- 090 @Override 091 public int hashCode() 092 { 093 int hashCode = name().hashCode(); 094 095 return hashCode; 096 } 097 098 //--------------------------------------------------------------------------- 099 public int compareTo(Object inObj2) 100 { 101 int result = -1; 102 if (inObj2 != null) 103 { 104 if (inObj2 instanceof QuantityType) 105 { 106 QuantityType type2 = (QuantityType) inObj2; 107 108 result = CompareUtil.compare(name(), type2.name()); 109 } 110 } 111 112 return result; 113 } 114 115 //--------------------------------------------------------------------------- 116 @Override 117 public String toString() 118 { 119 return name(); 120 } 121 122 //--------------------------------------------------------------------------- 123 public String name() 124 { 125 return mName; 126 } 127 128 //--------------------------------------------------------------------------- 129 public boolean isBaseQuantity() 130 { 131 return mIsBase; 132 } 133}