1 package tim.prune.drew.jpeg;
3 import java.util.ArrayList;
7 * Class to hold the GPS data extracted from a Jpeg including position and time
8 * All contents are in Rational format
12 private boolean _exifDataPresent = false;
13 private char _latitudeRef = '\0';
14 private char _longitudeRef = '\0';
15 private byte _altitudeRef = 0;
16 private Rational[] _latitude = null;
17 private Rational[] _longitude = null;
18 private Rational _altitude = null;
19 private Rational[] _timestamp = null;
20 private Rational[] _datestamp = null;
21 private ArrayList _errors = null;
25 * Set the exif data present flag
27 public void setExifDataPresent()
29 _exifDataPresent = true;
32 * @return true if exif data found
34 public boolean getExifDataPresent()
36 return _exifDataPresent;
40 * Set the latitude reference (N/S)
41 * @param inChar character representing reference
43 public void setLatitudeRef(char inChar)
45 _latitudeRef = inChar;
49 * Set the latitude reference (N/S)
50 * @param inString string containing reference
52 public void setLatitudeRef(String inString)
54 if (inString != null && inString.length() == 1)
55 setLatitudeRef(inString.charAt(0));
60 * @param inValues array of three Rationals for deg-min-sec
62 public void setLatitude(Rational[] inValues)
64 if (inValues != null && inValues.length == 3)
69 * Set the longitude reference (E/W)
70 * @param inChar character representing reference
72 public void setLongitudeRef(char inChar)
74 _longitudeRef = inChar;
78 * Set the longitude reference (E/W)
79 * @param inString string containing reference
81 public void setLongitudeRef(String inString)
83 if (inString != null && inString.length() == 1)
84 setLongitudeRef(inString.charAt(0));
89 * @param inValues array of three Rationals for deg-min-sec
91 public void setLongitude(Rational[] inValues)
93 if (inValues != null && inValues.length == 3)
94 _longitude = inValues;
98 * Set the altitude reference (sea level / not)
99 * @param inByte byte representing reference
101 public void setAltitudeRef(byte inByte)
103 _altitudeRef = inByte;
108 * @param inRational Rational number representing altitude
110 public void setAltitude(Rational inRational)
112 _altitude = inRational;
117 * @param inValues array of Rationals holding timestamp
119 public void setTimestamp(Rational[] inValues)
121 _timestamp = inValues;
126 * @param inValues array of Rationals holding datestamp
128 public void setDatestamp(Rational[] inValues)
130 _datestamp = inValues;
133 /** @return latitude ref as char */
134 public char getLatitudeRef() { return _latitudeRef; }
135 /** @return latitude as array of 3 Rationals */
136 public Rational[] getLatitude() { return _latitude; }
137 /** @return longitude ref as char */
138 public char getLongitudeRef() { return _longitudeRef; }
139 /** @return longitude as array of 3 Rationals */
140 public Rational[] getLongitude() { return _longitude; }
141 /** @return altitude ref as byte (should be 0) */
142 public byte getAltitudeRef() { return _altitudeRef; }
143 /** @return altitude as Rational */
144 public Rational getAltitude() { return _altitude; }
145 /** @return timestamp as array of 3 Rationals */
146 public Rational[] getTimestamp() { return _timestamp; }
147 /** @return timestamp as array of 3 Rationals */
148 public Rational[] getDatestamp() { return _datestamp; }
151 * @return true if data looks valid, ie has at least lat and long
152 * (altitude and timestamp optional).
154 public boolean isValid()
156 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
158 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
159 && _longitude != null;
163 * Add the given error message to the list of errors
164 * @param inError String containing error message
166 public void addError(String inError)
168 if (_errors == null) _errors = new ArrayList();
169 _errors.add(inError);
173 * @return the number of errors, if any
175 public int getNumErrors()
177 if (_errors == null) return 0;
178 return _errors.size();
182 * @return true if errors occurred
184 public boolean hasErrors()
186 return getNumErrors() > 0;
190 * @return all errors as a list
192 public List getErrors()