| 1 | /** |
| 2 | * Copyright (C) 2009-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.data.model; |
| 20 | |
| 21 | /** |
| 22 | * Class to represent an equate between two survey stations in different series |
| 23 | * |
| 24 | * @author Footleg |
| 25 | * @version 2015.08.31 (ISO 8601 YYYY.MM.DD) |
| 26 | * @since 1.6 (The Java version used) |
| 27 | * |
| 28 | */ |
| 29 | public class Equate { |
| 30 | private String series1; |
| 31 | private String stn1; |
| 32 | private String series2; |
| 33 | private String stn2; |
| 34 | |
| 35 | /** |
| 36 | * Create an equate defining the link between two stations in two series |
| 37 | * |
| 38 | * @param seriesPrefix1 Full path to the first series |
| 39 | * @param stnName1 Name of the station in the first series joining to the second series |
| 40 | * @param seriesPrefix2 Full path to the second series |
| 41 | * @param stnName2 Name of the station in the second series joining to the first series |
| 42 | */ |
| 43 | public Equate(String seriesPrefix1, String stnName1, String seriesPrefix2, String stnName2) { |
| 44 | //Need to combine series prefix with station name and then split off |
| 45 | //the station name from full series name |
| 46 | String[] resplitStnRef1 = combineAndResplitFullStnRef( seriesPrefix1, stnName1 ); |
| 47 | String[] resplitStnRef2 = combineAndResplitFullStnRef( seriesPrefix2, stnName2 ); |
| 48 | |
| 49 | this.series1 = resplitStnRef1[0]; |
| 50 | this.stn1 = resplitStnRef1[1]; |
| 51 | this.series2 = resplitStnRef2[0]; |
| 52 | this.stn2 = resplitStnRef2[1]; |
| 53 | } |
| 54 | |
| 55 | public String getSeries1() { |
| 56 | return series1; |
| 57 | } |
| 58 | |
| 59 | public String getStn1() { |
| 60 | return stn1; |
| 61 | } |
| 62 | |
| 63 | public String getSeries2() { |
| 64 | return series2; |
| 65 | } |
| 66 | |
| 67 | public String getStn2() { |
| 68 | return stn2; |
| 69 | } |
| 70 | |
| 71 | private String[] combineAndResplitFullStnRef( String seriesPrefix, String stnName ) { |
| 72 | String[] results = new String[2]; |
| 73 | |
| 74 | //Combine prefix and station name into fully qualified station reference |
| 75 | String fullStnRef = seriesPrefix + "." + stnName; |
| 76 | |
| 77 | //Split series name from station name |
| 78 | int pos = fullStnRef.lastIndexOf('.'); |
| 79 | if ( pos > 0 ) { |
| 80 | //Split at this position |
| 81 | results[0] = fullStnRef.substring( 0, pos ); |
| 82 | results[1] = fullStnRef.substring( pos + 1 ); |
| 83 | } |
| 84 | else { |
| 85 | //No '.' separator in equate, so throw error |
| 86 | throw new RuntimeException( "Equate does not contain a series name and station." ); |
| 87 | } |
| 88 | |
| 89 | return results; |
| 90 | } |
| 91 | |
| 92 | } |