public PointEntity getPosition(String namespace, String id) { Objects.requireNonNull(namespace); Objects.requireNonNull(id); Optional<VertexPositionEntity> first = vertexPositions.stream() .filter(e -> e.getVertexRef().getNamespace().equals(namespace) && e.getVertexRef().getId().equals(id)) .findFirst(); if (first.isPresent()) { VertexPositionEntity vertexPositionEntity = first.get(); return vertexPositionEntity.getPosition(); } return null; }
public static VertexRefEntity toVertexRefEntity(VertexRef vertexRef) { Objects.requireNonNull(vertexRef); VertexRefEntity vertexRefEntity = new VertexRefEntity(); vertexRefEntity.setId(vertexRef.getId()); vertexRefEntity.setNamespace(vertexRef.getNamespace()); return vertexRefEntity; }
public PointEntity getPosition(String namespace, String id) { Objects.requireNonNull(namespace); Objects.requireNonNull(id); Optional<VertexPositionEntity> first = vertexPositions.stream() .filter(e -> e.getVertexRef().getNamespace().equals(namespace) && e.getVertexRef().getId().equals(id)) .findFirst(); if (first.isPresent()) { VertexPositionEntity vertexPositionEntity = first.get(); return vertexPositionEntity.getPosition(); } return null; }
public static VertexRefEntity toVertexRefEntity(VertexRef vertexRef) { Objects.requireNonNull(vertexRef); VertexRefEntity vertexRefEntity = new VertexRefEntity(); vertexRefEntity.setId(vertexRef.getId()); vertexRefEntity.setNamespace(vertexRef.getNamespace()); return vertexRefEntity; }
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }