public static <V,E> HashBasedHipsterGraph<V, E> create() { return new HashBasedHipsterGraph<V, E>(); } }
@Override public Set<V> remove(V... vertices) { Set<V> removed = new HashSet<V>(); for(V v : vertices){ if (remove(v)) removed.add(v); } return removed; }
/** * Returns a list of the edges in the graph. * @return edges of the graph. */ @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); }
@Override public Set<V> add(V... vertices) { Set<V> added = new HashSet<V>(); for(V v : vertices){ if (add(v)) added.add(v); } return added; }
@Override public GraphEdge<V,E> connect(V v1, V v2, E value){ // Check non-null arguments if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); // Ensure that the vertices are in the graph if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); // Associate the vertices with their edge connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; }
/** * Returns a list of the edges in the graph. * @return edges of the graph. */ @Override public Iterable<GraphEdge<V, E>> edges() { return F.map(vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> entry) { return entry.getValue(); } }); }
@Override public Set<V> add(V... vertices) { Set<V> added = new HashSet<V>(); for(V v : vertices){ if (add(v)) added.add(v); } return added; }
@Override public GraphEdge<V,E> connect(V v1, V v2, E value){ // Check non-null arguments if(v1 == null || v2 == null) throw new IllegalArgumentException("Invalid vertices. A vertex cannot be null"); // Ensure that the vertices are in the graph if (!connected.containsKey(v1)) throw new IllegalArgumentException(v1 + " is not a vertex of the graph"); if (!connected.containsKey(v2)) throw new IllegalArgumentException(v2 + " is not a vertex of the graph"); GraphEdge<V,E> edge = buildEdge(v1, v2, value); // Associate the vertices with their edge connected.get(v1).add(edge); connected.get(v2).add(edge); return edge; }
@Override public Iterable<GraphEdge<V, E>> edges() { // TODO: [java-8-migration] use stream filter return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); }
@Override public Set<V> remove(V... vertices) { Set<V> removed = new HashSet<V>(); for(V v : vertices){ if (remove(v)) removed.add(v); } return removed; }
public static <V,E> HashBasedHipsterGraph<V, E> create() { return new HashBasedHipsterGraph<V, E>(); } }
@Override public Iterable<GraphEdge<V, E>> edges() { // TODO: [java-8-migration] use stream filter return F.map( F.filter(HashBasedHipsterDirectedGraph.super.vedges(), new Function<Map.Entry<V, GraphEdge<V, E>>, Boolean>() { @Override public Boolean apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getKey().equals(input.getValue().getVertex1()); } }), new Function<Map.Entry<V, GraphEdge<V, E>>, GraphEdge<V, E>>() { @Override public GraphEdge<V, E> apply(Map.Entry<V, GraphEdge<V, E>> input) { return input.getValue(); } }); }