mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Change function to return null on error, and change arity checks.
This commit is contained in:
parent
dff4c99126
commit
8a3e5cc5c7
|
@ -2,14 +2,11 @@ package org.nwapw.abacus.number;
|
||||||
|
|
||||||
public abstract class Function {
|
public abstract class Function {
|
||||||
|
|
||||||
public int arity;
|
protected abstract boolean matchesParams(Number[] params);
|
||||||
|
protected abstract Number applyInternal(Number[] params);
|
||||||
|
|
||||||
protected abstract Number applyInternal(Number...params);
|
public Number apply(Number...params) {
|
||||||
|
if(!matchesParams(params)) return null;
|
||||||
public Number apply(Number...params) throws IllegalArgumentException {
|
|
||||||
if(params.length != arity)
|
|
||||||
throw new IllegalArgumentException("Invalid number of arguments: Function takes "
|
|
||||||
+ arity + ", " + params.length + " provided.");
|
|
||||||
return applyInternal(params);
|
return applyInternal(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user