aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function/Addition.java
blob: f40bc24d7a2a23b7946ac983e5ae31ac52eb69d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package jcgp.function;

import jcgp.population.Connection;

public class Addition extends Function {
	
	private int arity = 2;

	@Override
	public Object run(Connection... connections) {
		if (connections.length < arity) {
			throw new InvalidArgumentsException("Not enough connections were given.");
		} else if (connections[0].getValue() instanceof Integer) {
			return ((Integer) connections[0].getValue()) + ((Integer) connections[1].getValue());
		} else {
			throw new InvalidArgumentsException("Wrong data type, this function takes Integer.");
		}
	}

	@Override
	public int getArity() {
		return arity;
	}

}