package com.kevlindev.karnaugh;

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

public class Function extends MinTermList {
	private String name;
	private List<String> arguments;
	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;
	}

	/**
	 * getMinTermIndexes
	 * 
	 * @return
	 */
	public List<Integer> getMinTermIndexes() {
		List<Integer> result = new ArrayList<Integer>();

		for (MinTerm term : this) {
			result.addAll(term.getIndexes());
		}

		return result;
	}

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

	/**
	 * setValues
	 * 
	 * @param values
	 */
	public void setValues(List<TruthValue> values) {
		int index = 0;

		for (TruthValue value : values) {
			if (value == TruthValue.TRUE) {
				this.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.size());

		for (MinTerm minterm : this) {
			int index = minterm.getIndexes().get(0);

			values.add(Integer.toString(index));
		}

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

		return sb.toString();
	}
}

@@ -524,98 +524,8 @@
 %09%7D%0A%0A
-%09/**%0A%09 * getName%0A%09 * %0A%09 * @return%0A%09 */%0A%09public String getName() %7B%0A%09%09return this.name;%0A%09%7D%0A%0A
 %09/**
@@ -547,16 +547,16 @@
 Indexes%0A
+
 %09 * %0A%09 *
@@ -754,24 +754,114 @@
 result;%0A%09%7D%0A%0A
+%09/**%0A%09 * getName%0A%09 * %0A%09 * @return%0A%09 */%0A%09public String getName() %7B%0A%09%09return this.name;%0A%09%7D%0A%0A
 %09/**%0A%09 * set
@@ -1224,16 +1224,774 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09/**%0A%09 * toFunctionString%0A%09 * %0A%09 * @param terms%0A%09 * @return%0A%09 */%0A%09public String toFunctionString(MinTermList terms) %7B%0A%09%09List%3CString%3E products = new ArrayList%3CString%3E();%0A%0A%09%09terms.sort();%0A%0A%09%09for (MinTerm term : terms) %7B%0A%09%09%09List%3CString%3E sums = new ArrayList%3CString%3E();%0A%09%09%09List%3CTruthValue%3E values = term.getBits();%0A%0A%09%09%09for (int i = 0; i %3C values.size(); i++) %7B%0A%09%09%09%09TruthValue value = values.get(i);%0A%09%09%09%09String argument = arguments.get(i);%0A%0A%09%09%09%09switch (value) %7B%0A%09%09%09%09%09case FALSE:%0A%09%09%09%09%09%09sums.add(%22~%22 + argument);%0A%09%09%09%09%09%09break;%0A%0A%09%09%09%09%09case TRUE:%0A%09%09%09%09%09%09sums.add(argument);%0A%09%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%0A%09%09%09products.add(Util.join(%22 & %22, sums));%0A%09%09%7D%0A%0A%09%09return name + %22 = %22 + Util.join(%22 %7C %22, products);%0A%09%7D%0A%0A%09/*%0A%09 * (non-Javadoc)%0A%09 * %0A%09 * @see java.lang.Object#toString()%0A%09 */%0A
 %09public 

Add ability to apply a list of minterms to a function to retrieve a string representation of that function with the minterms applied