?? parser.java
字號:
package Reader;
import java.util.NoSuchElementException;
public class Parser {
public static final int TYPE_NA = -1;
public static final int TYPE_START = -2;
public static final int TYPE_GPRMC = 0;
public static final int TYPE_GPGGA = 1;
public static int parse(String s, Record record)
throws UnsupportedTypeException, ParseException {
// Tokenizer to separate tokens
Tokenizer tokenizer = new Tokenizer(s);
// Type of record
int type;
try {
String token = tokenizer.next();
System.out.print("++++++++++++");
if (token.equals("$GPRMC")) {
type = TYPE_GPRMC;
token = tokenizer.next();
record.dateTimeOfFix = token.substring(0, 2) + ":"
+ token.substring(2, 4) + ":" + token.substring(4, 6);
record.warning = tokenizer.next().equals(Record.WARNING);
record.lattitude = tokenizer.next();
record.lattitudeDirection = tokenizer.next();
record.longitude = tokenizer.next();
record.longitudeDirection = tokenizer.next();
record.groundSpeed = tokenizer.next();
record.courseMadeGood = tokenizer.next();
token = tokenizer.next();
record.dateTimeOfFix += "/" + token.substring(0, 2) + "."
+ token.substring(2, 4) + "." + token.substring(4, 6);
record.magneticVariation = tokenizer.next();
} else if (token.equals("$GPGGA")) {
type = TYPE_GPGGA;
// Time of fix
tokenizer.next();
// Lattitude
tokenizer.next();
// Lattitude direction
tokenizer.next();
// Longitude
tokenizer.next();
// Longitude direction
tokenizer.next();
record.quality = tokenizer.next();
record.satelliteCount = tokenizer.next();
// Ignore rest
}
// Type is not supported.
else {
throw new UnsupportedTypeException("Type " + token
+ " is not supported.");
}
}
// Parsing exception.
catch (NoSuchElementException e) {
throw new ParseException("Unexpected end of input.");
}
return type;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -