package com.kevlindev.karnaugh;

import java.util.ArrayList;
import java.util.List;

public class Function {
	private String name;
	private List<String> arguments;
	private List<MinTerm> minterms;
	private int bits;

	/**
	 * Function
	 * 
	 * @param name
	 */
	public Function(String name, int bits) {
		this.name = name;
		this.bits = bits;
	}

	/**
	 * getArguments
	 * 
	 * @return
	 */
	public List<String> getArguments() {
		return this.arguments;
	}

	/**
	 * getBits
	 * 
	 * @return
	 */
	public int getBits() {
		return bits;
	}
	
	/**
	 * getName
	 * 
	 * @return
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * getValues
	 * 
	 * @return
	 */
	public List<MinTerm> getMinTerms() {
		return this.minterms;
	}

	/**
	 * setArguments
	 * 
	 * @param args
	 */
	public void setArguments(List<String> args) {
		this.arguments = args;
	}

	/**
	 * setValues
	 * 
	 * @param values
	 */
	public void setValues(List<TruthValue> values) {
		int index = 0;
		this.minterms = new ArrayList<MinTerm>();

		for (TruthValue value : values) {
			if (value == TruthValue.TRUE) {
				minterms.add(new MinTerm(bits, index));
			}
			
			index++;
		}
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();

		sb.append(name).append("(").append(Util.join(",", arguments)).append(") = ");

		List<String> values = new ArrayList<String>(this.minterms.size());

		for (MinTerm minterm : minterms) {
			int index = minterm.getIndexes().get(0);
			
			values.add(Integer.toString(index));
		}

		sb.append("\u2211(").append(Util.join(",", values)).append(")");

		return sb.toString();
	}
}

@@ -532,18 +532,17 @@
 its;%0A%09%7D%0A
-%09
 %0A
+
 %09/**%0A%09 *
@@ -619,24 +619,266 @@
 s.name;%0A%09%7D%0A%0A
+%09/**%0A%09 * getMinTermIndexes%0A%09 * %0A%09 * @return%0A%09 */%0A%09public List%3CInteger%3E getMinTermIndexes() %7B%0A%09%09List%3CInteger%3E result = new ArrayList%3CInteger%3E();%0A%0A%09%09for (MinTerm term : minterms) %7B%0A%09%09%09result.addAll(term.getIndexes());%0A%09%09%7D%0A%0A%09%09return result;%0A%09%7D%0A%0A
 %09/**%0A%09 * get
@@ -1375,20 +1375,17 @@
 );%0A%09%09%09%7D%0A
-%09%09%09
 %0A
+
 %09%09%09index
@@ -1699,19 +1699,16 @@
 get(0);%0A
-%09%09%09
 %0A%09%09%09valu

Add method to extract the list of all minterm indexes defined by a function