Debian Codegraph @

src/footleg/cavesurvey/tools/SurveyProcessing.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2015-2015 Paul Fretwell - aka 'Footleg' ([email protected])
3 *
4 * This file is part of Cave Converter.
5 *
6 * Cave Converter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Cave Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Cave Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package footleg.cavesurvey.tools;
20
21 import footleg.cavesurvey.data.model.SurveyLeg;
22 import footleg.cavesurvey.data.model.SurveySeries;
23
24 /**
25 * Data processing class for functions which process survey data.
26 *
27 * @author Footleg
28 * @version 2015.11.09 (ISO 8601 YYYY.MM.DD)
29 * @since 1.6 (The Java version used)
30 */
31 public final class SurveyProcessing {
32
33 /**
34 * Check the series for station names containing a dot separator, and if found then reorganise
35 * the series into a set of nested series using the full path name of the series to define the
36 * child series which the stations belong to. Only process series containing legs.
37 * @param series The survey series to rearrange
38 * @return True if series was rearranged
39 */
40 public static boolean generateSeriesFromFullPathStationNames( SurveySeries series ) {
41 boolean rearranged = false;
42
43 if ( series.innerSeriesCount() == 0 ) {
44 int matchingChildSeriesIdx = -1;
45
46 //Loop through all legs in the series
47 for (int legIdx = 0; legIdx < series.legCount(); legIdx++) {
48 SurveyLeg leg = series.getLegRaw( legIdx );
49
50 //Check fromStn name and check for dot separator
51 String fromStnName = leg.getFromStn().getName();
52 int sepPos = fromStnName.indexOf('.');
53 if ( sepPos > 0 ) {
54 String prefix = fromStnName.substring(0, sepPos);
55
56 //Check for child series matching the name of the prefix
57 if ( series.innerSeriesCount() > 0 ) {
58 if ( series.getInnerSeries( matchingChildSeriesIdx ).getSeriesName().equals( prefix ) == false ) {
59 //Need to search all inner series for match
60 matchingChildSeriesIdx = -1;
61 for ( int j = 0; j < series.innerSeriesCount(); j++ ) {
62 if ( series.getInnerSeries( j ).getSeriesName().equals( prefix ) ) {
63 //Store matching index
64 matchingChildSeriesIdx = j;
65 break;
66 }
67 }
68 }
69 }
70
71 //Create new child series if matching series not found
72 if ( matchingChildSeriesIdx == -1 ) {
73 SurveySeries newSeries = new SurveySeries( prefix );
74 series.addSeries(newSeries );
75 matchingChildSeriesIdx = series.innerSeriesCount() - 1;
76 }
77 //Remove prefix from fromStn name
78 String newFromName = fromStnName.substring( sepPos + 1 );
79 leg.getFromStn().setName(newFromName);
80
81 //If to station shares the same prefix, then remove prefix from that
82 String toStnName = leg.getToStn().getName();
83 int sepToPos = toStnName.indexOf('.');
84 if ( sepToPos > 0 ) {
85 if ( toStnName.substring(0, sepToPos).equals( prefix ) ) {
86 String newToName = toStnName.substring( sepToPos + 1 );
87 leg.getToStn().setName(newToName);
88 }
89 }
90 else {
91 //Otherwise, we need an equate from the toStn to the equivalent station in the series it matches
92 }
93
94 //Put leg into child series
95 series.getInnerSeries( matchingChildSeriesIdx ).addLeg (leg );
96
97 }
98 }
99
100 //Loop through all legs and remove them from the series
101 for (int legIdx = series.legCount() - 1; legIdx >= 0; legIdx--) {
102 series.removeLeg( legIdx );
103 }
104 rearranged = true;
105 }
106
107 return rearranged;
108 }
109 }