1    /* Copyright (C) 2002 Martin Green
2     *
3     * This program is free software; you can redistribute it and/or modify
4     * it under the terms of the GNU General Public License as published by
5     * the Free Software Foundation; either version 2 of the License, or
6     * (at your option) any later version.
7     *
8     * This program is distributed in the hope that it will be useful,
9     * but WITHOUT ANY WARRANTY; without even the implied warranty of
10    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    * GNU General Public License for more details.
12    *
13    * You should have received a copy of the GNU General Public License
14    * along with this program; if not, write to the Free Software
15    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16    */
17   
18   import java.util.Vector;
19   
20   public class SurvexSurvey
21   {
22           public Vector subsurveys = new Vector(0,1);
23           public Vector names = new Vector(0,1);
24           public Vector legs = new Vector(0,1);
25           public Vector stations = new Vector(0,1);
26           public String surveyname;
27           public void addname(String stringname, Name name)
28           	{
29           		int dotnumber = stringname.indexOf(".");
30           		if (dotnumber == -1)
31           		{
32           			this.names.addElement(name);
33           		}
34           		else
35           		{
36           			String surveyname = stringname.substring(0,dotnumber);
37           			String restname = stringname.substring(dotnumber+1);
38           			int surveyindex = -1;
39           			for (int index=0;index<this.subsurveys.size();index++)
40           			{
41           				if (surveyname.equals(((SurvexSurvey)this.subsurveys.elementAt(index)).surveyname))
42           				{
43           					surveyindex=index;
44           				}
45           			}
46           			if(surveyindex==-1)
47           			{
48           				SurvexSurvey newsurvey = new SurvexSurvey();
49           				newsurvey.surveyname = surveyname;
50           				this.subsurveys.addElement(newsurvey);
51           				((SurvexSurvey)this.subsurveys.lastElement()).addname(restname,name);
52           			}
53           			else
54           				((SurvexSurvey)this.subsurveys.elementAt(surveyindex)).addname(restname,name);
55           		}
56           }
57           
58           	public void addstation(String stringname, Station station)
59           	{
60           		int dotnumber = stringname.indexOf(".");
61           		if (dotnumber == -1)
62           		{
63           			this.stations.addElement(station);
64           		}
65           		else
66           		{
67           			String surveyname = stringname.substring(0,dotnumber);
68           			String restname = stringname.substring(dotnumber+1);
69           			int surveyindex = -1;
70           			for (int index=0;index<this.subsurveys.size();index++)
71           			{
72           				if (surveyname.equals(((SurvexSurvey)this.subsurveys.elementAt(index)).surveyname))
73           				{
74           					surveyindex=index;
75           				}
76           			}
77           			if(surveyindex==-1)
78           			{
79           				SurvexSurvey newsurvey = new SurvexSurvey();
80           				newsurvey.surveyname = surveyname;
81           				this.subsurveys.addElement(newsurvey);
82           				((SurvexSurvey)this.subsurveys.lastElement()).addstation(restname,station);
83           			}
84           			else
85           				((SurvexSurvey)this.subsurveys.elementAt(surveyindex)).addstation(restname,station);
86           		}
87           }
88           	
89           public void addleg(String stringname, Leg leg)
90           {
91           	int dotnumber = stringname.indexOf(".");
92   
93           	if (stringname.equals(""))
94           	{
95           		this.legs.addElement(leg);
96           	}
97   
98           	else
99           	{
100          		if (dotnumber==-1)
101          		{
102          			int surveyindex = -1;
103          			for (int index=0;index<this.subsurveys.size();index++)
104          			{
105          				if (stringname.equals(((SurvexSurvey)this.subsurveys.elementAt(index)).surveyname))
106          				{
107          					surveyindex=index;
108          				}
109          			}
110          			if(surveyindex==-1)
111          			{
112          				SurvexSurvey newsurvey = new SurvexSurvey();
113          				newsurvey.surveyname = stringname;
114          				this.subsurveys.addElement(newsurvey);
115          				((SurvexSurvey)this.subsurveys.lastElement()).addleg("",leg);
116          			}
117          			else
118          				((SurvexSurvey)this.subsurveys.elementAt(surveyindex)).addleg("",leg);
119          		}
120          		else
121          		{
122          			String surveyname = stringname.substring(0,dotnumber);				
123          			String restname = stringname.substring(dotnumber+1);
124          			int surveyindex = -1;
125          			for (int index=0;index<this.subsurveys.size();index++)
126          			{
127          				if (surveyname.equals(((SurvexSurvey)this.subsurveys.elementAt(index)).surveyname))
128          				{
129          					surveyindex=index;
130          				}
131          			}
132          			if(surveyindex==-1)
133          			{
134          				SurvexSurvey newsurvey = new SurvexSurvey();
135          				newsurvey.surveyname = surveyname;
136          				this.subsurveys.addElement(newsurvey);
137          				((SurvexSurvey)this.subsurveys.lastElement()).addleg(restname,leg);
138          			}
139          			else
140          				((SurvexSurvey)this.subsurveys.elementAt(surveyindex)).addleg(restname,leg);
141          		}
142          	}
143          }
144  }
145