1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-11 17:45:20 +00:00

Add a lot of comments. More to come.

This commit is contained in:
2017-07-25 22:47:48 -07:00
parent ade4eb1035
commit c19ae3b071
13 changed files with 343 additions and 0 deletions

View File

@@ -5,16 +5,40 @@ import org.nwapw.abacus.number.NumberInterface;
import java.util.HashMap;
/**
* A function that operates on one or more
* inputs and returns a single number.
*/
public abstract class Function {
/**
* A map to correctly promote different number implementations to each other.
*/
private static final HashMap<Class<? extends NumberInterface>, Integer> priorityMap =
new HashMap<Class<? extends NumberInterface>, Integer>() {{
put(NaiveNumber.class, 0);
}};
/**
* Checks whether the given params will work for the given function.
* @param params the given params
* @return true if the params can be used with this function.
*/
protected abstract boolean matchesParams(NumberInterface[] params);
/**
* Internal apply implementation, which already receives appropriately promoted
* parameters that have bee run through matchesParams
* @param params the promoted parameters.
* @return the return value of the function.
*/
protected abstract NumberInterface applyInternal(NumberInterface[] params);
/**
* Function to check, promote arguments and run the function.
* @param params the raw input parameters.
* @return the return value of the function, or null if an error occurred.
*/
public NumberInterface apply(NumberInterface...params) {
if(!matchesParams(params)) return null;
return applyInternal(params);