private void verifyEdge(final Object source, final Edge edge) { if (!Objects.equals(source, edge.getMatchedVertexValue())) { throw new IllegalArgumentException("Edge must continue the current walk."); } }
public Builder edge(final Edge edge) { if (entities.isEmpty()) { entities.add(new AbstractMap.SimpleEntry<>(edge.getMatchedVertexValue(), Sets.newHashSet())); } else { verifyEdge(entities.getLast().getKey(), edge); } edges.add(Sets.newHashSet(edge)); entities.add(new AbstractMap.SimpleEntry<>(edge.getAdjacentMatchedVertexValue(), Sets.newHashSet())); return this; }
private Builder edgeSet(final Set<Edge> edges) { final Object matchedVertexValue = edges.stream() .findFirst() .orElseThrow(IllegalAccessError::new) .getMatchedVertexValue(); final Object adjacentMatchedVertexValue = edges.stream() .findFirst() .orElseThrow(IllegalAccessError::new) .getAdjacentMatchedVertexValue(); if (entities.isEmpty()) { entities.add(new AbstractMap.SimpleEntry<>(matchedVertexValue, Sets.newHashSet())); } else { final Object root = entities.getLast().getKey(); if (!Objects.equals(root, matchedVertexValue)) { throw new IllegalArgumentException("Edge must continue the current walk."); } } this.edges.add(edges); entities.add(new AbstractMap.SimpleEntry<>(adjacentMatchedVertexValue, Sets.newHashSet())); return this; }
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case SOURCE: return getSource(); case DESTINATION: return getDestination(); case DIRECTED: return isDirected(); case MATCHED_VERTEX: return getMatchedVertexValue(); case ADJACENT_MATCHED_VERTEX: return getAdjacentMatchedVertexValue(); default: return null; } }
@Test public void shouldSetAndGetIdentifiersWithMatchedDestination() { // Given final Edge edge = new Edge.Builder() .group("group") .source("source vertex") .dest("destination vertex") .directed(true) .matchedVertex(EdgeId.MatchedVertex.DESTINATION) .build(); // When/Then assertEquals("destination vertex", edge.getMatchedVertexValue()); assertEquals("destination vertex", edge.getIdentifier(IdentifierType.MATCHED_VERTEX)); assertEquals("source vertex", edge.getIdentifier(IdentifierType.ADJACENT_MATCHED_VERTEX)); assertEquals("source vertex", edge.getAdjacentMatchedVertexValue()); assertTrue(edge.isDirected()); }
@Test public void shouldSetAndGetIdentifiersWithMatchedSourceIsNull() { // Given final Edge edge = new Edge.Builder() .group("group") .source("source vertex") .dest("destination vertex") .directed(true) .matchedVertex(null) .build(); // When/Then assertEquals("source vertex", edge.getMatchedVertexValue()); assertEquals("source vertex", edge.getIdentifier(IdentifierType.MATCHED_VERTEX)); assertEquals("destination vertex", edge.getIdentifier(IdentifierType.ADJACENT_MATCHED_VERTEX)); assertEquals("destination vertex", edge.getIdentifier(IdentifierType.ADJACENT_MATCHED_VERTEX)); assertTrue(edge.isDirected()); }
@Test public void shouldSetAndGetIdentifiersWithMatchedSource() { // Given final Edge edge = new Edge.Builder() .group("group") .source("source vertex") .dest("destination vertex") .directed(true) .matchedVertex(EdgeId.MatchedVertex.SOURCE) .build(); // When/Then assertEquals("source vertex", edge.getMatchedVertexValue()); assertEquals("source vertex", edge.getIdentifier(IdentifierType.MATCHED_VERTEX)); assertEquals("destination vertex", edge.getAdjacentMatchedVertexValue()); assertEquals("destination vertex", edge.getIdentifier(IdentifierType.ADJACENT_MATCHED_VERTEX)); assertTrue(edge.isDirected()); }
private void verifyEdge(final Object source, final Edge edge) { if (!Objects.equals(source, edge.getMatchedVertexValue())) { throw new IllegalArgumentException("Edge must continue the current walk."); } }
public Builder edge(final Edge edge) { if (entities.isEmpty()) { entities.add(new AbstractMap.SimpleEntry<>(edge.getMatchedVertexValue(), Sets.newHashSet())); } else { verifyEdge(entities.getLast().getKey(), edge); } edges.add(Sets.newHashSet(edge)); entities.add(new AbstractMap.SimpleEntry<>(edge.getAdjacentMatchedVertexValue(), Sets.newHashSet())); return this; }
private Builder edgeSet(final Set<Edge> edges) { final Object matchedVertexValue = edges.stream() .findFirst() .orElseThrow(IllegalAccessError::new) .getMatchedVertexValue(); final Object adjacentMatchedVertexValue = edges.stream() .findFirst() .orElseThrow(IllegalAccessError::new) .getAdjacentMatchedVertexValue(); if (entities.isEmpty()) { entities.add(new AbstractMap.SimpleEntry<>(matchedVertexValue, Sets.newHashSet())); } else { final Object root = entities.getLast().getKey(); if (!Objects.equals(root, matchedVertexValue)) { throw new IllegalArgumentException("Edge must continue the current walk."); } } this.edges.add(edges); entities.add(new AbstractMap.SimpleEntry<>(adjacentMatchedVertexValue, Sets.newHashSet())); return this; }
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case SOURCE: return getSource(); case DESTINATION: return getDestination(); case DIRECTED: return isDirected(); case MATCHED_VERTEX: return getMatchedVertexValue(); case ADJACENT_MATCHED_VERTEX: return getAdjacentMatchedVertexValue(); default: return null; } }