/** * Return a string representation of this truth table. * * @return a string representation of this truth table */ @Override public String toString() { String str = ""; // Build the header by listing all variables... for (final String var : variablesList) { str += var + " "; } // and then the expressions themselves for (final BooleanExpression expression : expressionCollection) { str += " " + expression + " "; } str += "\n"; // Build each row by listing the values of the variables and the value // of the expression for (final Map<String, Boolean> dict : resultsKeyList) { for (final String var : variablesList) { str += (dict.get(var) ? "1" : "0") + " "; } for (final BooleanExpression expression : expressionCollection) { for (int i = 0; i < (expression.toString().length() - 1) / 2; i++) { str += " "; } str += " " + (results.get(dict).get(expression) ? "1" : "0"); for (int i = 0; i < expression.toString().length() / 2; i++) { str += " "; } str += " "; } str += "\n"; } str = str.substring(0, str.length() - 1); return str; }