A lightweight and practical Java utility library
Focused on exception guards, null-safe access, Lambda adapters, reflection helpers, and Stream forking
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
<dependency>
<groupId>io.github.fbbzl</groupId>
<artifactId>erwin</artifactId>
<version>1.2.15</version>
</dependency>Requires Java 21 or later.
mvn test
mvn packageThrows 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");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
);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();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");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");| 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 |
Made with love by fengbinbin