Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fbbzl/erwin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

86 Commits

Repository files navigation

Java 21 Version 1.2.15 License

erwin

A lightweight and practical Java utility library
Focused on exception guards, null-safe access, Lambda adapters, reflection helpers, and Stream forking

中文


Module Matrix

erwin
├── exception : Conditional exception guards, message formatting, and MessageSource fallback
├── lang : Null-safe access, variable validation, and generic type resolution
├── lambda : Checked-exception Lambda adapters and LambdaMetafactory helpers
└── stream : Fork one Stream into multiple result pipelines

60-Second Setup

<dependency>
 <groupId>io.github.fbbzl</groupId>
 <artifactId>erwin</artifactId>
 <version>1.2.15</version>
</dependency>

Requires Java 21 or later.

mvn test
mvn package

Core Powers

Conditional Guards

Throws provides condition-based exception throwing, while Vars adds a require-style validation layer on top of it.

import org.fz.erwin.exception.Throws;
import org.fz.erwin.lang.Vars;
Vars.requireNotBlank(username);
Vars.requireNotEmpty(userList);
Throws.ifTrue(pageSize > 100, "page size must be <= {}", 100);
Throws.ifEmpty(userList, "user list can not be empty");

Null-Safe Access

NullSafe wraps a potentially null access chain in a Lambda. It is handy for simple read paths where nested null checks would be noisy.

import org.fz.erwin.lang.NullSafe;
Integer length = NullSafe.nullDefault(
 () -> user.getProfile().getName().length(),
 0
);

Checked Exception Lambda Adapters

Try adapts functions that throw checked exceptions into standard JDK functional interfaces, wrapping failures as runtime exceptions.

import org.fz.erwin.lambda.Try;
List<String> contents = paths.stream()
 .map(Try.apply(Files::readString))
 .toList();

Lambda Metadata and Reflection Helpers

LambdaMetas uses LambdaMetafactory to create functional entry points for constructors, getters, and setters.

import org.fz.erwin.lambda.LambdaMetas;
Supplier<User> constructor = LambdaMetas.lambdaConstructor(User.class);
Function<User, String> getter = LambdaMetas.lambdaGetter(User.class, String.class, "getName");
BiConsumer<User, String> setter = LambdaMetas.lambdaSetter(User.class, String.class, "setName");

Stream Forking

StreamForks lets multiple Stream pipelines consume the same source data and collect different results from a single entry point.

import org.fz.erwin.stream.StreamForks;
StreamForks.ForkResult result = StreamForks.of(List.of(1, 2, 3, 4))
 .fork("sum", stream -> stream.mapToInt(Integer::intValue).sum())
 .fork("even", stream -> stream.filter(i -> i % 2 == 0).toList())
 .done();
Integer sum = result.get("sum");
List<Integer> even = result.get("even");

Tech Stack

Technology Version
Java 21
Lombok 1.18.46
Hutool 5.8.44
Apache Commons Lang 3.20.0
Apache Commons Collections 4.5.0
Apache Commons IO 2.22.0
Apache Commons Codec 1.22.0
Apache Commons Text 1.15.0
Guava 33.6.0-jre
Failsafe 3.3.2
Spring Context 6.2.7 provided

License

Apache License 2.0

Made with love by fengbinbin

About

a java util

Resources

Stars

Watchers

Forks

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /