001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2002, Refractions Reserach Inc.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.graph.structure.basic;
018:
019: import java.io.Serializable;
020:
021: import org.geotools.graph.structure.Graphable;
022:
023: /**
024: * Basic implementation of Graphable. This class serves as the root in the
025: * hierarchy of basic graph components. <BR>
026: * <BR>
027: * Components in the basic hierarchy implement the Serializable interface.
028: * However serialization will fail if a Graphable object contains a reference
029: * to a non serializable object.
030: *
031: * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
032: *
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/structure/basic/BasicGraphable.java $
034: */
035: public abstract class BasicGraphable implements Graphable, Serializable {
036:
037: /** Used to generate id's for graph components */
038: private static int id = 0;
039:
040: /** underlying object of component **/
041: private Object m_obj;
042:
043: /** Flag to indicate wether the component has been visited */
044: private boolean m_visited;
045:
046: /** A counter to track how many times a component has been visited */
047: private int m_nvisited;
048:
049: /** Id for component. */
050: private int m_id;
051:
052: /**
053: * Constrcuts a new a graph component. Sets the visited flag to false,
054: * counter to -1, and generates a new id.
055: */
056: public BasicGraphable() {
057: m_visited = false;
058: m_nvisited = -1;
059: m_id = id++;
060: }
061:
062: /**
063: * @see Graphable#getID()
064: */
065: public int getID() {
066: return (m_id);
067: }
068:
069: /**
070: * @see Graphable#setID(int)
071: */
072: public void setID(int id) {
073: m_id = id;
074: }
075:
076: /**
077: * @see Graphable#getObject()
078: */
079: public Object getObject() {
080: return (m_obj);
081: }
082:
083: /**
084: * @see Graphable#setObject(Object)
085: */
086: public void setObject(Object obj) {
087: m_obj = obj;
088: }
089:
090: /**
091: * @see Graphable#isVisited()
092: */
093: public boolean isVisited() {
094: return (m_visited);
095: }
096:
097: /**
098: * @see Graphable#setVisited(boolean)
099: */
100: public void setVisited(boolean visited) {
101: m_visited = visited;
102: }
103:
104: /**
105: * @see Graphable#getCount()
106: */
107: public int getCount() {
108: return (m_nvisited);
109: }
110:
111: /**
112: * @see Graphable#setCount(int)
113: */
114: public void setCount(int count) {
115: m_nvisited = count;
116: }
117:
118: /**
119: * Returns the id of the component as a string.
120: *
121: * @see Graphable#getID()
122: */
123: public String toString() {
124: return (String.valueOf(m_id));
125: }
126: }
|