mirror of
https://github.com/DanilaFe/abacus
synced 2026-09-25 12:52:33 +00:00
Convert Applicable interfaces into Kotlin.
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
package org.nwapw.abacus.function;
|
||||
|
||||
/**
|
||||
* 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 <T> the type of the parameters passed to this applicable.
|
||||
* @param <O> the return type of the applicable.
|
||||
*/
|
||||
public interface Applicable<T, O> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* If the parameters can be used with this applicable, returns
|
||||
* the result of the application of the applicable to the parameters.
|
||||
* Otherwise, returns null.
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.nwapw.abacus.function;
|
||||
|
||||
import org.nwapw.abacus.tree.Reducer;
|
||||
|
||||
/**
|
||||
* A slightly more specific Applicable that requires a reducer
|
||||
* to be passed to it along with the parameters.
|
||||
* @param <T> the type of the input arguments.
|
||||
* @param <O> the return type of the application.
|
||||
* @param <R> the required type of the reducer.
|
||||
*/
|
||||
public interface ReducerApplicable<T, O, R> extends Applicable<T, O> {
|
||||
|
||||
@Override
|
||||
default O applyInternal(T[] params) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default O apply(T... params) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this applicable to the given arguments, and reducer.
|
||||
* @param reducer the reducer to use in the application.
|
||||
* @param args the arguments to apply to.
|
||||
* @return the result of the application.
|
||||
*/
|
||||
O applyWithReducerInternal(Reducer<R> reducer, T[] args);
|
||||
|
||||
/**
|
||||
* Applies this applicable to the given arguments, and reducer,
|
||||
* if the arguments and reducer are compatible with this applicable.
|
||||
* @param reducer the reducer to use in the application.
|
||||
* @param args the arguments to apply to.
|
||||
* @return the result of the application, or null if the arguments are incompatible.
|
||||
*/
|
||||
default O applyWithReducer(Reducer<R> reducer, T...args) {
|
||||
if(!matchesParams(args) || reducer == null) return null;
|
||||
return applyWithReducerInternal(reducer, args);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user