@Override public Object apply(final Object item) { return null != item ? item instanceof EntityId ? ((EntityId) item).getVertex() : item : null; } }
/** * 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; } }
/** * 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; }
@Test public void shouldUnwrapEntityIds() { // Given final EntityId value = mock(EntityId.class); final Object vertex = mock(Object.class); given(value.getVertex()).willReturn(vertex); final UnwrapEntityId function = new UnwrapEntityId(); // When final Object result = function.apply(value); // Then assertSame(vertex, result); }
@Override public Object apply(final Object item) { return null != item ? item instanceof EntityId ? ((EntityId) item).getVertex() : item : null; } }
protected Set<Object> extractVertices(final Iterator<? extends EntityId> seeds) { final Set<Object> vertices = new HashSet<>(); while (seeds.hasNext()) { vertices.add(seeds.next().getVertex()); } return vertices; }
/** * 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 Entity") @Override public void loadIdentifiers(final Element entity) { ((Entity) entity).setVertex(((EntityId) elementConverter.getElementId(key, false)).getVertex()); } }
/** * 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; }
final Collection<Element> elements = mapImpl.lookup(new EntitySeed(((EntityId) elementId).getVertex())); if (elements.isEmpty()) { return Collections.emptySet();
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; } }