package org.formular.operation;

import java.util.LinkedList;
import java.util.List;

import org.formular.core.IOperation;
import org.formular.core.Input;
import org.formular.description.DescriptionElement;

public abstract class BinaryOperation extends AOperation {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public IOperation right;
	public IOperation left;
	public void right(IOperation operation2) {
		right = operation2;	
	}

	public void left(IOperation operation1) {
		left = operation1;
	}

	

	public IOperation right(Float i, Class<? extends ParameterOperation> class1) {
		
		ParameterOperation newInstance = ParameterOperation.createParameter(i, class1);
		this.right(newInstance);
		return newInstance;
	}

	public IOperation left(Float i, Class<? extends ParameterOperation> class1) {
		ParameterOperation newInstance = ParameterOperation.createParameter(i, class1);
		this.left(newInstance);
		return newInstance;
	}

	@Override
	public List <DescriptionElement> inputDescriptions() {
		List<DescriptionElement> ret = new LinkedList<DescriptionElement>();
		for (Input input: inputs()) {
			ret.add(input.getDesciption());
		}
		return ret;
	}
	
	@Override
	public List<Input> inputs() {
		List<Input> inputs = new LinkedList<Input>();
		if(right != null)
			inputs.addAll(right.inputs());
		if(left != null)
			inputs.addAll(left.inputs());
		return inputs;
	}
	
	public void autoNameInputs() {
		int i = 1;
		for (Input input : this.inputs()) {
			input.setName("input " + i);
			i++;
		}
	};
	
	@Override
	public void addOperand(IOperation operation) {
		if (left == null) {
			left = operation;
			operation.setParent(this);
			return;
		}
		if(right == null) {
			right = operation;
			operation.setParent(this);
			return;
		}
	}
}

@@ -1400,141 +1400,8 @@
 %7D%0A%09%0A
-%09public void autoNameInputs() %7B%0A%09%09int i = 1;%0A%09%09for (Input input : this.inputs()) %7B%0A%09%09%09input.setName(%22input %22 + i);%0A%09%09%09i++;%0A%09%09%7D%0A%09%7D;%0A%09%0A
 %09@Ov

remove useless method