A simple collection of Java utilities for managing configurations, MongoDB connections, and Redis operations.
- Configuration Management
- MongoDB Integration
- Redis Integration
- Building the Project
- Contributing
- Coding Style
The library provides a flexible way to define and access configuration keys from various sources (currently supporting YAML).
ConfigRegistry registry = new ConfigRegistry();
// Required key (throws exception if missing and no default)
ConfigKey<String> MONGO_URI = registry.add("mongo.uri", String.class);
// Key with a default value (optional)
ConfigKey<Integer> REDIS_PORT = registry.add("redis.port", 6379, Integer.class);File configFile = new File("config.yml");
IConfigSource source = YamlUtil.load(configFile);
// Validate that all required keys are present
registry.validate(source);
// Retrieve values
String uri = registry.get(source, MONGO_URI);
int port = registry.getOrDefault(source, REDIS_PORT, 6379);Uses a singleton pattern for easy access and includes a fallback mechanism for local development.
// Load from file (automatically uses MongoConfig keys)
MongoConfig.load(new File("config.yml"));
// Access database
MongoDatabase db = Mongo.INSTANCE.getDatabase();If local.environment is set to true and the connection fails, it will use a fallback (where applicable).
Supports Pub/Sub, ZSETs (leaderboards), and Hashes with prefix wrapping.
// Load from file
RedisConfig.load(new File("config.yml"));
// Check connection
if (Redis.INSTANCE.isConnected()) {
// ...
}// Pub/Sub
Redis.INSTANCE.subscribe("my-channel", (channel, message) -> {
System.out.println("Received: " + message);
});
Redis.INSTANCE.publish("my-channel","Hello!");
// Leaderboards (ZSET)
Redis.INSTANCE.zaddOne("kills", 100, "player-uuid");
List<String> topPlayers = Redis.INSTANCE.zrangeAll("kills");- Java: Java 21 or higher.
- Gradle: The project uses the Gradle wrapper (
./gradlew), so no local installation is strictly required.
To build the project and generate the JAR files:
./gradlew buildThe resulting JAR files (including the shadow/fat JAR) will be located in build/libs/.
Contributions are welcome! If you have any improvements, bug fixes, or new features to suggest, feel free to open a Pull Request. We appreciate any help in making this project better.
Before submitting a Pull Request, please ensure that:
- Your code follows the Coding Style.
- All tests pass:
./gradlew test. - Checkstyle passes:
./gradlew checkstyleMain.
This project follows a strict coding style for robustness and clarity:
- Checkstyle: The project uses Checkstyle to enforce consistent code formatting. You can run the check locally
using
./gradlew checkstyleMain. The configuration can be found inconfig/checkstyle/checkstyle.xml. - Annotations: Every method parameter, return type, and field is annotated with
@NotNullor@Nullablefrom JetBrains annotations. - Validation: All
@NotNullparameters are validated usingObjects.requireNonNull(param, "message")at the beginning of the method.