Skip to content

MathConverterUtils

Aram edited this page Jan 9, 2025 · 2 revisions

MathConverterUtils

Overview

The MathConverterUtils class in the software.bluelib.utils.conversion package provides a set of methods for converting common units and handling date formats. This utility supports conversions such as inches to centimeters, Celsius to Fahrenheit, and string to date, enabling ease of use when working with measurements and date representations.

Key Methods

  1. inchesToCentimeters(double)
    Converts a given length from inches to centimeters.

    double centimeters = MathConverterUtils.inchesToCentimeters(5.0);
  2. centimetersToInches(double)
    Converts a given length from centimeters to inches.

    double inches = MathConverterUtils.centimetersToInches(12.7);
  3. celsiusToFahrenheit(double)
    Converts a temperature from Celsius to Fahrenheit.

    double fahrenheit = MathConverterUtils.celsiusToFahrenheit(25.0);
  4. fahrenheitToCelsius(double)
    Converts a temperature from Fahrenheit to Celsius.

    double celsius = MathConverterUtils.fahrenheitToCelsius(77.0);
  5. kilometersToMiles(double)
    Converts a distance from kilometers to miles.

    double miles = MathConverterUtils.kilometersToMiles(10.0);
  6. milesToKilometers(double)
    Converts a distance from miles to kilometers.

    double kilometers = MathConverterUtils.milesToKilometers(6.2);
  7. stringToDate(String, String)
    Converts a date in string format to a Date object based on a specified format.

    Date date = MathConverterUtils.stringToDate("2023-10-30", "yyyy-MM-dd");
  8. dateToString(Date, String)
    Converts a Date object to a string format based on a specified pattern.

    String dateStr = MathConverterUtils.dateToString(date, "yyyy-MM-dd");

Usage Notes

  • Error Handling: Conversion errors are logged with BaseLogger at the ERROR level. For instance, if a date string cannot be parsed, an error log is generated.
  • Utility Design: This class cannot be instantiated, as it contains a private constructor and only static methods.