public Edge getEdge(final Object id) { if (null == id) { throw new IllegalArgumentException("edge identifier cannot be null"); } if (supportEdgeIds) { Iterable<Edge> i = baseGraph.getEdges(ID, id); Iterator<Edge> iter = i.iterator(); if (!iter.hasNext()) { return null; } else { Edge e = iter.next(); if (iter.hasNext()) { LOGGER.warning("multiple edges exist with id '" + id + "'. Arbitarily choosing " + e); } return new IdEdge(e, this); } } else { Edge base = baseGraph.getEdge(id); return null == base ? null : new IdEdge(base, this); } }
public HistoricVersionedEdge<V> getEdgeByHardId(Object id) { Preconditions.checkNotNull(id, "id must be set."); Edge edge; if (isNaturalIds()) { edge = getSingleEdge(VEProps.NATURAL_EDGE_ID_PROP_KEY, id); } else { edge = getBaseGraph().getEdge(id); } if (edge != null) { if (edge instanceof HistoricVersionedEdge) { return (HistoricVersionedEdge<V>) edge; } else { utils.ensureHistoricType(edge); V start = utils.getStartVersion(edge); return new HistoricVersionedEdge<V>(edge, this, Range.range(start, start)); } } else { log.debug("Edge with [{}] was not found.", id); return null; } }
/** * Return the edge referenced by the provided object identifier. * * @param id the identifier of the edge to retrieved from the graph * @param mappingFunc the function to create a new dedicated edge from another * @param <E> the type of the edge after mapping * * @return an {@link Optional} containing the edge referenced by the provided identifier * * @see #getEdge(Object) */ @Nonnull public <E extends Edge> Optional<E> getEdge(Object id, BiFunction<Edge, G, E> mappingFunc) { checkNotNull(id, "id"); Optional<Edge> edge = supportEdgeIds ? MoreIterables.onlyElement(baseGraph.getEdges(ID, id)) : Optional.ofNullable(baseGraph.getEdge(id)); return edge.map(e -> mappingFunc.apply(e, me())); }