View Javadoc

    1   package baseCode.dataStructure.graph;
    2
    3   import java.util.HashSet;
    4   import java.util.Set;
    5
    6   /***
    7    * <p>
    8    * Copyright (c) Columbia University
    9    *
    10   * @author Paul Pavlidis
    11   * @version $Id: UndirectedGraphNode.java,v 1.4 2004/07/27 03:18:58 pavlidis Exp $
    12   */
    13  public class UndirectedGraphNode extends AbstractGraphNode {
    14
    15     private Set neighbors;
    16
    17     public UndirectedGraphNode( Object key, Object value, AbstractGraph graph ) {
    18        super( key, value, graph );
    19        neighbors = new HashSet();
    20     }
    21
    22     public UndirectedGraphNode( Object key ) {
    23        super( key );
    24        neighbors = new HashSet();
    25     }
    26
    27     public int numNeighbors() {
    28        return neighbors.size();
    29     }
    30
    31     public int compareTo( Object o ) {
    32        if ( ( ( UndirectedGraphNode ) o ).numNeighbors() > this.numNeighbors() ) {
    33           return -1;
    34        } else if ( ( ( UndirectedGraphNode ) o ).numNeighbors() < this
    35              .numNeighbors() ) {
    36           return 1;
    37        }
    38        return 0;
    39     }
    40
    41  }