diff options
Diffstat (limited to 'src/jcgp/function')
-rw-r--r-- | src/jcgp/function/FunctionSet.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/jcgp/function/FunctionSet.java b/src/jcgp/function/FunctionSet.java index 07b4ea4..49ff7e7 100644 --- a/src/jcgp/function/FunctionSet.java +++ b/src/jcgp/function/FunctionSet.java @@ -3,6 +3,7 @@ package jcgp.function; import java.util.ArrayList; import java.util.Iterator; + /** * * @author Eduardo Pedroni @@ -14,14 +15,14 @@ public abstract class FunctionSet { protected int maxArity; protected String name; -// public int getTotalFunctionCount() { -// return functionList.length; -// } - - public int getFunctionCount() { + public int getAllowedFunctionCount() { return allowedFunctions.size(); } + public int getTotalFunctionCount() { + return functionList.length; + } + public Function getFunction(int index) { return allowedFunctions.get(index); } @@ -35,14 +36,15 @@ public abstract class FunctionSet { } public void disableFunction(int index) { - for (Iterator<Function> iterator = allowedFunctions.iterator(); iterator.hasNext();) { - if (index < functionList.length) { + if (index < functionList.length) { + for (Iterator<Function> iterator = allowedFunctions.iterator(); iterator.hasNext();) { Function function = (Function) iterator.next(); if (function == functionList[index]) { iterator.remove(); } } - + } else { + throw new IndexOutOfBoundsException("Function " + index + " does not exist, the set only has " + functionList.length + " functions."); } } @@ -51,4 +53,9 @@ public abstract class FunctionSet { allowedFunctions.add(functionList[index]); } } + + @Override + public String toString() { + return name; + } }
\ No newline at end of file |