diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt b/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt index d0946e6..f76f147 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/NumberFunction.kt @@ -1,5 +1,6 @@ package org.nwapw.abacus.function +import org.nwapw.abacus.function.applicable.Applicable import org.nwapw.abacus.number.NumberInterface /** diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt b/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt index 9b1f2f1..81349c3 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/NumberOperator.kt @@ -1,5 +1,6 @@ package org.nwapw.abacus.function +import org.nwapw.abacus.function.applicable.Applicable import org.nwapw.abacus.number.NumberInterface /** diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt b/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt index 42568ea..7b31d92 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueFunction.kt @@ -1,5 +1,6 @@ package org.nwapw.abacus.function +import org.nwapw.abacus.function.applicable.ReducerApplicable import org.nwapw.abacus.number.NumberInterface import org.nwapw.abacus.tree.TreeNode diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt b/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt index beed6b2..990ef1c 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/TreeValueOperator.kt @@ -1,5 +1,6 @@ package org.nwapw.abacus.function +import org.nwapw.abacus.function.applicable.ReducerApplicable import org.nwapw.abacus.number.NumberInterface import javax.swing.tree.TreeNode diff --git a/core/src/main/java/org/nwapw/abacus/function/Applicable.java b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt similarity index 68% rename from core/src/main/java/org/nwapw/abacus/function/Applicable.java rename to core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt index 2133848..4988c2a 100644 --- a/core/src/main/java/org/nwapw/abacus/function/Applicable.java +++ b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt @@ -1,27 +1,28 @@ -package org.nwapw.abacus.function; +package org.nwapw.abacus.function.applicable /** - * A class that represents something that can be applied to one or more + * A class that can be applied to arguments. + * + * Applicable is a class that represents something that can be applied to one or more * arguments of the same type, and returns a single value from that application. * @param the type of the parameters passed to this applicable. * @param the return type of the applicable. */ -public interface Applicable { +interface Applicable { /** * Checks if the given applicable can be used with the given parameters. * @param params the parameter array to verify for compatibility. * @return whether the array can be used with applyInternal. */ - boolean matchesParams(T[] params); - + fun matchesParams(params: Array): Boolean /** * Applies the applicable object to the given parameters, * without checking for compatibility. * @param params the parameters to apply to. * @return the result of the application. */ - O applyInternal(T[] params); + fun applyInternal(params: Array): O? /** * If the parameters can be used with this applicable, returns @@ -30,9 +31,9 @@ public interface Applicable { * @param params the parameters to apply to. * @return the result of the operation, or null if parameters do not match. */ - default O apply(T... params){ - if(!matchesParams(params)) return null; - return applyInternal(params); + fun apply(vararg params: T): O? { + if(!matchesParams(params)) return null + return applyInternal(params) } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/nwapw/abacus/function/ReducerApplicable.java b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/ReducerApplicable.kt similarity index 54% rename from core/src/main/java/org/nwapw/abacus/function/ReducerApplicable.java rename to core/src/main/kotlin/org/nwapw/abacus/function/applicable/ReducerApplicable.kt index bff7934..6de6a27 100644 --- a/core/src/main/java/org/nwapw/abacus/function/ReducerApplicable.java +++ b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/ReducerApplicable.kt @@ -1,24 +1,24 @@ -package org.nwapw.abacus.function; +package org.nwapw.abacus.function.applicable -import org.nwapw.abacus.tree.Reducer; +import org.nwapw.abacus.tree.Reducer /** - * A slightly more specific Applicable that requires a reducer + * Applicable that requires a reducer. + * + * ReducerApplicable slightly more specific Applicable that requires a reducer * to be passed to it along with the parameters. * @param the type of the input arguments. * @param the return type of the application. * @param the required type of the reducer. */ -public interface ReducerApplicable extends Applicable { +interface ReducerApplicable : Applicable { - @Override - default O applyInternal(T[] params) { - return null; + override fun applyInternal(params: Array): O? { + return null } - @Override - default O apply(T... params) { - return null; + override fun apply(vararg params: T): O? { + return null } /** @@ -27,8 +27,7 @@ public interface ReducerApplicable extends Applicable { * @param args the arguments to apply to. * @return the result of the application. */ - O applyWithReducerInternal(Reducer reducer, T[] args); - + fun applyWithReducerInternal(reducer: Reducer, params: Array): O? /** * Applies this applicable to the given arguments, and reducer, * if the arguments and reducer are compatible with this applicable. @@ -36,9 +35,9 @@ public interface ReducerApplicable extends Applicable { * @param args the arguments to apply to. * @return the result of the application, or null if the arguments are incompatible. */ - default O applyWithReducer(Reducer reducer, T...args) { - if(!matchesParams(args) || reducer == null) return null; - return applyWithReducerInternal(reducer, args); + fun applyWithReducer(reducer: Reducer, vararg params: T): O? { + if(!matchesParams(params)) return null + return applyWithReducerInternal(reducer, params) } -} +} \ No newline at end of file