fixed time formats in SwissTiming connector

This commit is contained in:
Axel Uhl committed 2011-09-30 23:29:01 +02:00
1 parent f93a4e1729
commit 8c87a0e8f9
3 files changed
+19 -12

No files matched your search

@@ -2,6 +2,7 @@ package com.sap.sailing.domain.swisstimingadapter;
import java.io.IOException;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.Map;
import com.sap.sailing.domain.base.TimePoint;
@@ -16,7 +17,7 @@ public interface SailMasterConnector {
StartList getStartList(String raceID) throws UnknownHostException, IOException;
TimePoint getStartTime(String raceID) throws UnknownHostException, IOException;
TimePoint getStartTime(String raceID) throws UnknownHostException, IOException, ParseException;
/**
* @param markIndex
@@ -24,7 +25,7 @@ public interface SailMasterConnector {
* @return a map with the single mark index requested by <code>markIndex</code> or all mark indices (in case of
* <code>markIndex==-1</code>) as key; pairs of gap (TODO in milliseconds?) and boat ID as values.
*/
Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException;
Map<Integer, Pair<TimePoint, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException, NumberFormatException, ParseException;
double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) throws UnknownHostException, IOException;
@@ -4,6 +4,9 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -25,6 +28,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
private final String host;
private final int port;
private Socket socket;
private static final DateFormat dateFormat = new SimpleDateFormat("hh:MM:ss");
public SailMasterConnectorImpl(String host, int port) {
super();
@@ -106,7 +110,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public StartList getStartList(String raceID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("StartList|"+raceID);
String[] sections = response.getSections();
assertResponseType("StartList", sections[0]);
assertResponseType("Startlist", sections[0]);
assertRaceID(raceID, sections[1]);
ArrayList<Competitor> competitors = new ArrayList<Competitor>();
for (int i=2; i<sections.length; i++) {
@@ -117,24 +121,26 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
}
@Override
public TimePoint getStartTime(String raceID) throws UnknownHostException, IOException {
public TimePoint getStartTime(String raceID) throws UnknownHostException, IOException, ParseException {
SailMasterMessage response = sendRequestAndGetResponse("RaceTime|"+raceID);
String[] sections = response.getSections();
assertResponseType("RaceTime", sections[0]);
assertRaceID(raceID, sections[1]);
return new MillisecondsTimePoint(Long.valueOf(sections[2]));
return new MillisecondsTimePoint(dateFormat.parse(sections[2]));
}
@Override
public Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException {
public Map<Integer, Pair<TimePoint, String>> getDeltaClockAtMark(String raceID, int markIndex)
throws UnknownHostException, IOException, NumberFormatException, ParseException {
SailMasterMessage response = sendRequestAndGetResponse("ClockAtMark|"+raceID+"|"+markIndex);
String[] sections = response.getSections();
assertResponseType("ClockAtMark", sections[0]);
assertRaceID(raceID, sections[1]);
Map<Integer, Pair<Long, String>> result = new HashMap<Integer, Pair<Long,String>>();
Map<Integer, Pair<TimePoint, String>> result = new HashMap<Integer, Pair<TimePoint,String>>();
for (int i=2; i<sections.length; i+=2) {
String[] markTimeDetail = sections[i+1].split(",");
result.put(Integer.valueOf(sections[i]), new Pair<Long, String>(Long.valueOf(markTimeDetail[0]), markTimeDetail[1]));
result.put(Integer.valueOf(sections[i]), new Pair<TimePoint, String>(
new MillisecondsTimePoint(dateFormat.parse(markTimeDetail[0])), markTimeDetail[1]));
}
return result;
}