Add general KiwiException that other Exceptions extend

This commit is contained in:
Alex Birkett 2016-01-31 12:43:20 +01:00
parent fc14835bab
commit 88307a9f06
11 changed files with 30 additions and 14 deletions

View File

@ -3,9 +3,11 @@ package no.birkett.kiwi;
/** /**
* Created by alex on 30/01/15. * Created by alex on 30/01/15.
*/ */
public class DuplicateConstraintException extends Exception { public class DuplicateConstraintException extends KiwiException {
private Constraint constraint;
public DuplicateConstraintException(Constraint constraint) { public DuplicateConstraintException(Constraint constraint) {
this.constraint = constraint;
} }
} }

View File

@ -3,6 +3,6 @@ package no.birkett.kiwi;
/** /**
* Created by yongsun on 1/13/16. * Created by yongsun on 1/13/16.
*/ */
public class DuplicateEditVariableException extends Exception { public class DuplicateEditVariableException extends KiwiException {
} }

View File

@ -3,7 +3,7 @@ package no.birkett.kiwi;
/** /**
* Created by alex on 31/01/15. * Created by alex on 31/01/15.
*/ */
public class InternalSolverError extends RuntimeException { public class InternalSolverError extends Error {
public InternalSolverError(String string) { public InternalSolverError(String string) {

View File

@ -0,0 +1,10 @@
package no.birkett.kiwi;
/**
* Created by alex on 30/01/16.
*/
public class KiwiException extends Exception {
public KiwiException() {
}
}

View File

@ -3,5 +3,5 @@ package no.birkett.kiwi;
/** /**
* Created by alex on 01/02/15. * Created by alex on 01/02/15.
*/ */
public class NonlinearExpressionException extends RuntimeException { public class NonlinearExpressionException extends KiwiException {
} }

View File

@ -3,5 +3,5 @@ package no.birkett.kiwi;
/** /**
* Created by alex on 30/01/15. * Created by alex on 30/01/15.
*/ */
public class RequiredFailureException extends Exception { public class RequiredFailureException extends KiwiException {
} }

View File

@ -3,7 +3,7 @@ package no.birkett.kiwi;
/** /**
* Created by yongsun on 1/13/16. * Created by yongsun on 1/13/16.
*/ */
public class UnknownConstraintException extends Exception { public class UnknownConstraintException extends KiwiException {
public UnknownConstraintException(Constraint constraint){ public UnknownConstraintException(Constraint constraint){

View File

@ -3,8 +3,10 @@ package no.birkett.kiwi;
/** /**
* Created by alex on 30/01/15. * Created by alex on 30/01/15.
*/ */
public class UnsatisfiableConstraintException extends Exception { public class UnsatisfiableConstraintException extends KiwiException {
public UnsatisfiableConstraintException(Constraint constraint) {
private Constraint constraint;
public UnsatisfiableConstraintException(Constraint constraint) {
this.constraint = constraint;
} }
} }

View File

@ -7,7 +7,7 @@ import java.util.HashMap;
*/ */
public class Benchmarks { public class Benchmarks {
public static void testAddingLotsOfConstraints() throws DuplicateConstraintException, UnsatisfiableConstraintException { public static void testAddingLotsOfConstraints() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
Solver solver = new Solver(); Solver solver = new Solver();
final HashMap<String, Variable> variables = new HashMap<String, Variable>(); final HashMap<String, Variable> variables = new HashMap<String, Variable>();
@ -65,6 +65,8 @@ public class Benchmarks {
e.printStackTrace(); e.printStackTrace();
} catch (UnsatisfiableConstraintException e) { } catch (UnsatisfiableConstraintException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NonlinearExpressionException e) {
e.printStackTrace();
} }
} }

View File

@ -19,7 +19,7 @@ public class ConstraintParser {
Expression resolveConstant(String name); Expression resolveConstant(String name);
} }
public static Constraint parseConstraint(String constraintString, CassowaryVariableResolver variableResolver) { public static Constraint parseConstraint(String constraintString, CassowaryVariableResolver variableResolver) throws NonlinearExpressionException {
Matcher matcher = pattern.matcher(constraintString); Matcher matcher = pattern.matcher(constraintString);
matcher.find(); matcher.find();
@ -63,7 +63,7 @@ public class ConstraintParser {
return strength; return strength;
} }
public static Expression resolveExpression(String expressionString, CassowaryVariableResolver variableResolver) { public static Expression resolveExpression(String expressionString, CassowaryVariableResolver variableResolver) throws NonlinearExpressionException {
List<String> postFixExpression = infixToPostfix(tokenizeExpression(expressionString)); List<String> postFixExpression = infixToPostfix(tokenizeExpression(expressionString));

View File

@ -202,7 +202,7 @@ public class RealWorldTests {
} }
@Test @Test
public void testGridLayout() throws DuplicateConstraintException, UnsatisfiableConstraintException { public void testGridLayout() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
final Solver solver = new Solver(); final Solver solver = new Solver();
final HashMap<String, HashMap<String, Variable>> nodeHashMap = new HashMap<>(); final HashMap<String, HashMap<String, Variable>> nodeHashMap = new HashMap<>();
@ -321,7 +321,7 @@ public class RealWorldTests {
*/ */
@Test @Test
public void testGridX1000() throws DuplicateConstraintException, UnsatisfiableConstraintException { public void testGridX1000() throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
long nanoTime = System.nanoTime(); long nanoTime = System.nanoTime();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {