1 package net
.kezvh
.collections
.graphs
.directed
;
3 import java
.util
.AbstractSet
;
4 import java
.util
.Collection
;
5 import java
.util
.Iterator
;
8 import net
.kezvh
.collections
.views
.MapAsView
;
9 import net
.kezvh
.collections
.wrappers
.CollectionAsSet
;
10 import net
.kezvh
.functional
.lambda
.L1
;
15 * @param <Node> COMMENT
16 * @param <EdgeValue> COMMENT
18 public class HashDirectedGraphSet
<Node
, EdgeValue
> extends AbstractSet
<Node
> implements DirectedGraphWithEdgeValues
<Node
, EdgeValue
> {
20 public int hashCode() {
22 int result
= super.hashCode();
23 result
= prime
* result
+ ((this.innerGraph
== null) ?
0 : this.innerGraph
.hashCode());
28 public boolean equals(final Object obj
) {
31 if (!super.equals(obj
))
33 if (this.getClass() != obj
.getClass())
35 final HashDirectedGraphSet
<?
, ?
> other
= (HashDirectedGraphSet
<?
, ?
>) obj
;
36 if (this.innerGraph
== null) {
37 if (other
.innerGraph
!= null)
39 } else if (!this.innerGraph
.equals(other
.innerGraph
))
44 private static final Object PRESENT
= new Object();
45 private final HashDirectedGraph
<Node
, Object
, EdgeValue
> innerGraph
= new HashDirectedGraph
<Node
, Object
, EdgeValue
>();
47 private final L1
<Object
, Node
> presentMapper
= new L1
<Object
, Node
>() {
48 public Object
op(final Node param
) {
49 return HashDirectedGraphSet
.PRESENT
;
54 public boolean add(final Node e
) {
55 return this.innerGraph
.put(e
, HashDirectedGraphSet
.PRESENT
) != null;
58 @SuppressWarnings("unchecked")
60 public boolean addAll(final Collection
<?
extends Node
> c
) {
61 this.innerGraph
.putAll(new MapAsView
<Node
, Object
>(new CollectionAsSet
<Node
, Collection
<Node
>>((Collection
<Node
>) c
), this.presentMapper
));
67 this.innerGraph
.clear();
71 public boolean contains(final Object o
) {
72 return this.innerGraph
.containsKey(o
);
76 public boolean isEmpty() {
77 return this.innerGraph
.isEmpty();
81 public Iterator
<Node
> iterator() {
82 return this.innerGraph
.keySet().iterator();
86 public boolean remove(final Object o
) {
87 return this.innerGraph
.remove(o
) != null;
92 return this.innerGraph
.size();
96 public Object
[] toArray() {
97 return this.innerGraph
.keySet().toArray();
101 public <T
> T
[] toArray(final T
[] a
) {
102 return this.innerGraph
.keySet().toArray(a
);
106 public Set
<Node
> adjacentFrom(final Node source
) {
107 return this.innerGraph
.adjacentFrom(source
);
111 public Set
<Node
> adjacentTo(final Node destination
) {
112 return this.innerGraph
.adjacentTo(destination
);
116 public boolean containsEdge(final Node source
, final Node destination
) {
117 return this.innerGraph
.containsEdge(source
, destination
);
121 public boolean containsEdge(final EdgeWithEdgeValue
<Node
, EdgeValue
> edge
) {
122 return this.innerGraph
.keySet().contains(edge
);
126 public long edgeCount() {
127 return this.innerGraph
.edgeCount();
131 public Set
<EdgeWithEdgeValue
<Node
, EdgeValue
>> edges() {
132 return this.innerGraph
.keySet().edges();
136 public int inDegree(final Node destination
) {
137 return this.innerGraph
.inDegree(destination
);
141 public Set
<EdgeWithEdgeValue
<Node
, EdgeValue
>> inEdges(final Node destination
) {
142 return this.innerGraph
.keySet().inEdges(destination
);
146 public int outDegree(final Node source
) {
147 return this.innerGraph
.outDegree(source
);
151 public Set
<EdgeWithEdgeValue
<Node
, EdgeValue
>> outEdges(final Node source
) {
152 return this.innerGraph
.keySet().outEdges(source
);
156 public EdgeValue
addEdge(final Node source
, final Node destination
, final EdgeValue edgeValue
) {
157 return this.innerGraph
.addEdge(source
, destination
, edgeValue
);
161 public EdgeValue
getEdgeValue(final Node source
, final Node destination
) {
162 return this.innerGraph
.getEdgeValue(source
, destination
);
166 public EdgeValue
removeEdge(final Node source
, final Node destination
) {
167 return this.innerGraph
.removeEdge(source
, destination
);
171 public EdgeValue
removeEdge(final EdgeWithEdgeValue
<Node
, EdgeValue
> edge
) {
172 return this.innerGraph
.keySet().removeEdge(edge
);