public static void validateEquality(final Object original, final Object other) { if (original instanceof Vertex) validateVertexEquality((Vertex) original, (Vertex) other, true); else if (original instanceof VertexProperty) validateVertexPropertyEquality((VertexProperty) original, (VertexProperty) other); else if (original instanceof Edge) validateEdgeEquality((Edge) original, (Edge) other); else if (original instanceof Property) validatePropertyEquality((Property) original, (Property) other); else throw new IllegalArgumentException( "The provided object must be a graph object: " + original.getClass().getCanonicalName()); }
public static void validateVertexEquality( final Vertex originalVertex, final Vertex otherVertex, boolean testEdges) { assertEquals(originalVertex, otherVertex); assertEquals(otherVertex, originalVertex); assertEquals(originalVertex.id(), otherVertex.id()); assertEquals(originalVertex.label(), otherVertex.label()); assertEquals(originalVertex.keys().size(), otherVertex.keys().size()); for (final String key : originalVertex.keys()) { final List<VertexProperty<Object>> originalVertexProperties = IteratorUtils.list(originalVertex.properties(key)); final List<VertexProperty<Object>> otherVertexProperties = IteratorUtils.list(otherVertex.properties(key)); assertEquals(originalVertexProperties.size(), otherVertexProperties.size()); for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) { final VertexProperty<Object> otherVertexProperty = otherVertexProperties .parallelStream() .filter(vp -> vp.equals(originalVertexProperty)) .findAny() .get(); validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty); } } if (testEdges) { Iterator<Edge> originalEdges = IteratorUtils.list(originalVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR) .iterator(); Iterator<Edge> otherEdges = IteratorUtils.list(otherVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR) .iterator(); while (originalEdges.hasNext()) { validateEdgeEquality(originalEdges.next(), otherEdges.next()); } assertFalse(otherEdges.hasNext()); originalEdges = IteratorUtils.list(originalVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR) .iterator(); otherEdges = IteratorUtils.list(otherVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR) .iterator(); while (originalEdges.hasNext()) { validateEdgeEquality(originalEdges.next(), otherEdges.next()); } assertFalse(otherEdges.hasNext()); } }