-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Gmugra/26_API_Loading_strategies_2
#26 : API: Loading strategies, refactoring
- Loading branch information
Showing
4 changed files
with
67 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/main/java/net/cactusthorn/config/core/loader/LoadStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.cactusthorn.config.core.loader; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public enum LoadStrategy { | ||
// @formatter:off | ||
FIRST(l -> l.stream().filter(m -> !m.isEmpty()).findFirst().orElse(Collections.emptyMap())), | ||
MERGE(l -> { | ||
Map<String, String> result = new HashMap<>(); | ||
for (int i = l.size() - 1; i >= 0; i--) { | ||
result.putAll(l.get(i)); | ||
} | ||
return result; | ||
}); | ||
// @formatter:on | ||
|
||
private Function<List<Map<String, String>>, Map<String, String>> strategy; | ||
|
||
LoadStrategy(Function<List<Map<String, String>>, Map<String, String>> strategy) { | ||
this.strategy = strategy; | ||
} | ||
|
||
public Map<String, String> combine(List<Map<String, String>> properties) { | ||
return strategy.apply(properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters