public Collection<E> getInEdges(V vertex) { if (!containsVertex(vertex)) return null; return Collections.unmodifiableCollection(getIncoming_internal(vertex)); }
@Override public Collection<E> getInEdges(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections.unmodifiableCollection(getIncoming_internal(vertex)); }
@Override public Collection<V> getPredecessors(V vertex) { if (!containsVertex(vertex)) { return null; } Set<V> preds = new HashSet<V>(); for (E edge : getIncoming_internal(vertex)) { preds.add(this.getSource(edge)); } return Collections.unmodifiableCollection(preds); }
@Override public Collection<E> getIncidentEdges(V vertex) { if (!containsVertex(vertex)) { return null; } Collection<E> incident = new HashSet<E>(); incident.addAll(getIncoming_internal(vertex)); incident.addAll(getOutgoing_internal(vertex)); return incident; }
public Collection<E> getIncidentEdges(V vertex) { if (!containsVertex(vertex)) return null; Collection<E> incident = new HashSet<E>(); incident.addAll(getIncoming_internal(vertex)); incident.addAll(getOutgoing_internal(vertex)); return incident; }
public Collection<V> getPredecessors(V vertex) { if (!containsVertex(vertex)) return null; Set<V> preds = new HashSet<V>(); for (E edge : getIncoming_internal(vertex)) preds.add(this.getSource(edge)); return Collections.unmodifiableCollection(preds); }
public boolean removeVertex(V vertex) { if (!containsVertex(vertex)) return false; // copy to avoid concurrent modification in removeEdge Set<E> incident = new HashSet<E>(getIncoming_internal(vertex)); incident.addAll(getOutgoing_internal(vertex)); for (E edge : incident) removeEdge(edge); vertices.remove(vertex); return true; }
@Override public boolean removeVertex(V vertex) { if (!containsVertex(vertex)) { return false; } // copy to avoid concurrent modification in removeEdge Set<E> incident = new HashSet<E>(getIncoming_internal(vertex)); incident.addAll(getOutgoing_internal(vertex)); for (E edge : incident) { removeEdge(edge); } vertices.remove(vertex); return true; }
public Collection<V> getNeighbors(V vertex) { if (!containsVertex(vertex)) return null; Collection<V> neighbors = new HashSet<V>(); for (E edge : getIncoming_internal(vertex)) neighbors.add(this.getSource(edge)); for (E edge : getOutgoing_internal(vertex)) neighbors.add(this.getDest(edge)); return Collections.unmodifiableCollection(neighbors); }
@Override public Collection<V> getNeighbors(V vertex) { if (!containsVertex(vertex)) { return null; } Collection<V> neighbors = new HashSet<V>(); for (E edge : getIncoming_internal(vertex)) { neighbors.add(this.getSource(edge)); } for (E edge : getOutgoing_internal(vertex)) { neighbors.add(this.getDest(edge)); } return Collections.unmodifiableCollection(neighbors); }
public boolean removeEdge(E edge) { if (!containsEdge(edge)) return false; Pair<V> endpoints = this.getEndpoints(edge); V source = endpoints.getFirst(); V dest = endpoints.getSecond(); // remove edge from incident vertices' adjacency sets getOutgoing_internal(source).remove(edge); getIncoming_internal(dest).remove(edge); edges.remove(edge); return true; }
@Override public boolean removeEdge(E edge) { if (!containsEdge(edge)) { return false; } Pair<V> endpoints = this.getEndpoints(edge); V source = endpoints.getFirst(); V dest = endpoints.getSecond(); // remove edge from incident vertices' adjacency sets getOutgoing_internal(source).remove(edge); getIncoming_internal(dest).remove(edge); edges.remove(edge); return true; }
@Override public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) { this.validateEdgeType(edgeType); Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints); if (new_endpoints == null) return false; edges.put(edge, new_endpoints); V source = new_endpoints.getFirst(); V dest = new_endpoints.getSecond(); if (!containsVertex(source)) this.addVertex(source); if (!containsVertex(dest)) this.addVertex(dest); getIncoming_internal(dest).add(edge); getOutgoing_internal(source).add(edge); return true; }
@Override public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) { this.validateEdgeType(edgeType); Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints); if (new_endpoints == null) { return false; } edges.put(edge, new_endpoints); V source = new_endpoints.getFirst(); V dest = new_endpoints.getSecond(); if (!containsVertex(source)) { this.addVertex(source); } if (!containsVertex(dest)) { this.addVertex(dest); } getIncoming_internal(dest).add(edge); getOutgoing_internal(source).add(edge); return true; }