@Test public void testGetLargestWidth() { final GraphLayer layer1 = createGraphLayer(2); final int expectedSize1 = getExpectSize(2); final GraphLayer layer2 = createGraphLayer(4); final int expectedSize2 = getExpectSize(4); final GraphLayer layer3 = createGraphLayer(1); final int expectedSize3 = getExpectSize(1); final List<GraphLayer> layers = Arrays.asList(layer1, layer2, layer3); final HashMap<Integer, Integer> layersWidth = new HashMap<>(); final int largest = tested.calculateLayersWidth(layers, layersWidth); assertEquals(expectedSize2, largest); assertEquals((int) layersWidth.get(0), expectedSize1); assertEquals((int) layersWidth.get(1), expectedSize2); assertEquals((int) layersWidth.get(2), expectedSize3); }
int calculateLayersWidth(final List<GraphLayer> layers, final HashMap<Integer, Integer> layersWidth) { int largestWidth = 0; for (int i = 0; i < layers.size(); i++) { final GraphLayer layer = layers.get(i); int currentWidth = layer.getVertices().size() * DEFAULT_VERTEX_WIDTH; currentWidth += (layer.getVertices().size() - 1) * DEFAULT_VERTEX_SPACE; layersWidth.put(i, currentWidth); largestWidth = Math.max(largestWidth, currentWidth); } return largestWidth; }
DefaultVertexPositioning implements VertexPositioning { int calculateLayersWidth(final List<GraphLayer> layers, final HashMap<Integer, Integer> layersWidth) { int largestWidth = 0; for (int i = 0; i < layers.size(); i++) { final GraphLayer layer = layers.get(i); int currentWidth = layer.getVertices().size() * DEFAULT_VERTEX_WIDTH; currentWidth += (layer.getVertices().size() - 1) * DEFAULT_VERTEX_SPACE; layersWidth.put(i, currentWidth); largestWidth = Math.max(largestWidth, currentWidth); } return largestWidth; } }
DefaultVertexPositioning implements VertexPositioning { int calculateLayersWidth(final List<GraphLayer> layers, final HashMap<Integer, Integer> layersWidth) { int largestWidth = 0; for (int i = 0; i < layers.size(); i++) { final GraphLayer layer = layers.get(i); int currentWidth = layer.getVertices().size() * DEFAULT_VERTEX_WIDTH; currentWidth += (layer.getVertices().size() - 1) * DEFAULT_VERTEX_SPACE; layersWidth.put(i, currentWidth); largestWidth = Math.max(largestWidth, currentWidth); } return largestWidth; }  }
DefaultVertexPositioning implements VertexPositioning { int calculateLayersWidth(final List<GraphLayer> layers, final HashMap<Integer, Integer> layersWidth) { int largestWidth = 0; for (int i = 0; i < layers.size(); i++) { final GraphLayer layer = layers.get(i); int currentWidth = layer.getVertices().size() * DEFAULT_VERTEX_WIDTH; currentWidth += (layer.getVertices().size() - 1) * DEFAULT_VERTEX_SPACE; layersWidth.put(i, currentWidth); largestWidth = Math.max(largestWidth, currentWidth); } return largestWidth; }  @Override void calculateVerticesPositions(final ReorderedGraph graph,
                                           final LayerArrangement arrangement); boolean removeVirtualVertex(final OrientedEdge edge,
                                       final List<OrientedEdge> edges,
                                       final Set<Vertex> vertices); void removeVirtualVertices(final List<OrientedEdge> edges,
                                      final Set<Vertex> vertices); }
DefaultVertexPositioning implements VertexPositioning { int calculateLayersWidth(final List<GraphLayer> layers, final HashMap<Integer, Integer> layersWidth) { int largestWidth = 0; for (int i = 0; i < layers.size(); i++) { final GraphLayer layer = layers.get(i); int currentWidth = layer.getVertices().size() * DEFAULT_VERTEX_WIDTH; currentWidth += (layer.getVertices().size() - 1) * DEFAULT_VERTEX_SPACE; layersWidth.put(i, currentWidth); largestWidth = Math.max(largestWidth, currentWidth); } return largestWidth; }  @Override void calculateVerticesPositions(final ReorderedGraph graph,
                                           final LayerArrangement arrangement); boolean removeVirtualVertex(final OrientedEdge edge,
                                       final List<OrientedEdge> edges,
                                       final Set<Vertex> vertices); void removeVirtualVertices(final List<OrientedEdge> edges,
                                      final Set<Vertex> vertices);  }