The Equinox Essentials project is a robust utility library designed to simplify common programming tasks. It consists of well-structured classes that provide a wide range of functionality, from data conversions and random data generation to JSON handling, security, and more. Below is an overview of the key components in this library.
A versatile class for handling data conversions:
- String-to-Primitive Conversions:
- Convert strings to
int,double, andbooleanwith validation.
- Convert strings to
- JSON Handling:
- Serialize objects to JSON or deserialize JSON into objects.
- Unit Conversions:
- Perform conversions for temperature, length, and weight (e.g., Celsius to Fahrenheit, meters to feet, etc.).
Efficient and reliable random data generation:
- generateRandomString:
- Generate random alphanumeric strings of a specified length.
Streamlined JSON file I/O operations:
- readJson:
- Load and deserialize JSON data from a file.
- writeJson:
- Serialize and save an object to a JSON file.
A comprehensive solution for encryption and security evaluation:
- String Encryption:
- Offers several security levels:
HASH,SALTED_HASH,SHIFTED_HASH,FULLY_ENCRYPTED.
- Provides cryptographic hashing (SHA-256), salting, shifting, and repeated hashing for enhanced security.
- Offers several security levels:
- Password Security Check:
- Analyze and classify password strength as
NONE,LOW,MEDIUM, orHIGHbased on length and character diversity.
- Analyze and classify password strength as
- Extensibility: Designed for easy integration and scalability across projects.
- Efficiency: Optimized for performance while ensuring simplicity in use.
- Reliability: Built-in validation and exception handling to prevent common errors.
- Versatility: A collection of tools that caters to a wide variety of use cases.
Equinox Essentials is a one-stop utility library for Java developers. It eliminates the need for repetitive boilerplate code, improves development efficiency, and ensures adherence to modern programming practices. Whether you're working on data formatting, security, or random data generation, this library has you covered.
- Add the package to your project (details depend on your build system, e.g., Maven, Gradle).
- Import the Essentials class.
- Start utilizing the utilities without additional setup!
Example:
boolean isEmail = Essentials.checker.isValidEmail(email);- Java: Primary programming language (SDK version 21+).
- Gson: For JSON serialization/deserialization.
- Java Security: For encryption and hashing functionality.
Feel free to contact AnotherCastaway for anything.
The Checker class is part of the com.equinox.equinox_essentials.source package. It provides utility methods to validate common data formats, such as email addresses and numeric strings.
Checks if the provided string is a valid email address.
- email: A
Stringrepresenting the email address to be validated.
boolean:trueif the email address is valid.falseotherwise.
java boolean isValid = Checker.isValidEmail("example@email.com"); System.out.println(isValid); // Output: true
Checks if the provided string is a valid representation of a number.
- input: A
Stringrepresenting the input to be validated.
boolean:trueif the input is a valid number.falseotherwise.
java boolean isValidNumber = Checker.isNumber("123.45"); System.out.println(isValidNumber); // Output: true
java public class Main { public static void main(String[] args) { String email = "test@domain.com"; if (Checker.isValidEmail(email)) { System.out.println("Valid email address"); } else { System.out.println("Invalid email address"); } } }
java public class Main { public static void main(String[] args) { String input = "42.0"; if (Checker.isNumber(input)) { System.out.println("The input is a number."); } else { System.out.println("The input is not a number."); } } }
- For
isValidEmail, the method uses a regular expression to match the general format of email addresses. - For
isNumber, the method attempts to parse the input string into aDoubleand catches anyNumberFormatException.
The Constants class is part of the com.equinox.equinox_essentials.source package. It provides a collection of globally accessible constants that can be used across the application. These constants include common values, regular expression patterns, and ANSI escape codes for colors and formatting.
The Constants class acts as a central repository for commonly used values to promote reuse, maintain consistency, and prevent duplication across the codebase.
GOLDEN_RATIO: Represents the mathematical golden ratio (approximately 1.618).
- Predefined values for timekeeping and durations:
SECONDS_IN_MINUTE: Number of seconds in a minute (60).MINUTES_IN_HOUR: Number of minutes in an hour (60).HOURS_IN_DAY: Number of hours in a day (24).DAYS_IN_WEEK: Number of days in a week (7).MONTHS_IN_YEAR: Number of months in a year (12).
These patterns can be used for validating common data formats:
EMAIL_PATTERN: Validates email addresses.PASSWORD_PATTERN: Ensures passwords meet complexity requirements, including:- At least one uppercase letter.
- At least one lowercase letter.
- At least one digit.
- At least one special character.
- No whitespace characters.
- Minimum length requirement (8 characters).
URL_PATTERN: Validates URLs withhttp,https,ftp, orfileprotocols.
Color and formatting codes designed for console output:
-
Text colors:
ANSI_RED,ANSI_GREEN,ANSI_YELLOW,ANSI_BLUE,ANSI_CYAN,ANSI_PURPLE,ANSI_WHITE,ANSI_BLACK- Example: Use
ANSI_REDto display text in red.
-
Styles and formatting:
ANSI_BOLD,ANSI_ITALIC,ANSI_UNDERLINE,ANSI_BLINK- Example: Use
ANSI_BOLDfor bold text rendering.
-
ANSI_RESET: Resets all formatting to the console's default.
The Math class is part of the com.equinox.equinox_essentials.source package. It provides a set of general-purpose mathematical utilities, including calculations for clamping numbers, averages, prime checks, factorials, and more.
The Math class offers reusable mathematical methods for common operations that are not directly provided by the Java Math library or that bundle frequently needed logic.
Clamps a number between two bounds.
- Parameters:
x: The lower bound.y: The upper bound.input: The number to be clamped.
- Returns: The clamped value.
- Example:
double clampedValue = Math.clampNum(0, 10, 15); // Output: 10
Calculates the average of an array of numbers.
- Parameters:
numbers: A non-empty array ofdoublevalues.
- Returns: The average value of the array.
- Throws:
IllegalArgumentExceptionif the array is null or empty.
- Example:
double avg = Math.average(new double[]{1, 2, 3}); // Output: 2.0
Checks if a number is a prime number.
- Parameters:
number: An integer to be checked.
- Returns:
trueif the number is prime,falseotherwise. - Example:
boolean isPrime = Math.isPrime(7); // Output: true
Calculates the factorial of a non-negative integer.
- Parameters:
n: A non-negative integer.
- Returns: The factorial of
n. - Throws:
IllegalArgumentExceptionifnis negative.
- Example:
long fact = Math.factorial(5); // Output: 120
Finds the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
- Parameters:
aandb: The integers for which to find the GCD.
- Returns: The greatest common divisor.
- Example:
int gcdValue = Math.gcd(24, 18); // Output: 6
Finds the least common multiple (LCM) of two integers.
- Parameters:
aandb: The integers for which to find the LCM.
- Returns: The least common multiple.
- Example:
int lcmValue = Math.lcm(4, 6); // Output: 12
Calculates the result of raising a base to an integer exponent.
- Parameters:
base: The base value.exponent: The power to which the base is raised. Can be negative.
- Returns:
baseraised to the power ofexponent. - Example:
double result = Math.power(2, 3); // Output: 8.0
The Logging class is part of the com.equinox.equinox_essentials.source package. It provides utility methods for logging messages to the console and creating/updating visual progress bars. This class is useful for adding styled console outputs and visual feedback for long-running processes.
The Logging class serves the following purposes:
- Provides methods to log messages categorized as
INFO,ERROR,WARNING, andVERBOSE, with formatted and stylized console output using ANSI escape codes. - Offers the ability to create and update progress bars for real-time feedback in terminal-based applications.
Initializes and displays a progress bar in the console.
title: AStringdefining the title to display alongside the progress bar.total: Anintspecifying the total number of steps for the progress bar.
- Throws
IllegalArgumentExceptioniftotalis less than or equal to0. - Displays a progress bar set to
0%.
Updates the progress bar to reflect the current progress.
current: Anintrepresenting the current progress.total: Anintrepresenting the total number of steps for the progress bar.
- Throws
IllegalArgumentExceptionifcurrentis less than0,totalis less than or equal to0, orcurrentexceedstotal. - Dynamically adjusts the progress bar to represent the current percentage completion.
Logs a general informational message to the console.
string: AStringrepresenting the message to be logged.
Logs an error message to the console with red-colored formatting.
string: AStringrepresenting the error message to be logged.
Logs a warning message to the console with yellow-colored formatting.
string: AStringrepresenting the warning message to be logged.
Logs a verbose message to the console if verbosity is enabled.
string: AStringrepresenting the log message.isVerbose: Abooleanthat determines whether the verbose message should be displayed.
- Progress bars dynamically display progress using a combination of
█for completed progress and░for the remaining portion. - Logs are styled using ANSI escape codes:
- Messages such as
ERROR,WARNING, andINFOare given unique colors to distinguish their severity or type.
- Messages such as
- Verbose logs can be conditionally enabled or disabled through the
isVerboseparameter, making them ideal for debugging purposes. - The methods in this class ensure console output remains clear, consistent, and easy to interpret.
The Convert class is part of the com.equinox.equinox_essentials.source package. It provides utility methods for various data conversions, including string-to-primitive conversions, JSON serialization/deserialization, temperature, length, and weight conversions.
The Convert class centralizes common data transformation and conversion tasks, ensuring consistency, reuse, and reduced duplication across the codebase. It supports:
- String-to-primitive conversions (
int,double,boolean). - JSON-to-object and object-to-JSON transformations.
- Unit conversions for temperature, length, and weight.
Converts a String to an int.
- Removes all non-numeric characters before attempting conversion.
- Throws
IllegalArgumentExceptionfor null, empty, or invalid input.
Converts a String to a double.
- Throws
IllegalArgumentExceptionfor null, empty, or invalid input.
Converts a String to a boolean.
- Uses Java’s
Boolean.parseBooleanmethod, converting the string to lowercase before parsing.
Deserializes a JSON String into an object of the specified class type.
- Throws
IllegalArgumentExceptionfor malformed JSON or conversion issues.
Deserializes a JSON String into an object of the specified generic type.
- Useful for handling more complex types such as collections.
- Throws
IllegalArgumentExceptionfor malformed JSON or conversion issues.
Serializes an object into a JSON String.
Converts a temperature value from Celsius to Fahrenheit.
Converts a temperature value from Fahrenheit to Celsius.
Converts a temperature value from Celsius to Kelvin.
Converts a temperature value from Kelvin to Celsius.
Converts a length value from meters to feet.
Converts a length value from feet to meters.
Converts a weight value from kilograms to pounds.
Converts a weight value from pounds to kilograms.
- The string-to-primitive methods (
toInt,toDouble,toBoolean) ensure robust input validation and sanitize input before attempting conversions. - JSON serialization and deserialization methods internally utilize the Gson library for efficient and flexible handling of JSON data.
- Unit conversion methods adhere to standard conversion formulas to ensure high precision.
- The methods are lightweight, stateless, and reusable, making the class an ideal choice for static or utility-style usage.
The Generators class is part of the com.equinox.equinox_essentials.source package. It provides functionality for generating random values, such as random alphanumeric strings.
The Generators class is designed to simplify the creation of randomized data, which can be useful for various purposes such as test data generation, token creation, or random string generation.
Generates a random alphanumeric string of the specified length using a predefined character set.
length: Anintspecifying the length of the random string to generate. Must be non-negative.
- A randomly generated
Stringcomposed of characters from the predefined setABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.
- Throws
IllegalArgumentExceptionif the specifiedlengthis negative. - Uses an internal instance of
Randomfor randomness.
Generates a random full name composed of a first name and a last name.
isMale: Abooleanspecifying whether the generated first name should be male (true) or female (false).
- A
Stringcontaining the randomly generated full name.
- The first name is selected from a predefined list of male or female names based on the
isMaleparameter. - The last name is randomly selected from a predefined list of last names.
Generates a random first name.
isMale: Abooleanspecifying whether the first name should be male (true) or female (false).
- A randomly selected
Stringrepresenting a first name from the predefined name lists.
Generates a random last name.
- None.
- A randomly selected
Stringrepresenting a last name from the predefined last name list.
- The
generateRandomStringmethod is efficient and produces reliably random strings suitable for most applications. - The character set includes uppercase letters, lowercase letters, and digits, making it ideal for generating generic alphanumeric tokens, credentials, or identifiers.
- Ensure proper handling of exceptions if a negative length is passed.
The Getter class is part of the com.equinox.equinox_essentials.source package. It provides utility methods for reading and writing JSON data to and from files.
The Getter class simplifies file-based JSON operations, offering methods to read JSON data into Java objects and write Java objects to JSON files. It leverages the Gson library for serialization and deserialization.
Reads JSON data from a specified file and deserializes it into a generic Java object.
path: AStringspecifying the path to the JSON file.
- A generic
Objectcontaining the deserialized JSON data.
- Throws
RuntimeExceptionif anIOExceptionoccurs during file reading.
Writes a Java object to a specified file as serialized JSON.
path: AStringspecifying the path to write the JSON file to.data: AnObjectcontaining the data to serialize and write as JSON.
- Throws
RuntimeExceptionif anIOExceptionoccurs during file writing.
- The
readJsonmethod deserializes JSON data into a generic Java object. If a more specific type is required, consider additional type handling or wrapping this method. - The
writeJsonmethod serializes any Java object into JSON format, ensuring compatibility with Gson-supported types. - Proper error handling is embedded in the methods to surface issues related to file operations (e.g., file not found, insufficient permissions, etc.).
- The file streams are automatically managed using the try-with-resources syntax to ensure resources are closed properly.
The Security class is part of the com.equinox.equinox_essentials.source package. It provides functionality for encryption, hashing, and assessing password security levels.
The Security class is designed to handle operations related to securing sensitive data, primarily through hashing and encryption techniques, as well as evaluating the complexity of passwords. It supports different security levels for versatile use cases, from basic hashing to fully encrypted transformations.
Defines the available security levels for encryption:
HASH: Basic hashing without salt or additional processing.SALTED_HASH: Hashing with a randomly generated salt for added security.SHIFTED_HASH: Hashing with both salt and character shifting.FULLY_ENCRYPTED: Combines salt, shifting, and multiple hashing operations for maximum security.
Represents password security levels:
NONE: Password does not meet any security criteria.LOW: Password meets at least two criteria (e.g., uppercase/lowercase or digit/special character).MEDIUM: Password meets at least three criteria.HIGH: Password meets all criteria and is at least 12 characters long.
Encrypts a string based on the specified security level.
input: TheStringto be encrypted.securityLevel: A value from thesecurityLevelsenum specifying the desired encryption level.shift: Anintvalue used for character shifting (applicable forSHIFTED_HASHandFULLY_ENCRYPTEDlevels).
- A
String[]where:output[0]contains the resulting encrypted string.- Additional indices may include:
- Salt value (for
SALTED_HASH,SHIFTED_HASH, orFULLY_ENCRYPTED). - Other intermediate values depending on the security level.
- Salt value (for
- Generates a random salt (for applicable levels).
- Uses the SHA-256 hashing algorithm for cryptographic hashing.
- Applies character shifting (for applicable levels).
- Throws
RuntimeExceptionif the SHA-256 algorithm is unavailable.
Converts a byte array into a hexadecimal-encoded string.
hash: Abyte[]containing the hash to be converted.
- A
Stringrepresenting the hexadecimal value of the byte array.
Applies a character shift to each character in the input string.
input: TheStringto shift.shift: Anintvalue indicating how much to shift each character.
- A new
Stringwhere each character has been shifted by the specified amount.
Evaluates the security level of a given password.
password: TheStringpassword to be evaluated.
- A value from the
securityenum:NONE,LOW,MEDIUM, orHIGH, based on the password's complexity and length.
- Checks for:
- Presence of uppercase letters.
- Presence of lowercase letters.
- Presence of digits.
- Presence of special characters.
- Evaluates security based on length and criteria satisfaction (as outlined in the
securityenum).
-
Encryption Process:
- Handles varying levels of security through combinations of hashing, salting, shifting, and rehashing.
- SHA-256 is used as the primary hashing algorithm, ensuring strong cryptographic security.
-
Password Evaluation:
- The strength of a password is determined by a combination of its length and character diversity.
- Encourages users to create stronger passwords that meet higher security criteria.
-
Utility:
- The class is ideal for managing encryption and password security in applications requiring enhanced data protection.