001/* 002 * ============================================================================ 003 * Copyright © 2002-2023 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.internal; 019 020import static org.apiguardian.api.API.Status.STABLE; 021import static org.tquadrat.foundation.i18n.I18nUtil.loadResourceBundle; 022import static org.tquadrat.foundation.i18n.I18nUtil.retrieveText; 023import static org.tquadrat.foundation.lang.CommonConstants.EMPTY_STRING; 024import static org.tquadrat.foundation.value.api.DimensionedValue.MATH_CONTEXT; 025 026import java.math.BigDecimal; 027import java.util.MissingResourceException; 028import java.util.ResourceBundle; 029 030import org.apiguardian.api.API; 031import org.tquadrat.foundation.annotation.ClassVersion; 032import org.tquadrat.foundation.annotation.UtilityClass; 033import org.tquadrat.foundation.exception.PrivateConstructorForStaticClassCalledError; 034import org.tquadrat.foundation.i18n.BaseBundleName; 035 036/** 037 * Internal utilities for the value module. 038 * 039 * @version $Id: Tools.java 1072 2023-09-30 20:44:38Z tquadrat $ 040 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 041 * @UMLGraph.link 042 * @since 0.1.0 043 */ 044@SuppressWarnings( "NewClassNamingConvention" ) 045@UtilityClass 046@ClassVersion( sourceVersion = "$Id: Tools.java 1072 2023-09-30 20:44:38Z tquadrat $" ) 047@API( status = STABLE, since = "0.1.0" ) 048public final class Tools 049{ 050 /*---------------*\ 051 ====** Inner Classes **==================================================== 052 \*---------------*/ 053 054 /*-----------*\ 055 ====** Constants **======================================================== 056 \*-----------*/ 057 /** 058 * The base class for the resource bundle. 059 */ 060 @BaseBundleName 061 public static final String BASE_BUNDLE_NAME = "org.tquadrat.foundation.value.Texts"; 062 063 /** 064 * {@summary 1/3} 065 */ 066 public static final BigDecimal V1t3 = BigDecimal.ONE.divide( new BigDecimal( 3 ), MATH_CONTEXT ); 067 068 /** 069 * {@summary 5/9} 070 */ 071 public static final BigDecimal V5t9 = new BigDecimal( 5 ).divide( new BigDecimal( 9 ), MATH_CONTEXT ); 072 073 /** 074 * {@summary 0.525} 075 */ 076 public static final BigDecimal V0t525 = new BigDecimal( "0.525" ); 077 078 /** 079 * {@summary 0.8} 080 */ 081 public static final BigDecimal V0p8 = new BigDecimal( "0.8" ); 082 083 /** 084 * {@summary 1.5} 085 */ 086 public static final BigDecimal V1p5 = new BigDecimal( "1.5" ); 087 088 /** 089 * {@summary 7.5} 090 */ 091 public static final BigDecimal V7p5 = new BigDecimal( "7.5" ); 092 093 /** 094 * {@summary 32} 095 */ 096 public static final BigDecimal V32 = new BigDecimal( 32 ); 097 098 /** 099 * {@summary 100} 100 */ 101 public static final BigDecimal V100 = new BigDecimal( 100 ); 102 103 /** 104 * {@summary 273.15} 105 */ 106 public static final BigDecimal V273 = new BigDecimal( "273.15" ); 107 108 /*------------*\ 109 ====** Attributes **======================================================= 110 \*------------*/ 111 112 /*------------------------*\ 113 ====** Static Initialisations **=========================================== 114 \*------------------------*/ 115 /** 116 * The resource bundle for this module. 117 */ 118 private static final ResourceBundle m_ResourceBundle; 119 120 static 121 { 122 final var module = Tools.class.getModule(); 123 try 124 { 125 m_ResourceBundle = loadResourceBundle( BASE_BUNDLE_NAME, module ) 126 .orElseThrow( () -> new MissingResourceException( "Cannot find ResourceBundle", BASE_BUNDLE_NAME, EMPTY_STRING ) ); 127 } 128 catch( final MissingResourceException e ) 129 { 130 throw new ExceptionInInitializerError( e ); 131 } 132 } 133 134 /*--------------*\ 135 ====** Constructors **===================================================== 136 \*--------------*/ 137 /** 138 * No instance allowed for this class. 139 */ 140 private Tools() { throw new PrivateConstructorForStaticClassCalledError( Tools.class ); } 141 142 /*---------*\ 143 ====** Methods **========================================================== 144 \*---------*/ 145 /** 146 * Returns the translation for the given enum name. 147 * 148 * @param <E> The type of the enum. 149 * @param value The enum value. 150 * @return The translation. 151 */ 152 public static final <E extends Enum<?>> String retrieveName( final E value ) 153 { 154 final var retValue = retrieveText( m_ResourceBundle, value ); 155 156 //---* Done *---------------------------------------------------------- 157 return retValue; 158 } // retrieveName() 159} 160// class Tools 161 162/* 163 * End of File 164 */