001package edu.pdx.cs410J.net; 002 003import java.util.*; 004 005/** 006 * This class is used to demonstrate object serialization support for 007 * referential integrity. 008 */ 009public class GraphNode implements java.io.Serializable { 010 private Collection children = new ArrayList(); 011 private transient boolean beenVisited = false; 012 013 /** 014 * Adds a child node to this node 015 */ 016 public void addChild(GraphNode child) { 017 this.children.add(child); 018 } 019 020 /** 021 * Returns this node's number of unvisited descendents 022 */ 023 public int traverse() { 024 int total = 1; 025 this.beenVisited = true; 026 027 Iterator iter = children.iterator(); 028 while (iter.hasNext()) { 029 GraphNode child = (GraphNode) iter.next(); 030 if (!child.beenVisited) { 031 total += child.traverse(); 032 } 033 } 034 035 return total; 036 } 037}