View Javadoc

    1   package baseCode.dataStructure.graph;
    2
    3   import org.apache.commons.logging.Log;
    4   import org.apache.commons.logging.LogFactory;
    5
    6   import baseCode.common.Visitable;
    7
    8   /***
    9    * <p>
    10   * Copyright (c) Columbia University
    11   *
    12   * @author Paul Pavlidis
    13   * @version $Id: AbstractGraphNode.java,v 1.9 2004/07/29 08:38:49 pavlidis Exp $
    14   */
    15  public abstract class AbstractGraphNode extends Visitable implements GraphNode {
    16     protected Object key;
    17     protected Object item;
    18     protected Graph graph; // the graph this belongs to.
    19     protected boolean visited = false;
    20     protected static Log log = LogFactory.getLog( GraphNode.class );
    21
    22     /***
    23      * Get the actual contents of the node.
    24      *
    25      * @return
    26      */
    27     public Object getItem() {
    28        return item;
    29     }
    30
    31     /***
    32      * Get the key for the node.
    33      *
    34      * @return Object
    35      */
    36     public Object getKey() {
    37        return key;
    38     }
    39
    40     /***
    41      * Create a new node with key and value given. The key is stored by the graph and is used to retrieve nodes. Keys and
    42      * nodes can be any kind of object.
    43      *
    44      * @param key
    45      * @param value
    46      * @param graph
    47      */
    48     public AbstractGraphNode( Object key, Object value, Graph graph ) {
    49        this.setValue( key, value );
    50        this.graph = graph;
    51     }
    52
    53     /***
    54      * Create a new node when given only a key.
    55      *
    56      * @param key
    57      */
    58     public AbstractGraphNode( Object key ) {
    59        this.key = key;
    60        this.item = null;
    61     }
    62
    63     /***
    64      * Set the graph this belongs to.
    65      *
    66      * @param graph Graph
    67      */
    68     public void setGraph( Graph graph ) {
    69        this.graph = graph;
    70     }
    71
    72     public void setValue( Object key, Object value ) {
    73        this.item = value;
    74        this.key = key;
    75     }
    76
    77     public void setItem( Object value ) {
    78        this.item = value;
    79     }
    80
    81     public String toString() {
    82        return item.toString();
    83     }
    84
    85     public Graph getGraph() {
    86        return graph;
    87     }
    88
    89     public void mark() {
    90        visited = true;
    91     }
    92
    93     public void unMark() {
    94        visited = false;
    95     }
    96
    97     public boolean isVisited() {
    98        return visited;
    99     }
    100
    101 }