Skip to content

jojo8356/utools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

UTools

A collection of Java utility classes to eliminate everyday verbosity. Zero dependencies, Java 21+.

Modules

Module Description
UStr String manipulation: capitalize, case conversion, slugify, pad, between, count...
UConvert Type conversions with defaults, human-readable (bytes, millis), hex, base64
URand Simplified random: int, double, bool, string, pick, shuffle, sample, seed
USys Environment variables, sleep, timing, exec, system info
UIO User input, file read/write, filesystem operations
UHttp HTTP client wrapper: GET, POST, PUT, PATCH, DELETE, download
UJson Minimal JSON parser/builder with dot notation and pretty print
UTime Simplified time, multilingual relative time ("3 minutes ago"), timer with laps
UJsonDB JSON file as database: fluent CRUD, queries, SQL, JOIN, aggregates, indexes, transactions

Installation

<dependency>
    <groupId>dev.utools</groupId>
    <artifactId>utools</artifactId>
    <version>1.0.0</version>
</dependency>

Quick Examples

UStr

UStr.capitalize("hello");          // "Hello"
UStr.toSnakeCase("helloWorld");    // "hello_world"
UStr.slugify("Café au lait!");     // "cafe-au-lait"
UStr.between("<b>text</b>", "<b>", "</b>"); // "text"

UConvert

UConvert.toInt("42");              // 42
UConvert.toInt("abc");             // 0 (default)
UConvert.toBool("yes");           // true
UConvert.bytesToHuman(1536);       // "1.5 KB"

URand

URand.nextInt(1, 100);             // 42
URand.string(8);                   // "aB3xK9mZ"
URand.pick("red", "blue");         // "blue"
URand.uuid();                      // "a1b2c3d4"

USys

USys.env("HOME");                  // "/home/user"
USys.exec("ls", "-la");           // ExecResult(exitCode, stdout, stderr)
long ms = USys.time(() -> work()); // 150

UIO

String content = UIO.read("file.txt");
UIO.write("out.txt", "Hello!");
List<String> lines = UIO.readLines("data.csv");
boolean ok = UIO.confirm("Continue?");

UHttp

String body = UHttp.get("https://api.example.com/users");
String resp = UHttp.post("https://api.example.com/users", jsonBody);
UHttp.download("https://example.com/file.zip", "file.zip");

UJson

UJson json = UJson.parse("{\"name\":\"Alice\",\"age\":25}");
json.getString("name");            // "Alice"
json.getInt("age");                // 25

UJson obj = UJson.object()
    .put("name", "Bob")
    .put("scores", UJson.array().add(10).add(20));
obj.toPrettyString();

UTime

UTime.now();                       // LocalDateTime
UTime.ago(someDate);               // "il y a 3 minutes" (French default)
UTime.ago(someDate, Locale.ENGLISH); // "3 minutes ago"
UTime.between(d1, d2);            // "2 days, 3 hours and 15 minutes"

var timer = UTime.startTimer();
doWork();
timer.lap("step1");
timer.stop();
System.out.println(timer.report());

UJsonDB

// Open or create a database
var db = UJsonDB.open("data.json");

// CRUD
var users = db.collection("users");
users.insert(Map.of("name", "Alice", "age", 25));
users.find(q -> q.where("age").gte(18).orderBy("name"));

// SQL
db.sql("SELECT name, age FROM users WHERE age > 20 ORDER BY name");
db.sql("SELECT department, AVG(salary) AS avg_sal FROM employees GROUP BY department");
db.sql("SELECT u.name, p.title FROM users u JOIN posts p ON p.authorId = u._id");

// Transactions
db.transaction(tx -> {
    tx.collection("accounts").updateById(1, Map.of("balance", 900));
    tx.collection("accounts").updateById(2, Map.of("balance", 1100));
});

Supported Languages (UTime.ago)

French, English, Spanish, German, Italian, Portuguese

Build & Test

mvn test

235 tests.

License

MIT

About

Java utility collection: UStr, UConvert, URand, USys, UIO, UHttp, UJson, UTime, UJsonDB. Zero dependencies, Java 21+.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages