@Override public E findEdge(V v1, V v2) { if (!containsVertex(v1) || !containsVertex(v2)) return null; return vertices.get(v1).get(v2); }
@Override public E findEdge(V v1, V v2) { if (!containsVertex(v1) || !containsVertex(v2)) { return null; } return vertices.get(v1).get(v2); }
public Collection<V> getNeighbors(V vertex) { if (!containsVertex(vertex)) return null; return Collections.unmodifiableCollection(vertices.get(vertex).keySet()); }
public boolean addVertex(V vertex) { if(vertex == null) { throw new IllegalArgumentException("vertex may not be null"); } if (!containsVertex(vertex)) { vertices.put(vertex, new HashMap<V,E>()); return true; } else { return false; } }
@Override public Collection<E> getIncidentEdges(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections .unmodifiableCollection(vertices.get(vertex).values()); }
@Override public boolean addVertex(V vertex) { if (vertex == null) { throw new IllegalArgumentException("vertex may not be null"); } if (!containsVertex(vertex)) { vertices.put(vertex, new HashMap<V, E>()); return true; } return false; }
@Override public Collection<V> getNeighbors(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections .unmodifiableCollection(vertices.get(vertex).keySet()); }
public Collection<E> getIncidentEdges(V vertex) { if (!containsVertex(vertex)) return null; return Collections.unmodifiableCollection(vertices.get(vertex).values()); }
@Override public Collection<E> findEdgeSet(V v1, V v2) { if (!containsVertex(v1) || !containsVertex(v2)) return null; ArrayList<E> edge_collection = new ArrayList<E>(1); // if (!containsVertex(v1) || !containsVertex(v2)) // return edge_collection; E e = findEdge(v1, v2); if (e == null) return edge_collection; edge_collection.add(e); return edge_collection; }
public boolean removeVertex(V vertex) { if (!containsVertex(vertex)) return false; // iterate over copy of incident edge collection for (E edge : new ArrayList<E>(vertices.get(vertex).values())) removeEdge(edge); vertices.remove(vertex); return true; }
@Override public Collection<E> findEdgeSet(V v1, V v2) { if (!containsVertex(v1) || !containsVertex(v2)) { return null; } ArrayList<E> edge_collection = new ArrayList<E>(1); // if (!containsVertex(v1) || !containsVertex(v2)) // return edge_collection; E e = findEdge(v1, v2); if (e == null) { return edge_collection; } edge_collection.add(e); return edge_collection; }
@Override public boolean removeVertex(V vertex) { if (!containsVertex(vertex)) { return false; } // iterate over copy of incident edge collection for (E edge : new ArrayList<E>(vertices.get(vertex).values())) { removeEdge(edge); } vertices.remove(vertex); return true; }