@Test public void readData() throws IOException { String[] arr; List<ScreenStateInfo> listScreenStateInfo; Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.414092110985E9 ON 15 30.0", "1.414092182923E9 OFF", "1.414092195631E9 ON 15 32.0", "1.414092264469E9 ON 15 33.0", "1.414092292153E9 OFF", "1.414092303535E9 ON 15 35.0" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); assertEquals(6, listScreenStateInfo.size(), 0); assertEquals(1.414092110985E9, listScreenStateInfo.get(0).getBeginTimeStamp(), 0); assertEquals("SCREEN_ON", listScreenStateInfo.get(0).getScreenState().toString()); assertEquals(15, listScreenStateInfo.get(0).getScreenTimeout(), 0); assertEquals("30.0", listScreenStateInfo.get(0).getScreenBrightness()); assertEquals(1.414092182923E9, listScreenStateInfo.get(1).getBeginTimeStamp(), 0); assertEquals("SCREEN_OFF", listScreenStateInfo.get(1).getScreenState().toString()); assertEquals(1.414092303535E9, listScreenStateInfo.get(5).getBeginTimeStamp(), 0); assertEquals("SCREEN_ON", listScreenStateInfo.get(5).getScreenState().toString()); assertEquals(15, listScreenStateInfo.get(5).getScreenTimeout(), 0); assertEquals("35.0", listScreenStateInfo.get(5).getScreenBrightness()); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.414092110985E9 OFF", "1.414092182923E9 ON 15 30.0", "1.414092195631E9 ON 15 32.0" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.414092110986E9 UNKNOWN", "1.414092182923E9 ON 15 30.0", "1.414092195631E9 ON 15 32.0" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); assertEquals(3, listScreenStateInfo.size(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.414092110985E9 OFF", "1.414092182923E9 ON 15 30.0", "1.414092264469E9 UNKNOWN", "1.414092292153E9", "1.414092264469E9 blah" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "", "1.414092182923E9 ON 15 30.0", "1.414092264469E9 UNKNOWN", "1.414092292153E9 OFF", "1.414092264469E9 blah" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(false); arr = new String[] { "1.414092110985E9 OFF", "1.414092264469E9 blah" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); traceDataReader.setFileReader(filereader); listScreenStateInfo = traceDataReader.readData("/", 0, 0); assertEquals(0, listScreenStateInfo.size(), 0); }
@Override public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) { List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE; if (!filereader.fileExist(filepath)) { return screenStateInfos; } double beginTime = 0.0; double endTime = 0.0; ScreenState prevScreenState = null; ScreenState screenState; String prevBrigtness = null; String brightness = null; int prevTimeOut = 0; int timeout = 0; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open Screen State 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.SCREEN_ON.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_ON; if (strFieldsFirstLine.length >= 4) { prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]); prevBrigtness = strFieldsFirstLine[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + firstLine); prevScreenState = ScreenState.SCREEN_UNKNOWN; } } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized screen state 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); brightness = null; timeout = 0; if (TraceDataConst.SCREEN_ON.equals(strFields[1])) { screenState = ScreenState.SCREEN_ON; if (strFields.length >= 4) { timeout = Integer.parseInt(strFields[2]); brightness = strFields[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) { screenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + strLineBuf); screenState = ScreenState.SCREEN_UNKNOWN; } ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut); screenStateInfos.add(screenInfo); prevScreenState = screenState; prevBrigtness = brightness; prevTimeOut = timeout; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized screen state event: " + strLineBuf); } } screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut)); } return screenStateInfos; }
ScreenStateInfoReaderImpl extends PeripheralBase implements IScreenStateInfoReader { @Override public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) { List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE; if (!filereader.fileExist(filepath)) { return screenStateInfos; } double beginTime = 0.0; double endTime = 0.0; ScreenState prevScreenState = null; ScreenState screenState; String prevBrigtness = null; String brightness = null; int prevTimeOut = 0; int timeout = 0; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open Screen State 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.SCREEN_ON.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_ON; if (strFieldsFirstLine.length >= 4) { prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]); prevBrigtness = strFieldsFirstLine[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + firstLine); prevScreenState = ScreenState.SCREEN_UNKNOWN; } } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized screen state 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); brightness = null; timeout = 0; if (TraceDataConst.SCREEN_ON.equals(strFields[1])) { screenState = ScreenState.SCREEN_ON; if (strFields.length >= 4) { timeout = Integer.parseInt(strFields[2]); brightness = strFields[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) { screenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + strLineBuf); screenState = ScreenState.SCREEN_UNKNOWN; } ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut); screenStateInfos.add(screenInfo); prevScreenState = screenState; prevBrigtness = brightness; prevTimeOut = timeout; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized screen state event: " + strLineBuf); } } screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut)); } return screenStateInfos; } }
ScreenStateInfoReaderImpl extends PeripheralBase implements IScreenStateInfoReader { @Override public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) { List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE; if (!filereader.fileExist(filepath)) { return screenStateInfos; } double beginTime = 0.0; double endTime = 0.0; ScreenState prevScreenState = null; ScreenState screenState; String prevBrigtness = null; String brightness = null; int prevTimeOut = 0; int timeout = 0; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open Screen State 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.SCREEN_ON.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_ON; if (strFieldsFirstLine.length >= 4) { prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]); prevBrigtness = strFieldsFirstLine[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + firstLine); prevScreenState = ScreenState.SCREEN_UNKNOWN; } } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized screen state 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); brightness = null; timeout = 0; if (TraceDataConst.SCREEN_ON.equals(strFields[1])) { screenState = ScreenState.SCREEN_ON; if (strFields.length >= 4) { timeout = Integer.parseInt(strFields[2]); brightness = strFields[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) { screenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + strLineBuf); screenState = ScreenState.SCREEN_UNKNOWN; } ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut); screenStateInfos.add(screenInfo); prevScreenState = screenState; prevBrigtness = brightness; prevTimeOut = timeout; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized screen state event: " + strLineBuf); } } screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut)); } return screenStateInfos; }  }
ScreenStateInfoReaderImpl extends PeripheralBase implements IScreenStateInfoReader { @Override public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) { List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE; if (!filereader.fileExist(filepath)) { return screenStateInfos; } double beginTime = 0.0; double endTime = 0.0; ScreenState prevScreenState = null; ScreenState screenState; String prevBrigtness = null; String brightness = null; int prevTimeOut = 0; int timeout = 0; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open Screen State 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.SCREEN_ON.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_ON; if (strFieldsFirstLine.length >= 4) { prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]); prevBrigtness = strFieldsFirstLine[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + firstLine); prevScreenState = ScreenState.SCREEN_UNKNOWN; } } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized screen state 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); brightness = null; timeout = 0; if (TraceDataConst.SCREEN_ON.equals(strFields[1])) { screenState = ScreenState.SCREEN_ON; if (strFields.length >= 4) { timeout = Integer.parseInt(strFields[2]); brightness = strFields[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) { screenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + strLineBuf); screenState = ScreenState.SCREEN_UNKNOWN; } ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut); screenStateInfos.add(screenInfo); prevScreenState = screenState; prevBrigtness = brightness; prevTimeOut = timeout; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized screen state event: " + strLineBuf); } } screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut)); } return screenStateInfos; }  @Override List<ScreenStateInfo> readData(String directory, double startTime,
			double traceDuration); }
