From ae51c587c53f7ca311e556e3cbd0c5566d6c2843 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 12 Feb 2018 22:44:26 -0500 Subject: Update --- .../main/java/bjc/utils/math/CardinalState.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 base/src/main/java/bjc/utils/math/CardinalState.java (limited to 'base/src/main/java/bjc/utils/math/CardinalState.java') 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 { + + } + + /** + * Custom cardinals for numbers. + */ + public final Map customNumbers; + + /** + * Custom functions to apply to certain scales. + */ + public final Map 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 customNumbers, Map 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 ent : customScales.entrySet()) { + if(ent.getKey().test(number)) { + return ent.getValue().apply(number, this); + } + } + + return null; + } +} \ No newline at end of file -- cgit v1.2.3