diff --git a/.classpath b/.classpath index 1864a77c5..a8fa2726c 100644 --- a/.classpath +++ b/.classpath @@ -1,23 +1,23 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="test"/> - <classpathentry kind="src" path="icons"/> - <classpathentry kind="src" path="tipdata"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> - <attributes> - <attribute name="module" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFX14"> - <attributes> - <attribute name="module" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"> - <attributes> - <attribute name="module" value="true"/> - </attributes> - </classpathentry> - <classpathentry kind="output" path="bin/jetuml"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="test"/> + <classpathentry kind="src" path="icons"/> + <classpathentry kind="src" path="tipdata"/> + <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFX14"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="bin/jetuml"/> +</classpath> diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/ClassDiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/ClassDiagramBuilder.java index 08c5cfb39..9a0a7e397 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/ClassDiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/ClassDiagramBuilder.java @@ -27,7 +27,6 @@ import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.DiagramType; -import ca.mcgill.cs.jetuml.diagram.Edge; import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.builder.constraints.ClassDiagramEdgeConstraints; import ca.mcgill.cs.jetuml.diagram.builder.constraints.ConstraintSet; @@ -49,7 +48,19 @@ public class ClassDiagramBuilder extends DiagramBuilder { private static final int PADDING = 10; private static final int TOP_HEIGHT = 20; - + private static final ConstraintSet constraints = new ConstraintSet( + EdgeConstraints.noteEdge(), + EdgeConstraints.noteNode(), + EdgeConstraints.maxEdges(1), + ClassDiagramEdgeConstraints.noSelfGeneralization(), + ClassDiagramEdgeConstraints.noSelfDependency(), + ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class), + ClassDiagramEdgeConstraints.noDirectCycles(GeneralizationEdge.class), + ClassDiagramEdgeConstraints.noDirectCycles(AggregationEdge.class), + ClassDiagramEdgeConstraints.noDirectCycles(AssociationEdge.class), + ClassDiagramEdgeConstraints.noCombinedAssociationAggregation() + ); + /** * Creates a new builder for class diagrams. * @@ -101,18 +112,9 @@ public DiagramOperation createAddNodeOperation(Node pNode, Point pRequestedPosit } @Override - protected ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint) + protected ConstraintSet getEdgeConstraints() { - return new ConstraintSet( - EdgeConstraints.maxEdges(pEdge, pStart, pEnd, aDiagram, 1), - ClassDiagramEdgeConstraints.noSelfGeneralization(pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noSelfDependency(pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class, pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noDirectCycles(GeneralizationEdge.class, pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noDirectCycles(AggregationEdge.class, pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noDirectCycles(AssociationEdge.class, pEdge, pStart, pEnd), - ClassDiagramEdgeConstraints.noCombinedAssociationAggregation(pEdge, pStart, pEnd) - ); + return constraints; } private static boolean validChild(Node pPotentialChild) diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/DiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/DiagramBuilder.java index 1ece6eac3..fc4b66eaf 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/DiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/DiagramBuilder.java @@ -38,7 +38,6 @@ import ca.mcgill.cs.jetuml.diagram.Edge; import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.builder.constraints.ConstraintSet; -import ca.mcgill.cs.jetuml.diagram.builder.constraints.EdgeConstraints; import ca.mcgill.cs.jetuml.diagram.edges.NoteEdge; import ca.mcgill.cs.jetuml.diagram.nodes.FieldNode; import ca.mcgill.cs.jetuml.diagram.nodes.NoteNode; @@ -136,12 +135,9 @@ public final boolean canAdd(Edge pEdge, Point pStart, Point pEnd) return false; } - ConstraintSet constraints = new ConstraintSet( - EdgeConstraints.noteEdge(pEdge, startNode.get(), endNode.get()), - EdgeConstraints.noteNode(pEdge, startNode.get(), endNode.get()) - ); - constraints.merge(getAdditionalEdgeConstraints(pEdge, startNode.get(), endNode.get(), pStart, pEnd)); - return constraints.satisfied(); + + return this.getEdgeConstraints().satisfied(pEdge, startNode.get(), endNode.get(), pStart, pEnd, aDiagram); + } /** @@ -161,15 +157,9 @@ public boolean canAdd(Node pNode, Point pRequestedPosition) } /** - * @param pEdge The edge to add. - * @param pStart The start node. - * @param pEnd The end node. - * @param pStartPoint the point in the start node. - * @param pEndPoint the point in the end node. - * @return Additional, diagram type-specific constraints for adding edges. - * @pre pEdge != null && pStart != null && pEnd != null && pStartPoint!= null && pEndPoint != null + * @return diagram type-specific constraints for adding edges. */ - protected abstract ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint); + protected abstract ConstraintSet getEdgeConstraints(); /** * The default behavior is to position the node so it entirely fits in the diagram, then diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/ObjectDiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/ObjectDiagramBuilder.java index bb86db7b9..e08ed64c6 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/ObjectDiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/ObjectDiagramBuilder.java @@ -40,6 +40,15 @@ */ public class ObjectDiagramBuilder extends DiagramBuilder { + private static final ConstraintSet constraints = new ConstraintSet( + + EdgeConstraints.noteEdge(), + EdgeConstraints.noteNode(), + EdgeConstraints.maxEdges(1), + ObjectDiagramEdgeConstraints.collaboration(), + ObjectDiagramEdgeConstraints.reference() + ); + /** * Creates a new builder for object diagrams. * @@ -53,13 +62,9 @@ public ObjectDiagramBuilder( Diagram pDiagram ) } @Override - protected ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint) + protected ConstraintSet getEdgeConstraints() { - return new ConstraintSet( - EdgeConstraints.maxEdges(pEdge, pStart, pEnd, aDiagram, 1), - ObjectDiagramEdgeConstraints.collaboration(pEdge, pStart, pEnd), - ObjectDiagramEdgeConstraints.reference(pEdge, pStart, pEnd) - ); + return constraints; } @Override diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/SequenceDiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/SequenceDiagramBuilder.java index 421cc2059..42f093484 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/SequenceDiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/SequenceDiagramBuilder.java @@ -52,6 +52,15 @@ public class SequenceDiagramBuilder extends DiagramBuilder { private static final int CALL_NODE_YGAP = 5; private static final ImplicitParameterNodeViewer IMPLICIT_PARAMETER_NODE_VIEWER = new ImplicitParameterNodeViewer(); + private static final ConstraintSet constraints = new ConstraintSet( + EdgeConstraints.noteEdge(), + EdgeConstraints.noteNode(), + EdgeConstraints.maxEdges(1), + SequenceDiagramEdgeConstraints.noEdgesFromParameterTop(), + SequenceDiagramEdgeConstraints.returnEdge(), + SequenceDiagramEdgeConstraints.singleEntryPoint(), + SequenceDiagramEdgeConstraints.callEdgeEnd() + ); /** * Creates a new builder for sequence diagrams. @@ -66,16 +75,10 @@ public SequenceDiagramBuilder( Diagram pDiagram ) } @Override - protected ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint) + protected ConstraintSet getEdgeConstraints() { - ConstraintSet constraintSet = new ConstraintSet( - EdgeConstraints.maxEdges(pEdge, pStart, pEnd, aDiagram, 1), - SequenceDiagramEdgeConstraints.noEdgesFromParameterTop(pStart, pStartPoint), - SequenceDiagramEdgeConstraints.returnEdge(pEdge, pStart, pEnd, aDiagram), - SequenceDiagramEdgeConstraints.singleEntryPoint(pEdge, pStart, aDiagram), - SequenceDiagramEdgeConstraints.callEdgeEnd(pEdge, pStart, pEnd, pEndPoint, aDiagram) - ); - return constraintSet; + + return constraints; } /** diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/StateDiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/StateDiagramBuilder.java index e8c838fd6..3239043ac 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/StateDiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/StateDiagramBuilder.java @@ -23,12 +23,10 @@ import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.DiagramType; -import ca.mcgill.cs.jetuml.diagram.Edge; -import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.builder.constraints.ConstraintSet; import ca.mcgill.cs.jetuml.diagram.builder.constraints.EdgeConstraints; import ca.mcgill.cs.jetuml.diagram.builder.constraints.StateDiagramEdgeConstraints; -import ca.mcgill.cs.jetuml.geom.Point; + /** * A builder for state diagrams. @@ -41,6 +39,15 @@ public class StateDiagramBuilder extends DiagramBuilder * @param pDiagram The diagram to wrap around. * @pre pDiagram != null; */ + private static final ConstraintSet constraints = new ConstraintSet( + + EdgeConstraints.noteEdge(), + EdgeConstraints.noteNode(), + EdgeConstraints.maxEdges(2), + StateDiagramEdgeConstraints.noEdgeFromFinalNode(), + StateDiagramEdgeConstraints.noEdgeToInitialNode() + ); + public StateDiagramBuilder( Diagram pDiagram ) { super( pDiagram ); @@ -48,12 +55,8 @@ public StateDiagramBuilder( Diagram pDiagram ) } @Override - protected ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint) + protected ConstraintSet getEdgeConstraints() { - return new ConstraintSet( - EdgeConstraints.maxEdges(pEdge, pStart, pEnd, aDiagram, 2), - StateDiagramEdgeConstraints.noEdgeFromFinalNode(pEdge, pStart), - StateDiagramEdgeConstraints.noEdgeToInitialNode(pEnd) - ); + return constraints; } } diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/UseCaseDiagramBuilder.java b/src/ca/mcgill/cs/jetuml/diagram/builder/UseCaseDiagramBuilder.java index f84d6913d..56803f0e4 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/UseCaseDiagramBuilder.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/UseCaseDiagramBuilder.java @@ -23,17 +23,23 @@ import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.DiagramType; -import ca.mcgill.cs.jetuml.diagram.Edge; -import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.builder.constraints.ConstraintSet; import ca.mcgill.cs.jetuml.diagram.builder.constraints.EdgeConstraints; -import ca.mcgill.cs.jetuml.geom.Point; + /** * A builder for use case diagram. */ public class UseCaseDiagramBuilder extends DiagramBuilder { + private static final ConstraintSet constraints = new ConstraintSet( + + EdgeConstraints.noteEdge(), + EdgeConstraints.noteNode(), + EdgeConstraints.maxEdges(1), + EdgeConstraints.noSelfEdge() + ); + /** * Creates a new builder for use case diagrams. * @@ -47,11 +53,8 @@ public UseCaseDiagramBuilder( Diagram pDiagram ) } @Override - protected ConstraintSet getAdditionalEdgeConstraints(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint) + protected ConstraintSet getEdgeConstraints() { - return new ConstraintSet( - EdgeConstraints.maxEdges(pEdge, pStart, pEnd, aDiagram, 1), - EdgeConstraints.noSelfEdge(pStart, pEnd) - ); + return constraints; } } diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ClassDiagramEdgeConstraints.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ClassDiagramEdgeConstraints.java index ae5409dd3..bd73b5da6 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ClassDiagramEdgeConstraints.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ClassDiagramEdgeConstraints.java @@ -21,12 +21,14 @@ package ca.mcgill.cs.jetuml.diagram.builder.constraints; +import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.Edge; import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.edges.AggregationEdge; import ca.mcgill.cs.jetuml.diagram.edges.AssociationEdge; import ca.mcgill.cs.jetuml.diagram.edges.DependencyEdge; import ca.mcgill.cs.jetuml.diagram.edges.GeneralizationEdge; +import ca.mcgill.cs.jetuml.geom.Point; /** * Methods to create edge addition constraints that only apply to @@ -34,14 +36,22 @@ */ public final class ClassDiagramEdgeConstraints { - private ClassDiagramEdgeConstraints() {} + private ClassDiagramEdgeConstraints() { + + noSelfGeneralization(); + noSelfDependency(); + noDirectCycles(GeneralizationEdge.class); + noDirectCycles(AggregationEdge.class); + noDirectCycles(AssociationEdge.class); + noCombinedAssociationAggregation(); + } /* * Self edges are not allowed for Generalization edges. */ - public static Constraint noSelfGeneralization(Edge pEdge, Node pStart, Node pEnd) + public static Constraint noSelfGeneralization() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !( pEdge.getClass() == GeneralizationEdge.class && pStart == pEnd ); }; @@ -50,9 +60,9 @@ public static Constraint noSelfGeneralization(Edge pEdge, Node pStart, Node pEnd /* * Self edges are not allowed for Dependency edges. */ - public static Constraint noSelfDependency(Edge pEdge, Node pStart, Node pEnd) + public static Constraint noSelfDependency() { - return () -> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram) -> { return !( pEdge.getClass() == DependencyEdge.class && pStart == pEnd ); }; @@ -61,10 +71,9 @@ public static Constraint noSelfDependency(Edge pEdge, Node pStart, Node pEnd) /* * There can't be two edges of a given type, one in each direction, between two nodes. */ - public static Constraint noDirectCycles(Class<? extends Edge> pEdgeType, - Edge pEdge, Node pStart, Node pEnd) + public static Constraint noDirectCycles(Class<? extends Edge> pEdgeType) { - return () -> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram) -> { if( pEdge.getClass() != pEdgeType ) { @@ -84,9 +93,9 @@ public static Constraint noDirectCycles(Class<? extends Edge> pEdgeType, /* * There can't be both an association and an aggregation edge between two nodes */ - public static Constraint noCombinedAssociationAggregation(Edge pEdge, Node pStart, Node pEnd) + public static Constraint noCombinedAssociationAggregation() { - return () -> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram) -> { if( pEdge.getClass() != AssociationEdge.class && pEdge.getClass() != AggregationEdge.class ) { @@ -105,4 +114,4 @@ public static Constraint noCombinedAssociationAggregation(Edge pEdge, Node pStar return true; }; } -} +} \ No newline at end of file diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/Constraint.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/Constraint.java index b4f40a4bb..f0dc0195e 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/Constraint.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/Constraint.java @@ -21,6 +21,11 @@ package ca.mcgill.cs.jetuml.diagram.builder.constraints; +import ca.mcgill.cs.jetuml.diagram.Diagram; +import ca.mcgill.cs.jetuml.diagram.Edge; +import ca.mcgill.cs.jetuml.diagram.Node; +import ca.mcgill.cs.jetuml.geom.Point; + /** * Represents a generic constraint. */ @@ -30,5 +35,5 @@ public interface Constraint * Indicates if the constraint is satisfied. * @return True if this constraint is satisfied. */ - boolean satisfied(); -} + boolean satisfied(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram); +} \ No newline at end of file diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ConstraintSet.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ConstraintSet.java index 3e3c11b1d..205280cb3 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ConstraintSet.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ConstraintSet.java @@ -25,6 +25,11 @@ import java.util.HashSet; import java.util.Set; +import ca.mcgill.cs.jetuml.diagram.Diagram; +import ca.mcgill.cs.jetuml.diagram.Edge; +import ca.mcgill.cs.jetuml.diagram.Node; +import ca.mcgill.cs.jetuml.geom.Point; + /** * Represents a set of constraints. Constraint sets are not meant to * be reused, so they do not have a method to clear the set. The intended @@ -47,32 +52,19 @@ public ConstraintSet( Constraint... pConstraints ) assert pConstraints != null; aConstraints.addAll(Arrays.asList(pConstraints)); } - - /** - * Add all constraints in pConstraintSet into this - * set. - * - * @param pConstraintSet The set to merge into this set. - * @pre pConstraintSet != null; - */ - public void merge( ConstraintSet pConstraintSet ) - { - assert pConstraintSet != null; - pConstraintSet.aConstraints.forEach( constraint -> aConstraints.add(constraint )); - } - + /** * @return True if and only if all the constraints in the set are satisfied. */ - public boolean satisfied() + public boolean satisfied(Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram) { for( Constraint constraint : aConstraints ) { - if( !constraint.satisfied() ) + if( !constraint.satisfied(pEdge, pStart, pEnd, pStartPoint, pEndPoint, pDiagram)) { return false; } } return true; } -} +} \ No newline at end of file diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/EdgeConstraints.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/EdgeConstraints.java index f658b602d..56dcc45a3 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/EdgeConstraints.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/EdgeConstraints.java @@ -27,6 +27,7 @@ import ca.mcgill.cs.jetuml.diagram.edges.NoteEdge; import ca.mcgill.cs.jetuml.diagram.nodes.NoteNode; import ca.mcgill.cs.jetuml.diagram.nodes.PointNode; +import ca.mcgill.cs.jetuml.geom.Point; /** * Methods to create edge addition constraints that apply to @@ -41,9 +42,10 @@ private EdgeConstraints() {} * - Any node and a note node. * - A note node and a point node. */ - public static Constraint noteEdge(Edge pEdge, Node pStart, Node pEnd) + public static Constraint noteEdge() { - return ()-> !( pEdge.getClass() == NoteEdge.class && + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> + !( pEdge.getClass() == NoteEdge.class && !((pStart.getClass() == NoteNode.class && pEnd.getClass() == PointNode.class) || (pEnd.getClass() == NoteNode.class))); @@ -52,9 +54,9 @@ public static Constraint noteEdge(Edge pEdge, Node pStart, Node pEnd) /* * An edge can only be added to or from a note node if it is a note edge */ - public static Constraint noteNode(Edge pEdge, Node pStart, Node pEnd) + public static Constraint noteNode() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { if( pStart.getClass() == NoteNode.class || pEnd.getClass() == NoteNode.class ) { @@ -67,10 +69,10 @@ public static Constraint noteNode(Edge pEdge, Node pStart, Node pEnd) /* * Only pNumber of edges of the same type are allowed in one direction between two nodes */ - public static Constraint maxEdges(Edge pEdge, Node pStart, Node pEnd, Diagram pDiagram, int pNumber) + public static Constraint maxEdges(int pNumber) { assert pNumber > 0; - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return numberOfEdges(pEdge.getClass(), pStart, pEnd, pDiagram) <= pNumber-1; }; @@ -79,9 +81,9 @@ public static Constraint maxEdges(Edge pEdge, Node pStart, Node pEnd, Diagram pD /* * Self-edges are not allowed. */ - public static Constraint noSelfEdge(Node pStart, Node pEnd) + public static Constraint noSelfEdge() { - return ()-> { return pStart != pEnd; }; + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return pStart != pEnd; }; } /* @@ -100,4 +102,4 @@ private static int numberOfEdges(Class<? extends Edge> pType, Node pStart, Node } return result; } -} +} \ No newline at end of file diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ObjectDiagramEdgeConstraints.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ObjectDiagramEdgeConstraints.java index 1a957f4c3..2c62beae2 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ObjectDiagramEdgeConstraints.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/ObjectDiagramEdgeConstraints.java @@ -21,12 +21,14 @@ package ca.mcgill.cs.jetuml.diagram.builder.constraints; +import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.Edge; import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.edges.ObjectCollaborationEdge; import ca.mcgill.cs.jetuml.diagram.edges.ObjectReferenceEdge; import ca.mcgill.cs.jetuml.diagram.nodes.FieldNode; import ca.mcgill.cs.jetuml.diagram.nodes.ObjectNode; +import ca.mcgill.cs.jetuml.geom.Point; /** * Methods to create edge addition constraints that only apply to @@ -39,9 +41,9 @@ private ObjectDiagramEdgeConstraints() {} /* * A collaboration edge can only be between two object nodes */ - public static Constraint collaboration(Edge pEdge, Node pStart, Node pEnd) + public static Constraint collaboration() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pEdge.getClass() == ObjectCollaborationEdge.class && (pStart.getClass() != ObjectNode.class || pEnd.getClass() != ObjectNode.class)); @@ -51,12 +53,12 @@ public static Constraint collaboration(Edge pEdge, Node pStart, Node pEnd) /* * A reference edge can only be between an object node and a field node. */ - public static Constraint reference(Edge pEdge, Node pStart, Node pEnd) + public static Constraint reference() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pEdge.getClass() == ObjectReferenceEdge.class && (pStart.getClass() != FieldNode.class || pEnd.getClass() != ObjectNode.class)); }; } -} +} \ No newline at end of file diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/SequenceDiagramEdgeConstraints.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/SequenceDiagramEdgeConstraints.java index 31810de3b..893529558 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/SequenceDiagramEdgeConstraints.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/SequenceDiagramEdgeConstraints.java @@ -45,9 +45,9 @@ private SequenceDiagramEdgeConstraints() {} /* * No edge is allowed to start in a parameter node. */ - public static Constraint noEdgesFromParameterTop(Node pStart, Point pStartPoint) + public static Constraint noEdgesFromParameterTop() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pStart.getClass() == ImplicitParameterNode.class && IMPLICIT_PARAMETER_NODE_VIEWER.getTopRectangle(pStart).contains(pStartPoint)); @@ -58,11 +58,12 @@ public static Constraint noEdgesFromParameterTop(Node pStart, Point pStartPoint) * For a return edge, the end node has to be the caller, and return * edges on self-calls are not allowed. */ - public static Constraint returnEdge(Edge pEdge, Node pStart, Node pEnd, Diagram pDiagram) + public static Constraint returnEdge() { - ControlFlow flow = new ControlFlow(pDiagram); - return ()-> + //ControlFlow flow = new ControlFlow(pDiagram); + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { + ControlFlow flow = new ControlFlow(pDiagram); return !(pEdge.getClass() == ReturnEdge.class && (pStart.getClass() != CallNode.class || pEnd.getClass() != CallNode.class || @@ -76,14 +77,14 @@ public static Constraint returnEdge(Edge pEdge, Node pStart, Node pEnd, Diagram * Call edges that land on a parameter node must land on the lifeline part, * except if it is allowed to create a constructor. */ - public static Constraint callEdgeEnd(Edge pEdge, Node pStartNode, Node pEndNode, Point pEndPoint, Diagram pDiagram) + public static Constraint callEdgeEnd() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pEdge.getClass() == CallEdge.class && - pEndNode.getClass() == ImplicitParameterNode.class && - IMPLICIT_PARAMETER_NODE_VIEWER.getTopRectangle(pEndNode).contains(pEndPoint) && - !canCreateConstructor(pStartNode, pEndNode, pDiagram, pEndPoint)); + pEnd.getClass() == ImplicitParameterNode.class && + IMPLICIT_PARAMETER_NODE_VIEWER.getTopRectangle(pEnd).contains(pEndPoint) && + !canCreateConstructor(pStart, pEnd, pDiagram, pEndPoint)); }; } @@ -97,12 +98,12 @@ private static boolean canCreateConstructor(Node pStartNode, Node pEndNode, Diag * It's only legal to start an interaction on a parameter node if there are no existing activations * in the diagram. */ - public static Constraint singleEntryPoint(Edge pEdge, Node pStartNode, Diagram pDiagram) + public static Constraint singleEntryPoint() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pEdge.getClass() == CallEdge.class && - pStartNode.getClass() == ImplicitParameterNode.class && + pStart.getClass() == ImplicitParameterNode.class && new ControlFlow(pDiagram).hasEntryPoint()); }; } diff --git a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/StateDiagramEdgeConstraints.java b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/StateDiagramEdgeConstraints.java index ca1115c61..71cd5f1cc 100644 --- a/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/StateDiagramEdgeConstraints.java +++ b/src/ca/mcgill/cs/jetuml/diagram/builder/constraints/StateDiagramEdgeConstraints.java @@ -21,11 +21,13 @@ package ca.mcgill.cs.jetuml.diagram.builder.constraints; +import ca.mcgill.cs.jetuml.diagram.Diagram; import ca.mcgill.cs.jetuml.diagram.Edge; import ca.mcgill.cs.jetuml.diagram.Node; import ca.mcgill.cs.jetuml.diagram.edges.NoteEdge; import ca.mcgill.cs.jetuml.diagram.nodes.FinalStateNode; import ca.mcgill.cs.jetuml.diagram.nodes.InitialStateNode; +import ca.mcgill.cs.jetuml.geom.Point; /** * Methods to create edge addition constraints that only apply to @@ -38,9 +40,9 @@ private StateDiagramEdgeConstraints() {} /* * No edges are allowed into an Initial Node */ - public static Constraint noEdgeToInitialNode(Node pEnd) + public static Constraint noEdgeToInitialNode() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return pEnd.getClass() != InitialStateNode.class; }; @@ -49,11 +51,11 @@ public static Constraint noEdgeToInitialNode(Node pEnd) /* * The only edge allowed out of a FinalNode is a NoteEdge */ - public static Constraint noEdgeFromFinalNode(Edge pEdge, Node pStart) + public static Constraint noEdgeFromFinalNode() { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { return !(pStart.getClass() == FinalStateNode.class && pEdge.getClass() != NoteEdge.class ); }; } -} +} \ No newline at end of file diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestClassDiagramEdgeConstraints.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestClassDiagramEdgeConstraints.java index 0575bf1ba..f343d2339 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestClassDiagramEdgeConstraints.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestClassDiagramEdgeConstraints.java @@ -43,6 +43,7 @@ public class TestClassDiagramEdgeConstraints private ClassNode aNode2; private DependencyEdge aEdge1; private GeneralizationEdge aGen1; + private Point aPoint; @BeforeAll public static void setupClass() @@ -58,6 +59,7 @@ public void setUp() aNode2 = new ClassNode(); aEdge1 = new DependencyEdge(); aGen1 = new GeneralizationEdge(); + aPoint = new Point(0,0); } private void createDiagram() @@ -71,32 +73,30 @@ private void createDiagram() public void testNoSelfGeneralizationNotAGeneralizationEdge() { createDiagram(); - assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization(aEdge1, aNode1, aNode2).satisfied()); - assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization(aEdge1, aNode1, aNode1).satisfied()); + assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization().satisfied(aEdge1, aNode1, new ClassNode(), aPoint, aPoint, aDiagram)); + assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization().satisfied(aEdge1, aNode1, aNode1, aPoint, aPoint, aDiagram)); } @Test public void testNoSelfGeneralizationGeneralizationEdge() { createDiagram(); - assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization(aGen1, aNode1, aNode2).satisfied()); - assertFalse(ClassDiagramEdgeConstraints.noSelfGeneralization(aGen1, aNode1, aNode1).satisfied()); + assertTrue(ClassDiagramEdgeConstraints.noSelfGeneralization().satisfied(aGen1, aNode1, aNode2,aPoint, aPoint, aDiagram)); + assertFalse(ClassDiagramEdgeConstraints.noSelfGeneralization().satisfied(aGen1, aNode1, aNode1,aPoint, aPoint, aDiagram)); } @Test public void testNoDirectCycles_NotADependency() { createDiagram(); - assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class, - new GeneralizationEdge(), aNode1, aNode2).satisfied()); + assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class).satisfied(new GeneralizationEdge(), aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testNoDirectCycles_NoExistingEdge() { createDiagram(); - assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class, - aEdge1, aNode1, aNode2).satisfied()); + assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class).satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test @@ -106,8 +106,7 @@ public void testNoDirectCycles_NoExistingDependencyEdge() GeneralizationEdge edge = new GeneralizationEdge(); edge.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(edge); - assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class, - aEdge1, aNode1, aNode2).satisfied()); + assertTrue(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class).satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test @@ -117,7 +116,6 @@ public void testNoDirectCycles_False() DependencyEdge edge = new DependencyEdge(); edge.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(edge); - assertFalse(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class, - aEdge1, aNode2, aNode1).satisfied()); + assertFalse(ClassDiagramEdgeConstraints.noDirectCycles(DependencyEdge.class).satisfied(aEdge1, aNode2, aNode1, aPoint, aPoint, aDiagram)); } } diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestConstraintSet.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestConstraintSet.java index ced90f3b1..21a33c894 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestConstraintSet.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestConstraintSet.java @@ -21,7 +21,6 @@ package ca.mcgill.cs.jetuml.diagram.builder.constraints; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -31,13 +30,22 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import ca.mcgill.cs.jetuml.diagram.Diagram; +import ca.mcgill.cs.jetuml.diagram.DiagramType; +import ca.mcgill.cs.jetuml.diagram.Edge; +import ca.mcgill.cs.jetuml.diagram.Node; +import ca.mcgill.cs.jetuml.diagram.edges.DependencyEdge; +import ca.mcgill.cs.jetuml.diagram.nodes.ClassNode; +import ca.mcgill.cs.jetuml.geom.Point; + public class TestConstraintSet { private Set<String> aMessages; + private DependencyEdge aEdge1; private Constraint constraint(String pMessage, boolean pReturn) { - return ()-> + return (Edge pEdge, Node pStart, Node pEnd, Point pStartPoint, Point pEndPoint, Diagram pDiagram)-> { aMessages.add(pMessage); return pReturn; @@ -48,71 +56,34 @@ private Constraint constraint(String pMessage, boolean pReturn) public void setUp() { aMessages = new HashSet<>(); + aEdge1 = new DependencyEdge(); } @Test public void testEmpty() { ConstraintSet constraints = new ConstraintSet(); - assertTrue(constraints.satisfied()); - } - - @Test - public void testMergeIntoEmpty() - { - ConstraintSet set1 = new ConstraintSet(); - ConstraintSet set2 = new ConstraintSet(constraint("A", true), constraint("B", true)); - set1.merge(set2); - set1.satisfied(); - assertEquals(2, aMessages.size()); - assertTrue(aMessages.contains("A")); - assertTrue(aMessages.contains("B")); + assertTrue(constraints.satisfied(aEdge1, new ClassNode(), new ClassNode(), new Point(0,0), new Point(0,0), new Diagram(DiagramType.CLASS))); } - - @Test - public void testMergeEmpty() - { - ConstraintSet set1 = new ConstraintSet(); - ConstraintSet set2 = new ConstraintSet(constraint("A", true), constraint("B", true)); - set2.merge(set1); - set2.satisfied(); - assertEquals(2, aMessages.size()); - assertTrue(aMessages.contains("A")); - assertTrue(aMessages.contains("B")); - } - - @Test - public void testMergeNonEmptyNonEmpty() - { - ConstraintSet set1 = new ConstraintSet(constraint("X", true), constraint("Y", true)); - ConstraintSet set2 = new ConstraintSet(constraint("A", true), constraint("B", true)); - set2.merge(set1); - set2.satisfied(); - assertEquals(4, aMessages.size()); - assertTrue(aMessages.contains("A")); - assertTrue(aMessages.contains("B")); - assertTrue(aMessages.contains("X")); - assertTrue(aMessages.contains("Y")); - } - + @Test public void testSatisfiedAllFalse() { ConstraintSet set1 = new ConstraintSet(constraint("X", false), constraint("Y", false), constraint("Z", false)); - assertFalse(set1.satisfied()); + assertFalse(set1.satisfied(aEdge1, new ClassNode(), new ClassNode(), new Point(0,0), new Point(0,0), new Diagram(DiagramType.CLASS))); } @Test public void testSatisfiedSomeFalse() { ConstraintSet set1 = new ConstraintSet(constraint("X", true), constraint("Y", true), constraint("Z", false)); - assertFalse(set1.satisfied()); + assertFalse(set1.satisfied(aEdge1, new ClassNode(), new ClassNode(), new Point(0,0), new Point(0,0), new Diagram(DiagramType.CLASS))); } @Test public void testSatisfiedTrue() { ConstraintSet set1 = new ConstraintSet(constraint("X", true), constraint("Y", true), constraint("Z", true)); - assertTrue(set1.satisfied()); + assertTrue(set1.satisfied(aEdge1, new ClassNode(), new ClassNode(), new Point(0,0), new Point(0,0), new Diagram(DiagramType.CLASS))); } } diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestEdgeConstraints.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestEdgeConstraints.java index fc6343fc9..f0ac22758 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestEdgeConstraints.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestEdgeConstraints.java @@ -43,10 +43,12 @@ public class TestEdgeConstraints private Diagram aDiagram; private ClassNode aNode1; private ClassNode aNode2; - private PointNode aPoint; + private PointNode aPointNode; private DependencyEdge aEdge1; private NoteEdge aNoteEdge; private NoteNode aNote; + private Point aPoint; + @BeforeAll public static void setupClass() @@ -61,9 +63,10 @@ public void setUp() aNode1 = new ClassNode(); aNode2 = new ClassNode(); aNote = new NoteNode(); - aPoint = new PointNode(); + aPointNode = new PointNode(); aEdge1 = new DependencyEdge(); aNoteEdge = new NoteEdge(); + aPoint = new Point(0,0); } private void createDiagram() @@ -73,98 +76,98 @@ private void createDiagram() aDiagram.addRootNode(aNode1); aDiagram.addRootNode(aNode2); aDiagram.addRootNode(aNote); - aPoint.moveTo(new Point(200,200)); - aDiagram.addRootNode(aPoint); + aPointNode.moveTo(new Point(200,200)); + aDiagram.addRootNode(aPointNode); } @Test public void testNoteEdgeNotNoteEdge() { createDiagram(); - assertTrue(EdgeConstraints.noteEdge(aEdge1, aNode1, aNode2).satisfied()); + assertTrue(EdgeConstraints.noteEdge().satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testNoteEdgeNodeNotePoint() { createDiagram(); - assertTrue(EdgeConstraints.noteEdge(aNoteEdge, aNote, aPoint).satisfied()); + assertTrue(EdgeConstraints.noteEdge().satisfied(aNoteEdge, aNote, aPointNode, aPoint, aPoint, aDiagram)); } @Test public void testNoteEdgeNodeNoteNotPoint() { createDiagram(); - assertFalse(EdgeConstraints.noteEdge(aNoteEdge, aNote, aNode1).satisfied()); + assertFalse(EdgeConstraints.noteEdge().satisfied(aNoteEdge, aNote, aNode1, aPoint, aPoint, aDiagram)); } @Test public void testNoteEdgeNodeNoteNotePoint() { createDiagram(); - assertFalse(EdgeConstraints.noteEdge(aNoteEdge, aNode1, aPoint).satisfied()); + assertFalse(EdgeConstraints.noteEdge().satisfied(aNoteEdge, aNode1, aPointNode, aPoint, aPoint, aDiagram)); } @Test public void testNoteEdgeNodeAnyNode() { createDiagram(); - assertTrue(EdgeConstraints.noteEdge(aNoteEdge, aNode1, aNote).satisfied()); + assertTrue(EdgeConstraints.noteEdge().satisfied(aNoteEdge, aNode1, aNote, aPoint, aPoint, aDiagram)); } @Test public void testNoteNodeAnyAny() { createDiagram(); - assertTrue(EdgeConstraints.noteNode(aEdge1, aNode1, aNode2).satisfied()); + assertTrue(EdgeConstraints.noteNode().satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testNoteNodeNoteAny() { createDiagram(); - assertFalse(EdgeConstraints.noteNode(aEdge1, aNote, aNode2).satisfied()); - assertTrue(EdgeConstraints.noteNode(aNoteEdge, aNote, aNode2).satisfied()); + assertFalse(EdgeConstraints.noteNode().satisfied(aEdge1, aNote, aNode2, aPoint, aPoint, aDiagram)); + assertTrue(EdgeConstraints.noteNode().satisfied(aNoteEdge, aNote, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testNoteNodeAnyNote() { createDiagram(); - assertFalse(EdgeConstraints.noteNode(aEdge1, aNode1, aNote).satisfied()); - assertTrue(EdgeConstraints.noteNode(aNoteEdge, aNode1, aNote).satisfied()); + assertFalse(EdgeConstraints.noteNode().satisfied(aEdge1, aNode1, aNote, aPoint, aPoint, aDiagram)); + assertTrue(EdgeConstraints.noteNode().satisfied(aNoteEdge, aNode1, aNote, aPoint, aPoint, aDiagram)); } @Test public void testNoteNodeNoteNote() { createDiagram(); - assertFalse(EdgeConstraints.noteNode(aEdge1, aNote, aNote).satisfied()); - assertTrue(EdgeConstraints.noteNode(aNoteEdge, aNote, aNote).satisfied()); + assertFalse(EdgeConstraints.noteNode().satisfied(aEdge1, aNote, aNote, aPoint, aPoint, aDiagram)); + assertTrue(EdgeConstraints.noteNode().satisfied(aNoteEdge, aNote, aNote, aPoint, aPoint, aDiagram)); } @Test public void testMaxEdgesOne() { createDiagram(); - assertTrue(EdgeConstraints.maxEdges(aEdge1, aNode1, aNode2, aDiagram, 1).satisfied()); + assertTrue(EdgeConstraints.maxEdges(1).satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); - assertFalse(EdgeConstraints.maxEdges(new DependencyEdge(), aNode1, aNode2, aDiagram, 1).satisfied()); + assertFalse(EdgeConstraints.maxEdges(1).satisfied(new DependencyEdge(), aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testMaxEdgesTwo() { createDiagram(); - assertTrue(EdgeConstraints.maxEdges(aEdge1, aNode1, aNode2, aDiagram, 2).satisfied()); + assertTrue(EdgeConstraints.maxEdges(2).satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); - assertTrue(EdgeConstraints.maxEdges(new DependencyEdge(), aNode1, aNode2, aDiagram, 2).satisfied()); - DependencyEdge edge = new DependencyEdge(); + assertTrue(EdgeConstraints.maxEdges(2).satisfied(new DependencyEdge(), aNode1, aNode2, aPoint, aPoint, aDiagram)); + DependencyEdge edge = aEdge1; edge.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(edge); - assertFalse(EdgeConstraints.maxEdges(new DependencyEdge(), aNode1, aNode2, aDiagram, 2).satisfied()); + assertFalse(EdgeConstraints.maxEdges(2).satisfied(new DependencyEdge(), aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test @@ -174,7 +177,7 @@ public void testMaxEdgesNodesMatchNoMatch() aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); ClassNode node3 = new ClassNode(); - assertTrue(EdgeConstraints.maxEdges(new DependencyEdge(), aNode1, node3, aDiagram, 1).satisfied()); + assertTrue(EdgeConstraints.maxEdges(1).satisfied(new DependencyEdge(), aNode1, node3, aPoint, aPoint, aDiagram)); } @Test @@ -184,7 +187,7 @@ public void testMaxEdgesNodesNoMatchMatch() aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); ClassNode node3 = new ClassNode(); - assertTrue(EdgeConstraints.maxEdges(new DependencyEdge(), node3, aNode2, aDiagram, 1).satisfied()); + assertTrue(EdgeConstraints.maxEdges(1).satisfied(aEdge1, node3, aNode2, aPoint, aPoint, aDiagram)); } @Test @@ -194,7 +197,7 @@ public void testMaxEdgesNodesNoMatchNoMatch() aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); ClassNode node3 = new ClassNode(); - assertTrue(EdgeConstraints.maxEdges(new DependencyEdge(), node3, new ClassNode(), aDiagram, 1).satisfied()); + assertTrue(EdgeConstraints.maxEdges(1).satisfied(aEdge1, node3, new ClassNode(), aPoint, aPoint, aDiagram)); } @Test @@ -203,20 +206,20 @@ public void testMaxEdgesNodesDifferentEdgeType() createDiagram(); aEdge1.connect(aNode1, aNode2, aDiagram); aDiagram.addEdge(aEdge1); - assertTrue(EdgeConstraints.maxEdges(new NoteEdge(), aNode1, aNode2, aDiagram, 1).satisfied()); + assertTrue(EdgeConstraints.maxEdges(1).satisfied(new NoteEdge(), aNode1, aNode2, aPoint, aPoint, aDiagram )); } @Test public void testNodeSelfEdgeTrue() { createDiagram(); - assertTrue(EdgeConstraints.noSelfEdge(aNode1, aNode2).satisfied()); + assertTrue(EdgeConstraints.noSelfEdge().satisfied(aEdge1, aNode1, aNode2, aPoint, aPoint, aDiagram)); } @Test public void testNodeSelfEdgeFalse() { createDiagram(); - assertFalse(EdgeConstraints.noSelfEdge(aNode1, aNode1).satisfied()); + assertFalse(EdgeConstraints.noSelfEdge().satisfied(aEdge1, aNode1, aNode1, aPoint, aPoint, aDiagram)); } } diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestObjectDiagramEdgeConstraints.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestObjectDiagramEdgeConstraints.java index dbc9d85fb..d22448c28 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestObjectDiagramEdgeConstraints.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestObjectDiagramEdgeConstraints.java @@ -45,6 +45,7 @@ public class TestObjectDiagramEdgeConstraints private FieldNode aField1; private ObjectCollaborationEdge aCollaboration1; private ObjectReferenceEdge aReference1; + private Point aPoint; @BeforeAll public static void setupClass() @@ -61,6 +62,7 @@ public void setUp() aField1 = new FieldNode(); aCollaboration1 = new ObjectCollaborationEdge(); aReference1 = new ObjectReferenceEdge(); + aPoint = new Point(0,0); } private void createDiagram() @@ -75,56 +77,56 @@ private void createDiagram() public void testCollaborationNotCollaborationEdge() { createDiagram(); - assertTrue(ObjectDiagramEdgeConstraints.collaboration(aReference1, aObject1, aObject2).satisfied()); + assertTrue(ObjectDiagramEdgeConstraints.collaboration().satisfied(aReference1, aObject1, aObject2, aPoint, aPoint, aDiagram)); } @Test public void testCollaborationCollaborationNotCorrectStartNode() { createDiagram(); - assertFalse(ObjectDiagramEdgeConstraints.collaboration(aCollaboration1, aField1, aObject2).satisfied()); + assertFalse(ObjectDiagramEdgeConstraints.collaboration().satisfied(aCollaboration1, aField1, aObject2, aPoint, aPoint, aDiagram)); } @Test public void testCollaborationCollaborationNotCorrectEndNode() { createDiagram(); - assertFalse(ObjectDiagramEdgeConstraints.collaboration(aCollaboration1, aObject2, aField1).satisfied()); + assertFalse(ObjectDiagramEdgeConstraints.collaboration().satisfied(aCollaboration1, aObject2, aField1, aPoint, aPoint, aDiagram)); } @Test public void testCollaborationCollaborationCorrect() { createDiagram(); - assertTrue(ObjectDiagramEdgeConstraints.collaboration(aCollaboration1, aObject2, aObject2).satisfied()); + assertTrue(ObjectDiagramEdgeConstraints.collaboration().satisfied(aCollaboration1, aObject2, aObject2, aPoint, aPoint, aDiagram)); } @Test public void testReferenceNotReference() { createDiagram(); - assertTrue(ObjectDiagramEdgeConstraints.reference(aCollaboration1, aField1, aObject2).satisfied()); + assertTrue(ObjectDiagramEdgeConstraints.reference().satisfied(aCollaboration1, aField1, aObject2, aPoint, aPoint, aDiagram)); } @Test public void testReferenceReferenceNotCorrectStart() { createDiagram(); - assertFalse(ObjectDiagramEdgeConstraints.reference(aReference1, aObject1, aObject2).satisfied()); + assertFalse(ObjectDiagramEdgeConstraints.reference().satisfied(aReference1, aObject1, aObject2, aPoint, aPoint, aDiagram)); } @Test public void testReferenceReferenceNotCorrectEnd() { createDiagram(); - assertFalse(ObjectDiagramEdgeConstraints.reference(aReference1, aField1, aField1).satisfied()); + assertFalse(ObjectDiagramEdgeConstraints.reference().satisfied(aReference1, aField1, aField1, aPoint, aPoint, aDiagram)); } @Test public void testReferenceReferenceCorrect() { createDiagram(); - assertTrue(ObjectDiagramEdgeConstraints.reference(aReference1, aField1, aObject2).satisfied()); + assertTrue(ObjectDiagramEdgeConstraints.reference().satisfied(aReference1, aField1, aObject2, aPoint, aPoint, aDiagram)); } diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestSequenceDiagramEdgeConstraints.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestSequenceDiagramEdgeConstraints.java index 1e2fb7e76..9ec4a18bf 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestSequenceDiagramEdgeConstraints.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestSequenceDiagramEdgeConstraints.java @@ -47,6 +47,7 @@ public class TestSequenceDiagramEdgeConstraints private CallNode aCallNode3; private CallEdge aCallEdge; private ReturnEdge aReturnEdge; + private Point aPoint; @BeforeAll public static void setupClass() @@ -65,6 +66,7 @@ public void setUp() aCallNode3 = new CallNode(); aCallEdge = new CallEdge(); aReturnEdge = new ReturnEdge(); + aPoint = new Point(0,0); } private void createDiagram() @@ -80,49 +82,49 @@ private void createDiagram() public void testNoEdgeFromParameterTopNotParameterNode() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop(aCallNode1, new Point(0,0)).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop().satisfied(aCallEdge, aCallNode1, aCallNode1, aPoint, aPoint, aDiagram)); } @Test public void testNoEdgeFromParameterTopParameterFalse() { createDiagram(); - assertFalse(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop(aParameter1, new Point(5,5)).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop().satisfied(aCallEdge, aParameter1, aParameter1,new Point(5,5),aPoint, aDiagram)); } @Test public void testNoEdgeFromParameterTopParameterTrue() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop(aParameter1, new Point(40,65)).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.noEdgesFromParameterTop().satisfied(aCallEdge, aParameter1, aParameter1, new Point(40,65), aPoint, aDiagram)); } @Test public void testreturnEdgeNotReturnEdge() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.returnEdge(aCallEdge, aCallNode1, aCallNode2, aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aCallEdge, aCallNode1, aCallNode2, aPoint, aPoint, aDiagram)); } @Test public void testreturnEdgeIncompatibleStart() { createDiagram(); - assertFalse(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aParameter1, aCallNode2, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aParameter1, aCallNode2, aPoint, aPoint, aDiagram)); } @Test public void testreturnEdgeIncompatibleEnd() { createDiagram(); - assertFalse(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aCallNode1, aParameter2, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aCallNode1, aParameter2, aPoint, aPoint, aDiagram)); } @Test public void testreturnEdgeEndNoCaller() { createDiagram(); - assertFalse(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aCallNode1, aCallNode2, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aCallNode1, aCallNode2, aPoint, aPoint, aDiagram)); } @Test @@ -131,7 +133,7 @@ public void testreturnEdgeEndNotCaller() createDiagram(); aCallEdge.connect(aCallNode1, aCallNode2, aDiagram); aDiagram.addEdge(aCallEdge); - assertFalse(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aCallNode2, aCallNode3, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aCallNode2, aCallNode3, aPoint, aPoint, aDiagram)); } @Test @@ -140,7 +142,7 @@ public void testreturnEdgeSelfCaller() createDiagram(); aCallEdge.connect(aCallNode1, aCallNode3, aDiagram); aDiagram.addEdge(aCallEdge); - assertFalse(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aCallNode3, aCallNode1, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aCallNode3, aCallNode1, aPoint, aPoint, aDiagram)); } @Test @@ -149,62 +151,62 @@ public void testreturnEdgeValid() createDiagram(); aCallEdge.connect(aCallNode1, aCallNode2, aDiagram); aDiagram.addEdge(aCallEdge); - assertTrue(SequenceDiagramEdgeConstraints.returnEdge(aReturnEdge, aCallNode2, aCallNode1, aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.returnEdge().satisfied(aReturnEdge, aCallNode2, aCallNode1, aPoint, aPoint, aDiagram)); } @Test public void testCallEdgeEndNotCallEdge() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd(aReturnEdge, aCallNode2, aCallNode1, new Point(10,10), aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd().satisfied(aReturnEdge, aCallNode2, aCallNode1, aPoint, new Point(10,10), aDiagram)); } @Test public void testCallEdgeEndEndNotParameter() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd(aCallEdge, aCallNode2, aCallNode1, new Point(10,10), aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd().satisfied(aCallEdge, aCallNode2, aCallNode1, aPoint, new Point(10,10), aDiagram)); } @Test public void testCallEdgeEndEndOnLifeLine() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd(aCallEdge, aParameter2, aCallNode1, new Point(0,85), aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd().satisfied(aCallEdge, aParameter2, aCallNode1, aPoint, new Point(0,85), aDiagram)); } @Test public void testCallEdgeEndEndOnTopRectangle() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd(aCallEdge, aParameter2, aCallNode1, new Point(0,5), aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.callEdgeEnd().satisfied(aCallEdge, aParameter2, aCallNode1, aPoint, new Point(0,5), aDiagram)); } @Test public void testSingleEntryPointNotACallEdge() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint(aReturnEdge, aParameter1, aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint().satisfied(aReturnEdge, aParameter1, aParameter1, aPoint, aPoint, aDiagram)); } @Test public void testSingleEntryPointNotStartingOnAParameterNode() { createDiagram(); - assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint(aCallEdge, aCallNode1, aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint().satisfied(aCallEdge, aCallNode1, aCallNode1, aPoint, aPoint, aDiagram)); } @Test public void testSingleEntryPointStartingOnParameterNodeNotSatisfied() { createDiagram(); - assertFalse(SequenceDiagramEdgeConstraints.singleEntryPoint(aCallEdge, aParameter1, aDiagram).satisfied()); + assertFalse(SequenceDiagramEdgeConstraints.singleEntryPoint().satisfied(aCallEdge, aParameter1, aParameter1, aPoint, aPoint, aDiagram)); } @Test public void testSingleEntryPointStartingOnParameterNodeSatisfied() { aDiagram.addRootNode(aParameter1); - assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint(aCallEdge, aParameter1, aDiagram).satisfied()); + assertTrue(SequenceDiagramEdgeConstraints.singleEntryPoint().satisfied(aCallEdge, aParameter1, aParameter1, aPoint, aPoint, aDiagram)); } } \ No newline at end of file diff --git a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestStateDiagramEdgeConstraints.java b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestStateDiagramEdgeConstraints.java index ee0a18951..d5e538b7b 100644 --- a/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestStateDiagramEdgeConstraints.java +++ b/test/ca/mcgill/cs/jetuml/diagram/builder/constraints/TestStateDiagramEdgeConstraints.java @@ -36,6 +36,7 @@ import ca.mcgill.cs.jetuml.diagram.nodes.FinalStateNode; import ca.mcgill.cs.jetuml.diagram.nodes.InitialStateNode; import ca.mcgill.cs.jetuml.diagram.nodes.StateNode; +import ca.mcgill.cs.jetuml.geom.Point; public class TestStateDiagramEdgeConstraints { @@ -44,6 +45,7 @@ public class TestStateDiagramEdgeConstraints private InitialStateNode aInitialNode; private FinalStateNode aFinalNode; private StateTransitionEdge aEdge; + private Point aPoint; @BeforeAll public static void setupClass() @@ -59,6 +61,7 @@ public void setUp() aInitialNode = new InitialStateNode(); aFinalNode = new FinalStateNode(); aEdge = new StateTransitionEdge(); + aPoint = new Point(0,0); } private void createDiagram() @@ -72,34 +75,34 @@ private void createDiagram() public void testNoEdgeToInitialNodeFalse() { createDiagram(); - assertFalse(StateDiagramEdgeConstraints.noEdgeToInitialNode(aInitialNode).satisfied()); + assertFalse(StateDiagramEdgeConstraints.noEdgeToInitialNode().satisfied(aEdge, aState, aInitialNode, aPoint, aPoint, aDiagram)); } @Test public void testNoEdgeToInitialNodeTrue() { createDiagram(); - assertTrue(StateDiagramEdgeConstraints.noEdgeToInitialNode(aState).satisfied()); + assertTrue(StateDiagramEdgeConstraints.noEdgeToInitialNode().satisfied(aEdge, aInitialNode, aState, aPoint, aPoint, aDiagram)); } @Test public void testNoEdgeFromFinalNodeInapplicableEdge() { createDiagram(); - assertTrue(StateDiagramEdgeConstraints.noEdgeFromFinalNode(new NoteEdge(), aFinalNode).satisfied()); + assertTrue(StateDiagramEdgeConstraints.noEdgeFromFinalNode().satisfied(new NoteEdge(), aFinalNode, aState, aPoint, aPoint, aDiagram)); } @Test public void testNoEdgeFromFinalNodeApplicableEdgeFalse() { createDiagram(); - assertFalse(StateDiagramEdgeConstraints.noEdgeFromFinalNode(aEdge, aFinalNode).satisfied()); + assertFalse(StateDiagramEdgeConstraints.noEdgeFromFinalNode().satisfied(aEdge, aFinalNode, aState, aPoint, aPoint, aDiagram)); } @Test public void testNoEdgeFromFinalNodeApplicableEdgeTrue() { createDiagram(); - assertTrue(StateDiagramEdgeConstraints.noEdgeFromFinalNode(aEdge, aState).satisfied()); + assertTrue(StateDiagramEdgeConstraints.noEdgeFromFinalNode().satisfied(aEdge, aState, aState, aPoint, aPoint, aDiagram)); } } \ No newline at end of file