ScreenStateInfoReaderImpl extends PeripheralBase implements IScreenStateInfoReader { @Override public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) { List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE; if (!filereader.fileExist(filepath)) { return screenStateInfos; } double beginTime = 0.0; double endTime = 0.0; ScreenState prevScreenState = null; ScreenState screenState; String prevBrigtness = null; String brightness = null; int prevTimeOut = 0; int timeout = 0; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open Screen State 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.SCREEN_ON.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_ON; if (strFieldsFirstLine.length >= 4) { prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]); prevBrigtness = strFieldsFirstLine[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) { prevScreenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + firstLine); prevScreenState = ScreenState.SCREEN_UNKNOWN; } } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: " + firstLine, e); } } else { LOGGER.warn("Unrecognized screen state 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); brightness = null; timeout = 0; if (TraceDataConst.SCREEN_ON.equals(strFields[1])) { screenState = ScreenState.SCREEN_ON; if (strFields.length >= 4) { timeout = Integer.parseInt(strFields[2]); brightness = strFields[3]; } } else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) { screenState = ScreenState.SCREEN_OFF; } else { LOGGER.warn("Unknown screen state: " + strLineBuf); screenState = ScreenState.SCREEN_UNKNOWN; } ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut); screenStateInfos.add(screenInfo); prevScreenState = screenState; prevBrigtness = brightness; prevTimeOut = timeout; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error in screen events: "+ strLineBuf, e); } } else { LOGGER.warn("Unrecognized screen state event: " + strLineBuf); } } screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut)); } return screenStateInfos; }  @Override List<ScreenStateInfo> readData(String directory, double startTime,
			double traceDuration);  }