| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.tools; |
| 20 |
|
| 21 |
import footleg.cavesurvey.data.model.SurveyLeg; |
| 22 |
import footleg.cavesurvey.data.model.SurveySeries; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public final class SurveyProcessing { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static boolean generateSeriesFromFullPathStationNames( SurveySeries series ) { |
| 41 |
boolean rearranged = false; |
| 42 |
|
| 43 |
if ( series.innerSeriesCount() == 0 ) { |
| 44 |
int matchingChildSeriesIdx = -1; |
| 45 |
|
| 46 |
|
| 47 |
for (int legIdx = 0; legIdx < series.legCount(); legIdx++) { |
| 48 |
SurveyLeg leg = series.getLegRaw( legIdx ); |
| 49 |
|
| 50 |
|
| 51 |
String fromStnName = leg.getFromStn().getName(); |
| 52 |
int sepPos = fromStnName.indexOf('.'); |
| 53 |
if ( sepPos > 0 ) { |
| 54 |
String prefix = fromStnName.substring(0, sepPos); |
| 55 |
|
| 56 |
|
| 57 |
if ( series.innerSeriesCount() > 0 ) { |
| 58 |
if ( series.getInnerSeries( matchingChildSeriesIdx ).getSeriesName().equals( prefix ) == false ) { |
| 59 |
|
| 60 |
matchingChildSeriesIdx = -1; |
| 61 |
for ( int j = 0; j < series.innerSeriesCount(); j++ ) { |
| 62 |
if ( series.getInnerSeries( j ).getSeriesName().equals( prefix ) ) { |
| 63 |
|
| 64 |
matchingChildSeriesIdx = j; |
| 65 |
break; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
if ( matchingChildSeriesIdx == -1 ) { |
| 73 |
SurveySeries newSeries = new SurveySeries( prefix ); |
| 74 |
series.addSeries(newSeries ); |
| 75 |
matchingChildSeriesIdx = series.innerSeriesCount() - 1; |
| 76 |
} |
| 77 |
|
| 78 |
String newFromName = fromStnName.substring( sepPos + 1 ); |
| 79 |
leg.getFromStn().setName(newFromName); |
| 80 |
|
| 81 |
|
| 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 |
|
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
series.getInnerSeries( matchingChildSeriesIdx ).addLeg (leg ); |
| 96 |
|
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 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 |
} |