public static boolean areCompatible(final DirectedType dirType1, final DirectedType dirType2) { if (DIRECTED == dirType1) { return dirType2.isDirected(); } else if (UNDIRECTED == dirType1) { return dirType2.isUndirected(); } return true; }
@Override public Object apply(final Object item) { return null != item ? item instanceof EntityId ? ((EntityId) item).getVertex() : item : null; } }
public static boolean isUndirected(final DirectedType directedType) { return null == directedType || directedType.isUndirected(); }
/** * 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; }
@JsonIgnore default Object getAdjacentMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getSource() : getDestination(); }
/** * 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()); }
public static boolean isDirected(final DirectedType directedType) { return null == directedType || directedType.isDirected(); }
void setIdentifiers(final Object source, final Object destination, final DirectedType directedType, final MatchedVertex matchedVertex);
/** * @return true if directed is UNDIRECTED, EITHER or null. Otherwise false. */ @JsonIgnore default boolean isUndirected() { return DirectedType.DIRECTED != getDirectedType(); }
/** * This is related to an {@link ElementId} if either the ElementId is equal * to this EntityId or it is an EdgeId and its source or destination matches * this EntityId's vertex. * * @param that the {@link ElementId} to compare * @return An instance of {@link ElementId.Matches} to describe how the seeds are related. */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Edge it must be an Edge") @Override default Matches isRelated(final ElementId that) { if (that instanceof EntityId) { if (isEqual(that)) { return Matches.VERTEX; } return Matches.NONE; } return isRelated((EdgeId) that); }
/** * This is related to an {@link ElementId} if either the ElementId is equal * to this EdgeId or it is an EntityId and its 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. */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Edge it must be an Entity") @Override default Matches isRelated(final ElementId that) { if (that instanceof EdgeId) { if (isEqual(that)) { return Matches.BOTH; } return Matches.NONE; } return isRelated((EntityId) that); }
@Override default boolean isEqual(final ElementId that) { return that instanceof EdgeId && isEqual((EdgeId) that); }
@Override default boolean isEqual(final ElementId that) { return that instanceof EntityId && isEqual((EntityId) that); }
/** * 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; } }
@JsonIgnore default Object getMatchedVertexValue() { return MatchedVertex.DESTINATION == getMatchedVertex() ? getDestination() : getSource(); }
private static boolean getDirected(final Boolean directed, final DirectedType directedType) { if (null != directed) { if (null != directedType) { throw new IllegalArgumentException("Use either 'directed' or 'directedType' - not both."); } return directed; } return DirectedType.isDirected(directedType); }
/** * @return true if directed is DIRECTED, EITHER or null. Otherwise false. */ @JsonIgnore default boolean isDirected() { return DirectedType.UNDIRECTED != getDirectedType(); }
/** * Sets the identifiers for an Edge. * <p> * If the edge is undirected the the source and destination vertices may get * swapped to ensure undirected edges are consistently constructed. * </p> * * @param source the source vertex * @param destination the destination vertex * @param directedType the edge directedType */ @Override public void setIdentifiers(final Object source, final Object destination, final DirectedType directedType) { setIdentifiers(source, destination, directedType.isDirected()); }
/** * Sets the identifiers for an Edge. * <p> * If the edge is undirected the the source and destination vertices may get * swapped to ensure undirected edges are consistently constructed. * </p> * * @param source the source vertex * @param destination the destination vertex * @param directedType the edge directedType * @param matchedVertex the vertex that matched a query seed */ @Override public void setIdentifiers(final Object source, final Object destination, final DirectedType directedType, final MatchedVertex matchedVertex) { setIdentifiers(source, destination, directedType.isDirected(), matchedVertex); }