Add toString() methods

This commit is contained in:
Alex Birkett 2016-01-31 13:50:48 +01:00
parent 7b2f8cacf2
commit 6010dc04f3
6 changed files with 37 additions and 0 deletions

View File

@ -73,4 +73,9 @@ public class Constraint {
this.op = op; this.op = op;
} }
@Override
public String toString() {
return "expression: (" + expression + ") strength: " + strength + " operator: " + op;
}
} }

View File

@ -68,5 +68,22 @@ public class Expression {
public final boolean isConstant() { public final boolean isConstant() {
return terms.size() == 0; return terms.size() == 0;
} }
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("isConstant: " + isConstant() + " constant: " + constant);
if (!isConstant()) {
sb.append(" terms: [");
for (Term term: terms) {
sb.append("(");
sb.append(term);
sb.append(")");
}
sb.append("] ");
}
return sb.toString();
}
} }

View File

@ -7,4 +7,7 @@ public class KiwiException extends Exception {
public KiwiException() { public KiwiException() {
} }
public KiwiException(String message) {
super(message);
}
} }

View File

@ -36,4 +36,9 @@ public class Term {
public double getValue() { public double getValue() {
return coefficient * variable.getValue(); return coefficient * variable.getValue();
} }
@Override
public String toString() {
return "variable: (" + variable + ") coefficient: " + coefficient;
}
} }

View File

@ -7,6 +7,7 @@ public class UnsatisfiableConstraintException extends KiwiException {
private Constraint constraint; private Constraint constraint;
public UnsatisfiableConstraintException(Constraint constraint) { public UnsatisfiableConstraintException(Constraint constraint) {
super(constraint.toString());
this.constraint = constraint; this.constraint = constraint;
} }
} }

View File

@ -27,4 +27,10 @@ public class Variable {
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String toString() {
return "name: " + name + " value: " + value;
}
} }