public static Bounds of(double ulx, double uly, double lrx, double lry) { return new Bounds(ulx, uly, lrx, lry); }
@Test public void testIsValid() { Bounds b = Bounds.of(10.0, 10.0, 13.0, 14.0); assertTrue(b.isValid()); b = Bounds.of(0.0, 0.0, 0.0, 0.0); assertFalse(b.isValid()); b = new Bounds(); assertFalse(b.isValid()); b = Bounds.of(0.0, 10.0, 0.0, 14.0); assertFalse(b.isValid()); b = Bounds.of(10.0, 0.0, 13.0, 0.0); assertFalse(b.isValid()); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((elementId == null) ? 0 : elementId.hashCode()); result = prime * result + ((bounds == null) ? 0 : bounds.hashCode()); result = prime * result + ((children == null) ? 0 : children.hashCode()); return result; }
private void writeBpmnDiagramBounds(Bounds bounds) { if (bounds != null && bounds.isValid()) { startElement(xml.createElement(OMG_DC_URI, "Bounds")); xml.addAttribute(OMG_DC_URI, "height", bounds.getHeight()); xml.addAttribute(OMG_DC_URI, "width", bounds.getWidth()); xml.addAttribute(OMG_DC_URI, "x", bounds.upperLeft.x-xOffset); xml.addAttribute(OMG_DC_URI, "y", bounds.upperLeft.y-yOffset); endElement(); } }
@Test public void testEquals() { double ulx = 11.0; double uly = 12.0; double lrx = 22.0; double lry = 23.0; Bounds b1 = Bounds.of(ulx, uly, lrx, lry); Bounds b2 = Bounds.of(ulx, uly, lrx, lry); assertEquals(b1, b2); assertEquals(b1.hashCode(), b2.hashCode()); b1 = new Bounds().upperLeft(Point.of(ulx, uly)); b2 = new Bounds().upperLeft(Point.of(ulx, uly)); assertEquals(b1, b2); b1 = new Bounds().lowerRight(Point.of(ulx, uly)); b2 = new Bounds().lowerRight(Point.of(ulx, uly)); assertEquals(b1, b2); b1 = new Bounds().upperLeft(Point.of(ulx, uly)); b2 = new Bounds().upperLeft(Point.of(lrx, lry)); assertNotEquals(b1, b2); }
@Test public void testSetLowerRight() { Bounds bounds = new Bounds(); bounds.lowerRight(Point.of(1.0, 2.0)); assertEquals(1.0, bounds.lowerRight.x, 0.0); assertEquals(2.0, bounds.lowerRight.y, 0.0); assertNull(bounds.upperLeft); }
/** * A Node is considered valid if its Bounds are valid * and all the contained children are valid. */ public boolean isValid() { if (bounds == null || !bounds.isValid()) { return false; } if (children != null) { for (Node node : children) { if (!node.isValid()) { return false; } } } return true; }
@Test public void testEnsureCanvas() { Diagram diagram = new Diagram(); assertNotNull(diagram.canvas); assertNotNull(diagram.version); assertEquals(1l, diagram.version.longValue()); diagram = new Diagram(); diagram.version(2l); assertNotNull(diagram.canvas); assertEquals(2l, diagram.version.longValue()); Node canvas = new Node().bounds(Bounds.of(1.0, 2.0, 3.0, 4.0)); diagram = new Diagram() .canvas(canvas) .version(2l); // should stay untouched assertEquals(canvas, diagram.canvas); assertEquals(2l, diagram.version.longValue()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Node other = (Node) obj; if (elementId == null) { if (other.elementId != null) return false; } else if (!elementId.equals(other.elementId)) return false; if (bounds == null) { if (other.bounds != null) return false; } else if (!bounds.equals(other.bounds)) return false; if (children == null) { if (other.children != null) return false; } else if (!children.equals(other.children)) return false; return true; }
/** * A Node is considered valid if its Bounds are valid * and all the contained children are valid. */ public boolean isValid() { if (bounds == null || !bounds.isValid()) { return false; } if (children != null) { for (Node node : children) { if (!node.isValid()) { return false; } } } return true; }
@Test public void testSetCanvas() { Diagram diagram = Diagram.newInstance(); assertNotNull(diagram.canvas); Node canvas = new Node().bounds(Bounds.of(1.0, 2.0, 3.0, 4.0)); assertNotEquals(canvas, diagram.canvas); diagram.canvas(canvas); assertEquals(canvas, diagram.canvas); diagram.canvas(null); assertNull(diagram.canvas); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Node other = (Node) obj; if (elementId == null) { if (other.elementId != null) return false; } else if (!elementId.equals(other.elementId)) return false; if (bounds == null) { if (other.bounds != null) return false; } else if (!bounds.equals(other.bounds)) return false; if (children == null) { if (other.children != null) return false; } else if (!children.equals(other.children)) return false; return true; }
public static Bounds of(double ulx, double uly, double lrx, double lry) { return new Bounds(ulx, uly, lrx, lry); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((elementId == null) ? 0 : elementId.hashCode()); result = prime * result + ((bounds == null) ? 0 : bounds.hashCode()); result = prime * result + ((children == null) ? 0 : children.hashCode()); return result; }
@Test public void testEquals() { Diagram diagram1 = Diagram.newInstance(); Diagram diagram2 = Diagram.newInstance(); assertEquals(diagram1, diagram2); diagram2.canvas(new Node().bounds(Bounds.of(1.0, 2.0, 3.0, 4.0))); assertNotEquals(diagram1, diagram2); diagram1.canvas.bounds(Bounds.of(1.0, 2.0, 3.0, 4.0)); assertEquals(diagram1, diagram2); assertEquals(diagram1.hashCode(), diagram2.hashCode()); diagram2.incVersion(); assertNotEquals(diagram1, diagram2); diagram1.incVersion(); assertEquals(diagram1, diagram2); String edgeId = "e1"; diagram1.addEdge(new Edge().transitionId(edgeId)); assertNotEquals(diagram1, diagram2); diagram2.addEdge(new Edge().transitionId(edgeId)); assertEquals(diagram1, diagram2); }
public Diagram addNode(String activityId, double ulx, double uly, double lrx, double lry) { ensureCanvas(); canvas.addNode(new Node() .elementId(activityId) .bounds(new Bounds(ulx, uly, lrx, lry))); return this; }
public Diagram addNode(String activityId, double ulx, double uly, double lrx, double lry) { ensureCanvas(); canvas.addNode(new Node() .elementId(activityId) .bounds(new Bounds(ulx, uly, lrx, lry))); return this; }
@Test public void testCreateEmptyBounds() { Bounds bounds = new Bounds(); assertNull(bounds.upperLeft); assertNull(bounds.lowerRight); }
double width = Double.valueOf(currentXml.removeAttribute(OMG_DC_URI, "width")); double height = Double.valueOf(currentXml.removeAttribute(OMG_DC_URI, "height")); node.bounds(new Bounds(new Point(x, y), width, height));