@Test public void readData_nullData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(null); info = cameraReader.readData(traceFolder, 0, 0); assertTrue(info.size() == 0); }
@Override public List<CameraInfo> readData(String directory, double startTime, double traceDuration) { this.activeDuration = 0; List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.CAMERA_FILE; if (!filereader.fileExist(filepath)) { return cameraInfos; } double beginTime = 0.0; double endTime; double dLastActiveTimeStamp = 0.0; double dActiveDuration = 0.0; CameraState prevCameraState = null; CameraState cameraState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Camera info file: "+filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = beginTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + firstLine); prevCameraState = CameraState.CAMERA_UNKNOWN; } if ((!TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (beginTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized camera event: " + firstLine); } for (int i=1;i<lines.length;i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFields[1])) { cameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = endTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFields[1])) { cameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + strLineBuf); cameraState = CameraState.CAMERA_UNKNOWN; } cameraInfos.add(new CameraInfo(beginTime, endTime, prevCameraState)); if ((!TraceDataConst.CAMERA_ON.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (endTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } prevCameraState = cameraState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized camera event: " + strLineBuf); } } cameraInfos.add(new CameraInfo(beginTime, traceDuration, prevCameraState)); if (cameraState == CameraState.CAMERA_ON) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.activeDuration = dActiveDuration; } return cameraInfos; }
CameraInfoReaderImpl extends PeripheralBase implements ICameraInfoReader { @Override public List<CameraInfo> readData(String directory, double startTime, double traceDuration) { this.activeDuration = 0; List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.CAMERA_FILE; if (!filereader.fileExist(filepath)) { return cameraInfos; } double beginTime = 0.0; double endTime; double dLastActiveTimeStamp = 0.0; double dActiveDuration = 0.0; CameraState prevCameraState = null; CameraState cameraState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Camera info file: "+filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = beginTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + firstLine); prevCameraState = CameraState.CAMERA_UNKNOWN; } if ((!TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (beginTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized camera event: " + firstLine); } for (int i=1;i<lines.length;i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFields[1])) { cameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = endTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFields[1])) { cameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + strLineBuf); cameraState = CameraState.CAMERA_UNKNOWN; } cameraInfos.add(new CameraInfo(beginTime, endTime, prevCameraState)); if ((!TraceDataConst.CAMERA_ON.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (endTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } prevCameraState = cameraState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized camera event: " + strLineBuf); } } cameraInfos.add(new CameraInfo(beginTime, traceDuration, prevCameraState)); if (cameraState == CameraState.CAMERA_ON) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.activeDuration = dActiveDuration; } return cameraInfos; } }
CameraInfoReaderImpl extends PeripheralBase implements ICameraInfoReader { @Override public List<CameraInfo> readData(String directory, double startTime, double traceDuration) { this.activeDuration = 0; List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.CAMERA_FILE; if (!filereader.fileExist(filepath)) { return cameraInfos; } double beginTime = 0.0; double endTime; double dLastActiveTimeStamp = 0.0; double dActiveDuration = 0.0; CameraState prevCameraState = null; CameraState cameraState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Camera info file: "+filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = beginTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + firstLine); prevCameraState = CameraState.CAMERA_UNKNOWN; } if ((!TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (beginTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized camera event: " + firstLine); } for (int i=1;i<lines.length;i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFields[1])) { cameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = endTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFields[1])) { cameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + strLineBuf); cameraState = CameraState.CAMERA_UNKNOWN; } cameraInfos.add(new CameraInfo(beginTime, endTime, prevCameraState)); if ((!TraceDataConst.CAMERA_ON.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (endTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } prevCameraState = cameraState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized camera event: " + strLineBuf); } } cameraInfos.add(new CameraInfo(beginTime, traceDuration, prevCameraState)); if (cameraState == CameraState.CAMERA_ON) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.activeDuration = dActiveDuration; } return cameraInfos; }  }
CameraInfoReaderImpl extends PeripheralBase implements ICameraInfoReader { @Override public List<CameraInfo> readData(String directory, double startTime, double traceDuration) { this.activeDuration = 0; List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.CAMERA_FILE; if (!filereader.fileExist(filepath)) { return cameraInfos; } double beginTime = 0.0; double endTime; double dLastActiveTimeStamp = 0.0; double dActiveDuration = 0.0; CameraState prevCameraState = null; CameraState cameraState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Camera info file: "+filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = beginTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + firstLine); prevCameraState = CameraState.CAMERA_UNKNOWN; } if ((!TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (beginTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized camera event: " + firstLine); } for (int i=1;i<lines.length;i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFields[1])) { cameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = endTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFields[1])) { cameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + strLineBuf); cameraState = CameraState.CAMERA_UNKNOWN; } cameraInfos.add(new CameraInfo(beginTime, endTime, prevCameraState)); if ((!TraceDataConst.CAMERA_ON.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (endTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } prevCameraState = cameraState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized camera event: " + strLineBuf); } } cameraInfos.add(new CameraInfo(beginTime, traceDuration, prevCameraState)); if (cameraState == CameraState.CAMERA_ON) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.activeDuration = dActiveDuration; } return cameraInfos; }  @Override List<CameraInfo> readData(String directory, double startTime,
			double traceDuration); @Override double getActiveDuration(); }
CameraInfoReaderImpl extends PeripheralBase implements ICameraInfoReader { @Override public List<CameraInfo> readData(String directory, double startTime, double traceDuration) { this.activeDuration = 0; List<CameraInfo> cameraInfos = new ArrayList<CameraInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.CAMERA_FILE; if (!filereader.fileExist(filepath)) { return cameraInfos; } double beginTime = 0.0; double endTime; double dLastActiveTimeStamp = 0.0; double dActiveDuration = 0.0; CameraState prevCameraState = null; CameraState cameraState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Camera info file: "+filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = beginTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFieldsFirstLine[1])) { prevCameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + firstLine); prevCameraState = CameraState.CAMERA_UNKNOWN; } if ((!TraceDataConst.CAMERA_ON.equals(strFieldsFirstLine[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (beginTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized camera event: " + firstLine); } for (int i=1;i<lines.length;i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); if (TraceDataConst.CAMERA_ON.equals(strFields[1])) { cameraState = CameraState.CAMERA_ON; if (0.0 == dLastActiveTimeStamp) { dLastActiveTimeStamp = endTime; } } else if (TraceDataConst.CAMERA_OFF.equals(strFields[1])) { cameraState = CameraState.CAMERA_OFF; } else { LOGGER.warn("Unknown camera state: " + strLineBuf); cameraState = CameraState.CAMERA_UNKNOWN; } cameraInfos.add(new CameraInfo(beginTime, endTime, prevCameraState)); if ((!TraceDataConst.CAMERA_ON.equals(strFields[1])) && dLastActiveTimeStamp > 0.0) { dActiveDuration += (endTime - dLastActiveTimeStamp); dLastActiveTimeStamp = 0.0; } prevCameraState = cameraState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in camera events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized camera event: " + strLineBuf); } } cameraInfos.add(new CameraInfo(beginTime, traceDuration, prevCameraState)); if (cameraState == CameraState.CAMERA_ON) { dActiveDuration += Math.max(0, traceDuration - dLastActiveTimeStamp); } this.activeDuration = dActiveDuration; } return cameraInfos; }  @Override List<CameraInfo> readData(String directory, double startTime,
			double traceDuration); @Override double getActiveDuration();  }