meaningless comment
[ephemerata.git] / KezvhLib / src-lib / net / kezvh / collections / graphs / directed / AdjacencyCollectionDirectedGraph.java
blob2d3b59f75e0f50a67884c9b248bc716f1fed1492
1 /**
3 */
4 package net.kezvh.collections.graphs.directed;
6 import java.util.AbstractMap;
7 import java.util.Collection;
8 import java.util.HashMap;
9 import java.util.Map;
10 import java.util.Set;
12 import net.kezvh.collections.views.MapAsView;
13 import net.kezvh.functional.lambda.L1;
14 import net.kezvh.patterns.AbstractFactory;
16 /**
17 * @author afflux
18 * @param <Node> COMMENT
19 * @param <NodeValue> COMMENT
20 * @param <EdgeValue> COMMENT
21 * @param <M> COMMENT
23 public class AdjacencyCollectionDirectedGraph<Node, NodeValue, EdgeValue, M extends Map<Node, EdgeValue>> extends AbstractMap<Node, NodeValue> implements DirectedGraphWithValues<Node, NodeValue, EdgeValue> {
24 /**
25 * @param collectionMaker something that makes a collection
27 public AdjacencyCollectionDirectedGraph(final AbstractFactory<M> collectionMaker) {
28 super();
29 this.collectionMaker = collectionMaker;
32 private static final class Entry<NodeValue, M> {
34 private NodeValue value;
35 private final M destinations;
37 /**
38 * @return the value
40 public NodeValue getValue() {
41 return this.value;
44 /**
45 * @param value the value to set
46 * @return the old value
48 public NodeValue setValue(final NodeValue value) {
49 try {
50 return this.value;
51 } finally {
52 this.value = value;
56 /**
57 * @return the m
59 public M getDestinations() {
60 return this.destinations;
63 public Entry(final NodeValue value, final M m) {
64 super();
65 this.value = value;
66 this.destinations = m;
70 private final AbstractFactory<M> collectionMaker;
71 private final Map<Node, Entry<NodeValue, M>> adjacencyListsByNode = new HashMap<Node, Entry<NodeValue, M>>();
73 DirectedGraphWithEdgeValues<Node, EdgeValue> keySet = new WrappedKeySet<Node, NodeValue, EdgeValue>(this);
75 /**
76 * @see net.kezvh.collections.graphs.directed.DirectedGraphWithValues#keySet()
77 * @return COMMENT
79 @Override
80 public DirectedGraphWithEdgeValues<Node, EdgeValue> keySet() {
81 return this.keySet;
84 /**
85 * @see net.kezvh.collections.graphs.directed.DirectedGraphNodesWithValues#inEdgeSources(java.lang.Object)
86 * @param destination COMMENT
87 * @return COMMENT
89 @Override
90 public Map<Node, NodeValue> inEdgeSources(final Node destination) {
91 // TODO Auto-generated method stub
92 return null;
95 private final L1<NodeValue, Node> getNodeValue = new L1<NodeValue, Node>() {
96 public NodeValue op(final Node param) {
97 return AdjacencyCollectionDirectedGraph.this.adjacencyListsByNode.get(param).getValue();
102 * @see net.kezvh.collections.graphs.directed.DirectedGraphNodesWithValues#outEdgeDestinations(java.lang.Object)
103 * @param source COMMENT
104 * @return COMMENT
106 @Override
107 public Map<Node, NodeValue> outEdgeDestinations(final Node source) {
108 final Entry<NodeValue, M> entry = this.adjacencyListsByNode.get(source);
109 return new MapAsView<Node, NodeValue>(entry.getDestinations().keySet(), this.getNodeValue) {
110 @Override
111 public NodeValue put(final Node key, final NodeValue value) {
112 return AdjacencyCollectionDirectedGraph.this.adjacencyListsByNode.get(key).setValue(value);
118 * @see java.util.Map#clear()
120 @Override
121 public void clear() {
122 this.adjacencyListsByNode.clear();
126 * @see java.util.Map#containsKey(java.lang.Object)
127 * @param key COMMENT
128 * @return COMMENT
130 @Override
131 public boolean containsKey(final Object key) {
132 return this.adjacencyListsByNode.containsKey(key);
136 * @see java.util.Map#containsValue(java.lang.Object)
137 * @param value COMMENT
138 * @return COMMENT
140 @Override
141 public boolean containsValue(final Object value) {
142 // TODO Auto-generated method stub
143 return false;
147 * @see java.util.Map#entrySet()
148 * @return COMMENT
150 @Override
151 public Set<Map.Entry<Node, NodeValue>> entrySet() {
152 // TODO Auto-generated method stub
153 return null;
157 * @see java.util.Map#get(java.lang.Object)
158 * @param key COMMENT
159 * @return COMMENT
161 @Override
162 public NodeValue get(final Object key) {
163 return this.adjacencyListsByNode.get(key).getValue();
167 * @see java.util.Map#isEmpty()
168 * @return COMMENT
170 @Override
171 public boolean isEmpty() {
172 return this.adjacencyListsByNode.isEmpty();
176 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
177 * @param key COMMENT
178 * @param value COMMENT
179 * @return COMMENT
181 @Override
182 public NodeValue put(final Node key, final NodeValue value) {
183 if (this.adjacencyListsByNode.containsKey(key))
184 return this.adjacencyListsByNode.get(key).setValue(value);
186 this.adjacencyListsByNode.put(key, new Entry<NodeValue, M>(value, this.collectionMaker.create()));
187 return null;
191 * @see java.util.Map#remove(java.lang.Object)
192 * @param key COMMENT
193 * @return COMMENT
195 @Override
196 public NodeValue remove(final Object key) {
197 if (this.adjacencyListsByNode.containsKey(key))
198 return this.adjacencyListsByNode.remove(key).getValue();
199 return null;
203 * @see java.util.Map#size()
204 * @return COMMENT
206 @Override
207 public int size() {
208 return this.adjacencyListsByNode.size();
212 * @see java.util.Map#values()
213 * @return COMMENT
215 @Override
216 public Collection<NodeValue> values() {
217 // TODO Auto-generated method stub
218 return null;
222 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdgesWithValues#addEdge(java.lang.Object,
223 * java.lang.Object, java.lang.Object)
224 * @param source COMMENT
225 * @param destination COMMENT
226 * @param edgeValue COMMENT
227 * @return COMMENT
229 @Override
230 public EdgeValue addEdge(final Node source, final Node destination, final EdgeValue edgeValue) {
231 return this.adjacencyListsByNode.get(source).getDestinations().put(destination, edgeValue);
235 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdgesWithValues#getEdgeValue(java.lang.Object,
236 * java.lang.Object)
237 * @param source COMMENT
238 * @param destination COMMENT
239 * @return COMMENT
241 @Override
242 public EdgeValue getEdgeValue(final Node source, final Node destination) {
243 return this.adjacencyListsByNode.get(source).getDestinations().get(destination);
247 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdgesWithValues#removeEdge(java.lang.Object,
248 * java.lang.Object)
249 * @param source COMMENT
250 * @param destination COMMENT
251 * @return COMMENT
253 @Override
254 public EdgeValue removeEdge(final Node source, final Node destination) {
255 return this.adjacencyListsByNode.get(source).getDestinations().remove(destination);
259 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdgesWithValues#removeEdge(net.kezvh.collections.graphs.directed.EdgeWithEdgeValue)
260 * @param edge COMMENT
261 * @return COMMENT
263 @Override
264 public EdgeValue removeEdge(final EdgeWithValues<Node, NodeValue, EdgeValue> edge) {
265 return this.removeEdge(edge.getSourceNode(), edge.getDestinationNode());
269 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#adjacentFrom(java.lang.Object)
270 * @param source COMMENT
271 * @return COMMENT
273 @Override
274 public Set<Node> adjacentFrom(final Node source) {
275 // TODO Auto-generated method stub
276 return null;
280 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#adjacentTo(java.lang.Object)
281 * @param destination COMMENT
282 * @return COMMENT
284 @Override
285 public Set<Node> adjacentTo(final Node destination) {
286 // TODO Auto-generated method stub
287 return null;
291 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#containsEdge(java.lang.Object,
292 * java.lang.Object)
293 * @param source COMMENT
294 * @param destination COMMENT
295 * @return COMMENT
297 @Override
298 public boolean containsEdge(final Node source, final Node destination) {
299 // TODO Auto-generated method stub
300 return false;
304 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#containsEdge(net.kezvh.collections.graphs.directed.Edge)
305 * @param edge COMMENT
306 * @return COMMENT
308 @Override
309 public boolean containsEdge(final EdgeWithValues<Node, NodeValue, EdgeValue> edge) {
310 // TODO Auto-generated method stub
311 return false;
315 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#edgeCount()
316 * @return COMMENT
318 @Override
319 public long edgeCount() {
320 // TODO Auto-generated method stub
321 return 0;
325 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#edges()
326 * @return COMMENT
328 @Override
329 public Set<EdgeWithValues<Node, NodeValue, EdgeValue>> edges() {
330 // TODO Auto-generated method stub
331 return null;
335 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#inDegree(java.lang.Object)
336 * @param destination COMMENT
337 * @return COMMENT
339 @Override
340 public int inDegree(final Node destination) {
341 // TODO Auto-generated method stub
342 return 0;
346 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#inEdges(java.lang.Object)
347 * @param destination COMMENT
348 * @return COMMENT
350 @Override
351 public Set<EdgeWithValues<Node, NodeValue, EdgeValue>> inEdges(final Node destination) {
352 // TODO Auto-generated method stub
353 return null;
357 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#outDegree(java.lang.Object)
358 * @param source COMMENT
359 * @return COMMENT
361 @Override
362 public int outDegree(final Node source) {
363 // TODO Auto-generated method stub
364 return 0;
368 * @see net.kezvh.collections.graphs.directed.DirectedGraphEdges#outEdges(java.lang.Object)
369 * @param source COMMENT
370 * @return COMMENT
372 @Override
373 public Set<EdgeWithValues<Node, NodeValue, EdgeValue>> outEdges(final Node source) {
374 // TODO Auto-generated method stub
375 return null;