/** * Note this does not include the matchedVertex field. * * @param that the reference EdgeId with which to compare. * @return {@code true} if this object is the same as the edge * argument; {@code false} otherwise. */ default boolean isEqual(final EdgeId that) { return null != that && (new EqualsBuilder() .append(getDirectedType(), that.getDirectedType()) .append(getSource(), that.getSource()) .append(getDestination(), that.getDestination()) .isEquals()); }
@JsonIgnore default Object getAdjacentMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getSource() : getDestination(); }
@JsonIgnore default Object getMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getDestination() : getSource(); }
/** * This is related to an {@link EntityId} if the EntityId's identifier * matches this EdgeId's source or destination. * * @param that the {@link ElementId} to compare * @return An instance of {@link ElementId.Matches} to describe how the ids are related. */ default Matches isRelated(final EntityId that) { boolean matchesSource = (null == getSource()) ? null == that.getVertex() : getSource().equals(that.getVertex()); boolean matchesDestination = (null == getDestination()) ? null == that.getVertex() : getDestination().equals(that.getVertex()); if (matchesSource) { if (matchesDestination) { return Matches.BOTH; } return Matches.SOURCE; } if (matchesDestination) { return Matches.DESTINATION; } return Matches.NONE; }
/** * This is related to an {@link EdgeId} if either the EdgeId's source or * destination matches this EntityId's vertex. * * @param that the {@link EdgeId} to compare * @return An instance of {@link ElementId.Matches} to describe how the seeds are related. */ default Matches isRelated(final EdgeId that) { boolean matchesSource = (null == getVertex()) ? null == that.getSource() : getVertex().equals(that.getSource()); boolean matchesDestination = (null == getVertex()) ? null == that.getDestination() : getVertex().equals(that.getDestination()); if (matchesSource) { if (matchesDestination) { return Matches.BOTH; } return Matches.SOURCE; } if (matchesDestination) { return Matches.DESTINATION; } return Matches.NONE; } }
/** * Note this does not include the matchedVertex field. * * @param that the reference EdgeId with which to compare. * @return {@code true} if this object is the same as the edge * argument; {@code false} otherwise. */ default boolean isEqual(final EdgeId that) { return null != that && (new EqualsBuilder() .append(getDirectedType(), that.getDirectedType()) .append(getSource(), that.getSource()) .append(getDestination(), that.getDestination()) .isEquals()); }
@JsonIgnore default Object getAdjacentMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getSource() : getDestination(); }
@JsonIgnore default Object getMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getDestination() : getSource(); }
/** * This is related to an {@link EntityId} if the EntityId's identifier * matches this EdgeId's source or destination. * * @param that the {@link ElementId} to compare * @return An instance of {@link ElementId.Matches} to describe how the ids are related. */ default Matches isRelated(final EntityId that) { boolean matchesSource = (null == getSource()) ? null == that.getVertex() : getSource().equals(that.getVertex()); boolean matchesDestination = (null == getDestination()) ? null == that.getVertex() : getDestination().equals(that.getVertex()); if (matchesSource) { if (matchesDestination) { return Matches.BOTH; } return Matches.SOURCE; } if (matchesDestination) { return Matches.DESTINATION; } return Matches.NONE; }
/** * This is related to an {@link EdgeId} if either the EdgeId's source or * destination matches this EntityId's vertex. * * @param that the {@link EdgeId} to compare * @return An instance of {@link ElementId.Matches} to describe how the seeds are related. */ default Matches isRelated(final EdgeId that) { boolean matchesSource = (null == getVertex()) ? null == that.getSource() : getVertex().equals(that.getSource()); boolean matchesDestination = (null == getVertex()) ? null == that.getDestination() : getVertex().equals(that.getDestination()); if (matchesSource) { if (matchesDestination) { return Matches.BOTH; } return Matches.SOURCE; } if (matchesDestination) { return Matches.DESTINATION; } return Matches.NONE; } }
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "element provided should always be an Edge") @Override public void loadIdentifiers(final Element edge) { final EdgeId edgeId = (EdgeId) elementConverter.getElementId(key, includeMatchedVertex); ((Edge) edge).setIdentifiers(edgeId.getSource(), edgeId.getDestination(), edgeId.isDirected(), edgeId.getMatchedVertex()); } }
@Override public CloseableIterator<EntityId> iterator() { // For each EntityId, get relevant edges with group-by properties // Create full Element // Apply view // Extract adjacent vertices Stream<Element> elementStream = Streams.toStream(getAdjacentIds.getInput()) .flatMap(entityId -> GetElementsUtil.getRelevantElements(mapImpl, entityId, getAdjacentIds.getView(), getAdjacentIds.getDirectedType(), getAdjacentIds.getIncludeIncomingOutGoing(), SeedMatching.SeedMatchingType.RELATED) .stream() .map(mapImpl::getAggElement)); // Apply the view elementStream = GetElementsUtil.applyView(elementStream, schema, getAdjacentIds.getView()); final Stream<EntityId> adjacentIdsStream = elementStream .filter(Objects::nonNull) .map(element -> { final Object nextVertex; if (EdgeId.MatchedVertex.DESTINATION == ((EdgeId) element).getMatchedVertex()) { nextVertex = ((EdgeId) element).getSource(); } else { nextVertex = ((EdgeId) element).getDestination(); } return new EntitySeed(nextVertex); }); return new WrappedCloseableIterator<>(adjacentIdsStream.iterator()); } }
if (elementId instanceof EdgeId) { if (EdgeId.MatchedVertex.DESTINATION == ((EdgeId) elementId).getMatchedVertex()) { nextId = new EntitySeed(((EdgeId) elementId).getSource()); } else { nextId = new EntitySeed(((EdgeId) elementId).getDestination());
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), false))); relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), true))); } else { relevantElements.addAll(mapImpl.lookup(edgeId)); mapImpl.lookup(new EntitySeed(edgeId.getSource())) .stream() .filter(e -> e instanceof Entity)
private List<Range> getRange(final ElementId elementId, final GraphFilters operation, final SeededGraphFilters.IncludeIncomingOutgoingType inOutType) throws RangeFactoryException { if (elementId instanceof EntityId) { return getRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges()); } else { final EdgeId edgeId = (EdgeId) elementId; final List<Range> ranges = new ArrayList<>(); if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) { // EQUALS and RELATED seed matching. final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType()); ranges.addAll(getRange(edgeId.getSource(), edgeId.getDestination(), directed, operation, inOutType)); } // Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatching.SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching()); if (doRelated && operation.getView().hasEntities()) { // Get Entities related to EdgeIds ranges.addAll(getRange(edgeId.getSource(), operation, false)); ranges.addAll(getRange(edgeId.getDestination(), operation, false)); } return ranges; } }