meaningless comment
[ephemerata.git] / KezvhLib / src-lib / net / kezvh / collections / graphs / directed / GenericDirectedGraphSet.java
blob8f02b8da5f5edccff110ccfe3e34f92b09a91548
1 package net.kezvh.collections.graphs.directed;
3 import java.util.AbstractSet;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.Set;
8 import net.kezvh.collections.views.MapAsView;
9 import net.kezvh.collections.wrappers.CollectionAsSet;
10 import net.kezvh.functional.lambda.L1;
12 /**
13 * @author mjacob
14 * @param <Node> COMMENT
15 * @param <EdgeValue> COMMENT
17 public class GenericDirectedGraphSet<Node, EdgeValue> extends AbstractSet<Node> implements DirectedGraphWithEdgeValues<Node, EdgeValue> {
19 @Override
20 public int hashCode() {
21 final int prime = 31;
22 int result = super.hashCode();
23 result = prime * result + ((this.innerGraph == null) ? 0 : this.innerGraph.hashCode());
24 return result;
27 @Override
28 public boolean equals(final Object obj) {
29 if (this == obj)
30 return true;
31 if (!super.equals(obj))
32 return false;
33 if (this.getClass() != obj.getClass())
34 return false;
35 final GenericDirectedGraphSet<?, ?> other = (GenericDirectedGraphSet<?, ?>) obj;
36 if (this.innerGraph == null) {
37 if (other.innerGraph != null)
38 return false;
39 } else if (!this.innerGraph.equals(other.innerGraph))
40 return false;
41 return true;
44 private static final Object PRESENT = new Object();
45 private final DirectedGraphWithValues<Node, Object, EdgeValue> innerGraph;
47 /**
48 * @param innerGraph a graph on which to build the set
50 public GenericDirectedGraphSet(final DirectedGraphWithValues<Node, Object, EdgeValue> innerGraph) {
51 super();
52 this.innerGraph = innerGraph;
55 private final L1<Object, Node> presentMapper = new L1<Object, Node>() {
56 public Object op(final Node param) {
57 return GenericDirectedGraphSet.PRESENT;
61 @Override
62 public boolean add(final Node e) {
63 return this.innerGraph.put(e, GenericDirectedGraphSet.PRESENT) != null;
66 @SuppressWarnings("unchecked")
67 @Override
68 public boolean addAll(final Collection<? extends Node> c) {
69 this.innerGraph.putAll(new MapAsView<Node, Object>(new CollectionAsSet<Node, Collection<Node>>((Collection<Node>) c), this.presentMapper));
70 return !c.isEmpty();
73 @Override
74 public void clear() {
75 this.innerGraph.clear();
78 @Override
79 public boolean contains(final Object o) {
80 return this.innerGraph.containsKey(o);
83 @Override
84 public boolean isEmpty() {
85 return this.innerGraph.isEmpty();
88 @Override
89 public Iterator<Node> iterator() {
90 return this.innerGraph.keySet().iterator();
93 @Override
94 public boolean remove(final Object o) {
95 return this.innerGraph.remove(o) != null;
98 @Override
99 public int size() {
100 return this.innerGraph.size();
103 @Override
104 public Object[] toArray() {
105 return this.innerGraph.keySet().toArray();
108 @Override
109 public <T> T[] toArray(final T[] a) {
110 return this.innerGraph.keySet().toArray(a);
113 @Override
114 public Set<Node> adjacentFrom(final Node source) {
115 return this.innerGraph.adjacentFrom(source);
118 @Override
119 public Set<Node> adjacentTo(final Node destination) {
120 return this.innerGraph.adjacentTo(destination);
123 @Override
124 public boolean containsEdge(final Node source, final Node destination) {
125 return this.innerGraph.containsEdge(source, destination);
128 @Override
129 public boolean containsEdge(final EdgeWithEdgeValue<Node, EdgeValue> edge) {
130 return this.innerGraph.keySet().contains(edge);
133 @Override
134 public long edgeCount() {
135 return this.innerGraph.edgeCount();
138 @Override
139 public Set<EdgeWithEdgeValue<Node, EdgeValue>> edges() {
140 return this.innerGraph.keySet().edges();
143 @Override
144 public int inDegree(final Node destination) {
145 return this.innerGraph.inDegree(destination);
148 @Override
149 public Set<EdgeWithEdgeValue<Node, EdgeValue>> inEdges(final Node destination) {
150 return this.innerGraph.keySet().inEdges(destination);
153 @Override
154 public int outDegree(final Node source) {
155 return this.innerGraph.outDegree(source);
158 @Override
159 public Set<EdgeWithEdgeValue<Node, EdgeValue>> outEdges(final Node source) {
160 return this.innerGraph.keySet().outEdges(source);
163 @Override
164 public EdgeValue addEdge(final Node source, final Node destination, final EdgeValue edgeValue) {
165 return this.innerGraph.addEdge(source, destination, edgeValue);
168 @Override
169 public EdgeValue getEdgeValue(final Node source, final Node destination) {
170 return this.innerGraph.getEdgeValue(source, destination);
173 @Override
174 public EdgeValue removeEdge(final Node source, final Node destination) {
175 return this.innerGraph.removeEdge(source, destination);
178 @Override
179 public EdgeValue removeEdge(final EdgeWithEdgeValue<Node, EdgeValue> edge) {
180 return this.innerGraph.keySet().removeEdge(edge);