Skip to content

MiscUtils

Aram edited this page Nov 1, 2024 · 1 revision

MiscUtils

Overview

The MiscUtils class in the software.bluelib.utils.math package provides utility methods for various common operations. This utility class includes methods for validating email addresses, converting strings to integers with default values, calculating Levenshtein distance, and converting hexadecimal color codes to RGB values.

Key Methods

  1. isValidEmail(String)
    Checks if a string is a valid email address.

    boolean isValid = MiscUtils.isValidEmail("[email protected]");
  2. stringToIntWithDefault(String, int)
    Converts a string to an integer, returning a default value if the string is not a valid integer.

    int result = MiscUtils.stringToIntWithDefault("123", 0);
  3. calculateLevenshteinDistance(String, String)
    Calculates the Levenshtein distance between two strings.

    int distance = MiscUtils.calculateLevenshteinDistance("kitten", "sitting");
  4. hexToRGB(String)
    Converts a hexadecimal color code to an RGB array.

    int[] rgb = MiscUtils.hexToRGB("#FFFFFF");

Usage Notes

  • Error Handling: If an input is invalid (e.g., an invalid hex color code), the method throws an appropriate exception and logs an error message.
  • Utility Design: This class cannot be instantiated, as it contains a private constructor and only static methods.

By using MiscUtils, you can streamline common operations and improve the consistency of your utility methods across your mod.