1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Change function to return null on error, and change arity checks.

This commit is contained in:
Danila Fedorin 2017-07-24 14:03:55 -07:00
parent dff4c99126
commit 8a3e5cc5c7

View File

@ -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);
} }