diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:44:26 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:44:26 -0500 |
| commit | ae51c587c53f7ca311e556e3cbd0c5566d6c2843 (patch) | |
| tree | a6bbb0baaa20300ad9949425455ea890c021d046 /base/src/main/java/bjc/utils/math/CardinalState.java | |
| parent | 32f5da54c628408c96db09d279f3a7ef44b3bd19 (diff) | |
Update
Diffstat (limited to 'base/src/main/java/bjc/utils/math/CardinalState.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/math/CardinalState.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/math/CardinalState.java b/base/src/main/java/bjc/utils/math/CardinalState.java new file mode 100644 index 0000000..f42fb85 --- /dev/null +++ b/base/src/main/java/bjc/utils/math/CardinalState.java @@ -0,0 +1,74 @@ +package bjc.utils.math; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.BiFunction; +import java.util.function.LongPredicate; + +/* + * @TODO 2/12/18 Ben Culkin :AdditionalCardinals + * + * Add some built-in implementations for various things. + */ +/** + * Customizations for number cardinalization. + * + * @author EVE + * + */ +public class CardinalState { + /** + * Alias type for converting numbers to cardinals. + * + * @author EVE + * + */ + @FunctionalInterface + public interface Cardinalizer extends BiFunction<Long, CardinalState, String> { + + } + + /** + * Custom cardinals for numbers. + */ + public final Map<Long, String> customNumbers; + + /** + * Custom functions to apply to certain scales. + */ + public final Map<LongPredicate, Cardinalizer> customScales; + + /** + * Create a new set of cardinalization customizations. + * + * @param customNumbers + * The custom numbers to use. + * @param customScales + * The custom scales to use. + */ + public CardinalState(Map<Long, String> customNumbers, Map<LongPredicate, Cardinalizer> customScales) { + this.customNumbers = customNumbers; + this.customScales = customScales; + } + + /** + * Handle a custom cardinal number + * + * @param number + * The number to handle + * @return The number as a cardinal, or null if we don't handle it. + */ + public String handleCustom(long number) { + if(customNumbers.containsKey(number)) { + return customNumbers.get(number); + } + + for(Entry<LongPredicate, Cardinalizer> ent : customScales.entrySet()) { + if(ent.getKey().test(number)) { + return ent.getValue().apply(number, this); + } + } + + return null; + } +}
\ No newline at end of file |
