diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 20:15:17 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2018-10-14 20:15:17 -0400 |
| commit | 004bc5de7618bc44079e6cdd21a50d6814c76c50 (patch) | |
| tree | 3cbcc77bf04c7dae4c8ad3d745d181d4bfca77fb /src/main/java/bjc/inflexion/CardinalState.java | |
| parent | b09885e13d8829ee59e10ec0a957f6209c3e4aeb (diff) | |
General update
Testing, plus some reorganization
Diffstat (limited to 'src/main/java/bjc/inflexion/CardinalState.java')
| -rw-r--r-- | src/main/java/bjc/inflexion/CardinalState.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/bjc/inflexion/CardinalState.java b/src/main/java/bjc/inflexion/CardinalState.java new file mode 100644 index 0000000..b9867f7 --- /dev/null +++ b/src/main/java/bjc/inflexion/CardinalState.java @@ -0,0 +1,78 @@ +package bjc.inflexion; + +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. + * + * By this, I mean for various unit scales, like custom and metric weights + */ +/** + * 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> { + /* + * Alias + */ + } + + /** + * 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; + } +} |
