Skip to content

Commit

Permalink
separated default cases in switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
rouven-walter committed Jul 23, 2020
1 parent 89c03b2 commit 024f310
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public <T extends Proposition> UNSATCore<T> computeMUS(final List<T> proposition
case PLAIN_INSERTION:
return this.insertion.computeMUS(propositions, f, config);
case DELETION:
default:
return this.deletion.computeMUS(propositions, f, config);
default:
throw new IllegalStateException("Unknown MUS algorithm: " + config.algorithm);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/logicng/formulas/FormulaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ private Formula importOrPanic(final Formula formula) {
case IMPORT:
return importFormula(formula);
case PANIC:
default:
throw new UnsupportedOperationException("Found an operand with a different formula factory.");
default:
throw new IllegalStateException("Unknown formula merge strategy: " + this.formulaMergeStrategy);
}
}

Expand Down Expand Up @@ -476,8 +477,9 @@ private LinkedHashSet<? extends Formula> importOrPanic(final LinkedHashSet<? ext
}
return result;
case PANIC:
default:
throw new UnsupportedOperationException("Found an operand with a different formula factory.");
default:
throw new IllegalStateException("Unknown formula merge strategy: " + this.formulaMergeStrategy);
}
}

Expand Down Expand Up @@ -511,8 +513,9 @@ private Literal[] importOrPanic(final Literal[] literals) {
}
return result;
case PANIC:
default:
throw new UnsupportedOperationException("Found an operand with a different formula factory.");
default:
throw new IllegalStateException("Unknown formula merge strategy: " + this.formulaMergeStrategy);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/logicng/formulas/PBConstraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static Tristate evaluateCoeffs(final int minValue, final int maxValue, final int
case GT:
return status < 1 ? Tristate.TRUE : (status >= 3 ? Tristate.FALSE : Tristate.UNDEF);
default:
throw new IllegalStateException("Unknown pseudo-Boolean comparator");
throw new IllegalStateException("Unknown pseudo-Boolean comparator: " + comparator);
}
}

Expand Down Expand Up @@ -505,7 +505,7 @@ public Formula substitute(final Substitution substitution) {
newCoeffs.add(this.coefficients[i]);
break;
default:
throw new IllegalArgumentException("Cannnot substitute a formula for a literal in a pseudo-Boolean constraint");
throw new IllegalArgumentException("Cannot substitute a formula for a literal in a pseudo-Boolean constraint");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package org.logicng.formulas.printer;

import org.logicng.formulas.CType;
import org.logicng.formulas.FType;
import org.logicng.formulas.Formula;
import org.logicng.formulas.Literal;

Expand Down Expand Up @@ -62,13 +63,11 @@ private static String latexName(final String name) {

@Override
public String toInnerString(final Formula formula) {
switch (formula.type()) {
case LITERAL:
final Literal lit = (Literal) formula;
return lit.phase() ? latexName(lit.name()) : this.negation() + " " + latexName(lit.name());
default:
return super.toInnerString(formula);
if (formula.type() == FType.LITERAL) {
final Literal lit = (Literal) formula;
return lit.phase() ? latexName(lit.name()) : this.negation() + " " + latexName(lit.name());
}
return super.toInnerString(formula);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package org.logicng.formulas.printer;

import org.logicng.formulas.CType;
import org.logicng.formulas.FType;
import org.logicng.formulas.Formula;
import org.logicng.formulas.Literal;

Expand Down Expand Up @@ -103,13 +104,11 @@ private static String getSubscript(final String number) {

@Override
protected String toInnerString(final Formula formula) {
switch (formula.type()) {
case LITERAL:
final Literal lit = (Literal) formula;
return lit.phase() ? utf8Name(lit.name()) : this.negation() + utf8Name(lit.name());
default:
return super.toInnerString(formula);
if (formula.type() == FType.LITERAL) {
final Literal lit = (Literal) formula;
return lit.phase() ? utf8Name(lit.name()) : this.negation() + utf8Name(lit.name());
}
return super.toInnerString(formula);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/logicng/predicates/CNFPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public boolean test(final Formula formula, final boolean cache) {
case EQUIV:
case PBC:
return false;
// AND and OR always have a cached CNF predicate (set in the constructor)
case OR:
case AND:
throw new IllegalStateException("Formula of type AND/OR has no cached CNF predicate, but should have.");
default:
throw new IllegalArgumentException("Cannot compute CNF predicate on " + formula.type());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void update(final MiniSatStyleSolver s, final int rhs, final LNGIntVector
}
break;
default:
throw new IllegalStateException("Unknwon incremental strategy: " + this.incrementalStrategy);
throw new IllegalStateException("Unknown incremental strategy: " + this.incrementalStrategy);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private Formula computePosPolarity(final Formula formula) {
return result;
}
default:
throw new IllegalArgumentException("not yet implemented");
throw new IllegalArgumentException("Unknown or unexpected formula type. Expected AND or OR formula type only.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public Formula apply(final Formula formula, final boolean cache) {
final FormulaFactory f = formula.factory();
final Formula result;
switch (formula.type()) {
case FALSE:
case TRUE:
case LITERAL:
case PBC:
result = formula;
break;
case EQUIV:
final Equivalence equiv = (Equivalence) formula;
result = f.equivalence(this.apply(equiv.left(), cache), this.apply(equiv.right(), cache));
Expand All @@ -73,7 +79,7 @@ public Formula apply(final Formula formula, final boolean cache) {
result = distributeNAry(formula, cache, f);
break;
default:
result = formula;
throw new IllegalStateException("Unknown formula type: " + formula.type());
}
if (cache) {
formula.setTransformationCacheEntry(TransformationCacheEntry.DISTRIBUTIVE_SIMPLIFICATION, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ private Formula applyRec(final Formula formula, final boolean cache) {
return newFormula instanceof NAryOperator ? simplify((NAryOperator) newFormula) : newFormula;
case NOT:
return apply(((Not) formula).operand(), cache).negate();
default:
case FALSE:
case TRUE:
case LITERAL:
case IMPL:
case EQUIV:
case PBC:
return formula;
default:
throw new IllegalStateException("Unknown formula type: " + formula.type());
}
}

Expand Down

0 comments on commit 024f310

Please sign in to comment.