Movatterモバイル変換


[0]ホーム

URL:


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

Commit84bda82

Browse files
committed
Add config helper
1 parent1bec275 commit84bda82

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allprojects {
2121

2222
// Using Jitpack so I need the repo name in the group to match.
2323
group='com.stubbornjava.StubbornJava'
24-
version='0.1.27-SNAPSHOT'
24+
version='0.1.28-SNAPSHOT'
2525

2626
repositories {
2727
mavenLocal()

‎stubbornjava-common/src/main/java/com/stubbornjava/common/Configs.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
importjava.io.File;
44
importjava.util.Map;
5+
importjava.util.function.Function;
6+
importjava.util.function.Supplier;
57

68
importorg.jooq.lambda.Seq;
79
importorg.slf4j.Logger;
@@ -43,6 +45,20 @@ public static Map<String, Object> asMap(Config config) {
4345
.toMap(e ->e.getKey(),e ->e.getValue().unwrapped());
4446
}
4547

48+
public <T>TgetOrDefault(Configconfig,Stringpath,Function<Config,T>extractor,TdefaultValue) {
49+
if (config.hasPath(path)) {
50+
returnextractor.apply(config);
51+
}
52+
returndefaultValue;
53+
}
54+
55+
public <T>TgetOrDefault(Configconfig,Stringpath,Function<Config,T>extractor,Supplier<T>defaultSupplier) {
56+
if (config.hasPath(path)) {
57+
returnextractor.apply(config);
58+
}
59+
returndefaultSupplier.get();
60+
}
61+
4662
publicstaticclassBuilder {
4763
privateConfigconf;
4864

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp