root/trunk/Path.java

Revision 3, 3.6 kB (checked in by dpaola2, 4 years ago)

old pathways project added

Line 
1 /************************************************************************************
2  *                                                                              Path.java                                   *
3  *  CLASS: Path                                                                                            ACM SIGSoft at UIUC  *
4  *  PROJECT: UIUC Pathways                                                                                      December, 2004  *
5  *                                                                                                                                                                      *
6  *  DESCRIPTION--                                                                                                                                       *
7  *              The Path class is designed to store the nodes and edges that compose a          *
8  *  path from one node to another node.  It also stores the total movement cost of  *
9  *  this path.                                                                                                                                          *
10  *              This class does not intelligently calculate or verify anything; it is a         *
11  *  transparent data structure, the members of which can be accessed in any order   *
12  *  preferred by the user.                                                                                                                      *
13  *                                                                                                                                                                      *
14  *  Constructors Available:  Default only.                                                                                      *
15  *                                                                                                                                                                      *
16  *  Methods Available:          - stringWithNodeIDs()                                                                   *
17  *                                                      - setTotalCost(newCost)                                                                 *
18  ************************************************************************************/
19
20 import java.util.*;
21
22
23
24 class Path
25 {
26
27 /****************************************************
28  *  CONSTRUCTOR: Default                                                        *
29  *                                                                                                      *
30  *  Postcondition: All data members are allocated   *
31  *              and initialized; object is ready for use.   *
32  ****************************************************/
33 Path()
34 {
35         nodes = new LinkedList();
36         edges = new LinkedList();
37 }
38
39
40 /****************************************************
41  *  METHOD: stringWithNodeIDs()
42  *     
43  *  Postcondition: Returns a String containing
44  *              each of the nodes that compose the path in 
45  *              order, listed by ID number and separated
46  *              by spaces.
47  ****************************************************/
48 public String stringWithNodeIDs()
49 {
50         String nodeString = "";         // This is the string we will return.
51         
52         // Set up to iterate through all the nodes in the list
53         Iterator iter = nodes.iterator();
54        
55         for(;;)
56         {
57                 Node currentNode = (Node)iter.next();           // Get the next node
58                 nodeString += currentNode.id;                           // Add it to the string
59                 
60                 // If we have another node to list, add a space to separate it
61                 if( iter.hasNext() )
62                         nodeString += " ";
63                 else
64                         break;
65         }
66        
67         // The final string includes all of our nodes.
68         return nodeString;
69 }
70
71
72 /*-**************************************************
73  *      METHOD: addConnectingPath( Path addedPath )
74  *
75  *      DESCRIPTION--
76  *              The parameter addedPath is concatenated onto
77  *      the existing path.  If no path exists, this path
78  *      then comprises this entire object.  If there is a
79  *  problem, a value less than zero is returned.
80  *
81  *      @param addedPath This is the path that should be
82  *                                      added to the existing path, if any.
83  *
84  *      @return successCode
85  *      -- if 0, no error.
86  *      -- if < 0, error.
87  ****************************************************/
88 /*public int addConnectingPath( Path addedPath )
89 {
90
91 }*/
92
93 /*-**************************************************
94  *      METHOD: setTotalCost( Cost newTotalCost )
95  *
96  *      DESCRIPTION--
97  *              This merely sets the value totalCost.
98  *
99  *      @param newTotalCost This is the total cost of the
100  *              path contained by this object.
101  ****************************************************/
102 public void setTotalCost( Cost newTotalCost )
103 {
104         totalCost = newTotalCost;
105 }
106
107
108 /*-**************************************************
109  *      METHOD: getTotalCost ()
110  *
111  *      DESCRIPTION--
112  *              Retrieve the total cost of this path.
113  *
114  *      @return totalCost
115  *      -- The total cost of this path.
116  ****************************************************/
117 public Cost getTotalCost()
118 {
119         return totalCost;
120 } 
121
122
123 // note - this class is more like a struct
124 // it won't be correct unless you use it correctly
125 // and changing the nodes and edges won't update the cost
126
127 public LinkedList nodes, edges;
128 private Cost totalCost;
129 }
Note: See TracBrowser for help on using the browser.