001/* 002 * ============================================================================ 003 * Copyright © 2002-2026 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * Licensed to the public under the agreements of the GNU Lesser General Public 007 * License, version 3.0 (the "License"). You may obtain a copy of the License at 008 * 009 * http://www.gnu.org/licenses/lgpl.html 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package org.tquadrat.foundation.value; 019 020import org.apiguardian.api.API; 021import org.tquadrat.foundation.annotation.ClassVersion; 022import org.tquadrat.foundation.lang.value.DimensionWithLinearConversion; 023 024import java.math.BigDecimal; 025 026import static java.lang.String.format; 027import static java.util.Arrays.stream; 028import static org.apiguardian.api.API.Status.STABLE; 029import static org.tquadrat.foundation.lang.Objects.requireNotEmptyArgument; 030 031/** 032 * The various instances of energy … 033 * 034 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 035 * @version $Id: Energy.java 1195 2026-04-15 21:33:40Z tquadrat $ 036 * @since 0.3.0 037 * 038 * @UMLGraph.link 039 */ 040@SuppressWarnings( "NewClassNamingConvention" ) 041@ClassVersion( sourceVersion = "$Id: Energy.java 1195 2026-04-15 21:33:40Z tquadrat $" ) 042@API( status = STABLE, since = "0.3.0" ) 043public enum Energy implements DimensionWithLinearConversion 044{ 045 /*------------------*\ 046 ====** Enum Declaration **================================================= 047 \*------------------*/ 048 /** 049 * An electron volt. 050 */ 051 ELECTRONVOLT( new BigDecimal( "1.602176634E-19"), "eV" ), 052 053 /** 054 * An erg. 055 */ 056 ERG( new BigDecimal( "1E-7"), "erg" ), 057 058 /** 059 * A Joule. 060 */ 061 JOULE( BigDecimal.ONE, "J", 1 ), 062 063 /** 064 * A calorie. 065 */ 066 CALORIE( new BigDecimal( "4.1868" ), "cal" ), 067 068 /** 069 * A kilo Joule. 070 */ 071 KILOJOULE( new BigDecimal( "1000" ), "kJ", 1 ), 072 073 /** 074 * A British Thermal Unit (BTU). 075 */ 076 BTU( new BigDecimal( "1055.05585262" ), "BTU" ), 077 078 /** 079 * A kilo calorie. 080 */ 081 KILOCALORIE( new BigDecimal( "4186.8" ), "kcal" ), 082 083 /** 084 * A kilopond meter. 085 */ 086 KILOPONDMETER( new BigDecimal( "9.80665" ), "kpm" ), 087 088 /** 089 * A Mega Joule. 090 */ 091 MEGAJOULE( new BigDecimal( "1E+6" ), "MJ" ), 092 093 /** 094 * A kilo Watt per hour. 095 */ 096 KILOWATT_HOUR( new BigDecimal( "3.6E+6" ), "kWh" ), 097 098 /** 099 * <p>{@summary The energy equivalent of one kg TNT}. This is usually used 100 * to rate the power of (nuclear) bombs or other explosives.</p> 101 */ 102 KILOGRAM_TNT( new BigDecimal( "4.184E+6" ), "kg(TNT)" ), 103 104 /** 105 * A Giga Joule. 106 */ 107 GIGAJOULE( new BigDecimal( "1E+9" ), "GJ" ), 108 109 /** 110 * A Mega Joule. 111 */ 112 TERAJOULE( new BigDecimal( "1E+12" ), "TJ" ), 113 114 /** 115 * <p>{@summary The energy equivalent of one thousand tons of TNT}. This 116 * is usually used to rate the power of (nuclear) bombs or other 117 * explosives.</p> 118 */ 119 KILOTON_TNT( new BigDecimal( "4.184E+12" ), "kT(TNT)" ), 120 121 /** 122 * <p>{@summary The energy equivalent of one million tons of TNT}. This is 123 * usually used to rate the power of (nuclear) bombs or other 124 * explosives.</p> 125 */ 126 MEGATON_TNT( new BigDecimal( "4.184E+15" ), "MT(TNT)" ), 127 128 /** 129 * A quad. 130 */ 131 QUAD( new BigDecimal( "1055.05585262E+15" ), "quad" ), 132 133 /** 134 * <p>{@summary A foe (or a 'bethe').}</p> 135 * <p>A {@code foe} is used to express the large amount of energy released 136 * by a supernova. An acronym for "[ten to the power of] fifty-one 137 * ergs", the term was introduced by Gerald E. Brown of Stony Brook 138 * University in his work with Hans Bethe, because <cite>"it came up 139 * often enough in our work"</cite>.</p> 140 * <p>Without mentioning the foe, Steven Weinberg proposed in 2006 "a 141 * new unit called the bethe ({@code B})" with the same value, to 142 * "<i>replace</i>" it.</p> 143 * <p>This unit of measure is convenient because a supernova typically 144 * releases about one {@code foe} of observable energy in a very short 145 * period (which can be measured in seconds).</p> 146 */ 147 FOE( new BigDecimal( "1E+44" ), "foe" ), 148 149 /** 150 * <p>{@summary A bethe.}</p> 151 * <p>This is the same as 152 * {@link #FOE foe}.</p> 153 */ 154 BETHE( new BigDecimal( "1E+44" ), "B" ); 155 156 /*------------*\ 157 ====** Attributes **======================================================= 158 \*------------*/ 159 /** 160 * The factor. 161 */ 162 private final BigDecimal m_Factor; 163 164 /** 165 * The default precision. 166 */ 167 private final int m_Precision; 168 169 /** 170 * The unit string. 171 */ 172 private final String m_UnitSymbol; 173 174 /*--------------*\ 175 ====** Constructors **===================================================== 176 \*--------------*/ 177 /** 178 * Creates a new {@code Length} instance, with a default precision of zero 179 * mantissa digits. 180 * 181 * @param factor The factor. 182 * @param unitSymbol The unit symbol String. 183 */ 184 private Energy( final BigDecimal factor, final String unitSymbol ) 185 { 186 this( factor, unitSymbol, 0 ); 187 } // Energy() 188 189 /** 190 * Creates a new {@code Length} instance. 191 * 192 * @param factor The factor. 193 * @param unitSymbol The unit symbol String. 194 * @param precision The default precision. 195 */ 196 private Energy( final BigDecimal factor, final String unitSymbol, final int precision ) 197 { 198 m_Factor = factor.stripTrailingZeros(); 199 m_UnitSymbol = unitSymbol; 200 m_Precision = precision; 201 } // Energy() 202 203 /*---------*\ 204 ====** Methods **========================================================== 205 \*---------*/ 206 /** 207 * {@inheritDoc} 208 */ 209 @Override 210 @SuppressWarnings( "unchecked" ) 211 public final Energy baseUnit() { return JOULE; } 212 213 /** 214 * {@inheritDoc} 215 */ 216 @Override 217 public final BigDecimal factor() { return m_Factor; } 218 219 /** 220 * Returns the {@code Energy} instance for the given unit symbol. 221 * 222 * @param unitSymbol The unit symbol. 223 * @return The respective instance. 224 * @throws IllegalArgumentException The given unit is unknown. 225 */ 226 public static final Energy forUnit( final String unitSymbol ) throws IllegalArgumentException 227 { 228 requireNotEmptyArgument( unitSymbol, "unitSymbol" ); 229 230 final var retValue = stream( values() ) 231 .filter( v -> v.unitSymbol().equals( unitSymbol ) ) 232 .findFirst() 233 .orElseThrow( () -> new IllegalArgumentException( format( MSG_UnknownUnit, unitSymbol ) ) ); 234 235 //---* Done *---------------------------------------------------------- 236 return retValue; 237 } // forUnit() 238 239 /** 240 * {@inheritDoc} 241 */ 242 @Override 243 public final int getPrecision() { return m_Precision; } 244 245 /** 246 * {@inheritDoc} 247 */ 248 @Override 249 public final String unitSymbol() { return m_UnitSymbol; } 250} 251// enum Energy 252 253/* 254 * End of File 255 */