01: package prefuse.data.util;
02:
03: import java.util.Iterator;
04:
05: import prefuse.data.Edge;
06: import prefuse.data.Node;
07:
08: /**
09: * Iterator over neighbors of a given Node. Resolves Edge instances to
10: * provide direct iteration over the Node instances.
11: *
12: * @author <a href="http://jheer.org">jeffrey heer</a>
13: */
14: public class NeighborIterator implements Iterator {
15:
16: private Iterator m_edges;
17: private Node m_node;
18:
19: /**
20: * Create a new NeighborIterator.
21: * @param n the source node
22: * @param edges the node edges to iterate over
23: */
24: public NeighborIterator(Node n, Iterator edges) {
25: m_node = n;
26: m_edges = edges;
27: }
28:
29: /**
30: * @see java.util.Iterator#remove()
31: */
32: public void remove() {
33: throw new UnsupportedOperationException();
34: }
35:
36: /**
37: * @see java.util.Iterator#hasNext()
38: */
39: public boolean hasNext() {
40: return m_edges.hasNext();
41: }
42:
43: /**
44: * @see java.util.Iterator#next()
45: */
46: public Object next() {
47: Edge e = (Edge) m_edges.next();
48: return e.getAdjacentNode(m_node);
49: }
50:
51: } // end of class NeighborIterator
|