-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from JavaWebStack/dev
Release 1.0.1
- Loading branch information
Showing
12 changed files
with
164 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
target | ||
dependency-reduced-pom.xml | ||
.idea | ||
*.iml | ||
*.iml | ||
.env |
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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/org/javawebstack/webutils/config/EnvAssocMapping.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,28 @@ | ||
package org.javawebstack.webutils.config; | ||
|
||
import java.util.Locale; | ||
import java.util.function.Function; | ||
|
||
public class EnvAssocMapping implements Function<String, String> { | ||
|
||
private final String prefix; | ||
private final Function<String, String> subMapping; | ||
|
||
public EnvAssocMapping(String prefix, Function<String, String> subMapping) { | ||
this.prefix = prefix; | ||
this.subMapping = subMapping; | ||
} | ||
|
||
public String apply(String s) { | ||
if(!s.startsWith(prefix+ "_")) | ||
return null; | ||
String[] spl = s.substring(prefix.length() + 1).split("_", 2); | ||
if(spl.length != 2) | ||
return null; | ||
String sk = subMapping.apply(spl[1]); | ||
if(sk == null) | ||
return null; | ||
return prefix.toLowerCase(Locale.ROOT) + "." + spl[0].toLowerCase(Locale.ROOT) + "." + sk; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/javawebstack/webutils/config/Mapping.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,26 @@ | ||
package org.javawebstack.webutils.config; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class Mapping implements Function<String, String> { | ||
|
||
private final Map<String, String> mapping = new HashMap<>(); | ||
private boolean failIfNotFound = false; | ||
|
||
public Mapping failIfNotFound(boolean failIfNotFound) { | ||
this.failIfNotFound = failIfNotFound; | ||
return this; | ||
} | ||
|
||
public Mapping map(String from, String to) { | ||
mapping.put(from, to); | ||
return this; | ||
} | ||
|
||
public String apply(String s) { | ||
return mapping.getOrDefault(s, failIfNotFound ? null : s); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/javawebstack/webutils/config/MappingPipeline.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,19 @@ | ||
package org.javawebstack.webutils.config; | ||
|
||
import java.util.function.Function; | ||
|
||
public class MappingPipeline implements Function<String, String> { | ||
|
||
private final Function<String, String>[] pipeline; | ||
|
||
public MappingPipeline(Function<String, String>... pipeline) { | ||
this.pipeline = pipeline; | ||
} | ||
|
||
public String apply(String s) { | ||
String k = s; | ||
for(Function<String, String> mapping : pipeline) | ||
k = mapping.apply(k); | ||
return k == null ? s : k; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/javawebstack/webutils/config/MappingTryout.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,28 @@ | ||
package org.javawebstack.webutils.config; | ||
|
||
import java.util.function.Function; | ||
|
||
public class MappingTryout implements Function<String, String> { | ||
|
||
private final Function<String, String>[] tryout; | ||
private boolean failIfEqual = true; | ||
|
||
public MappingTryout(Function<String, String>... tryout) { | ||
this.tryout = tryout; | ||
} | ||
|
||
public MappingTryout failIfEqual(boolean failIfEqual) { | ||
this.failIfEqual = failIfEqual; | ||
return this; | ||
} | ||
|
||
public String apply(String s) { | ||
for(Function<String, String> mapping : tryout) { | ||
String k = mapping.apply(s); | ||
if(k != null && (!failIfEqual || !k.equals(s))) | ||
return k; | ||
} | ||
return null; | ||
} | ||
|
||
} |
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
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