diff options
author | Jed Estep <jestep@google.com> | 2015-12-18 16:23:30 -0800 |
---|---|---|
committer | Jed Estep <jestep@google.com> | 2015-12-21 10:38:15 -0800 |
commit | 641d2e02a9a1f8e5091985289cc485da723bc5eb (patch) | |
tree | 49af3c77eeba79ff56bfbd0167db8f324f162b2a | |
parent | 21a5f6afae53e05fdfe9c9ee2cc82d9b8f9da37e (diff) | |
download | loganalysis-641d2e02a9a1f8e5091985289cc485da723bc5eb.tar.gz |
Add a clear() method for LogcatParser
At present the only way to get a new LogcatItem is to reinstantiate the
LogcatParser; adding clear() will allow each parser to easily produce
multiple LogcatItems during its lifetime.
Change-Id: I0025d8509d75936d9bb29b94f278b788f4a2ab91
-rw-r--r-- | src/com/android/loganalysis/parser/LogcatParser.java | 9 | ||||
-rw-r--r-- | tests/src/com/android/loganalysis/parser/LogcatParserTest.java | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/com/android/loganalysis/parser/LogcatParser.java b/src/com/android/loganalysis/parser/LogcatParser.java index f64936c..ae3cf62 100644 --- a/src/com/android/loganalysis/parser/LogcatParser.java +++ b/src/com/android/loganalysis/parser/LogcatParser.java @@ -194,6 +194,15 @@ public class LogcatParser implements IParser { } /** + * Clear the existing {@link LogcatItem}. The next parse will create a new one. + */ + public void clear() { + mLogcat = null; + mDataList.clear(); + mDataMap.clear(); + } + + /** * Parse a line of input. * * @param line The line to parse diff --git a/tests/src/com/android/loganalysis/parser/LogcatParserTest.java b/tests/src/com/android/loganalysis/parser/LogcatParserTest.java index d45b06c..b8170f7 100644 --- a/tests/src/com/android/loganalysis/parser/LogcatParserTest.java +++ b/tests/src/com/android/loganalysis/parser/LogcatParserTest.java @@ -748,6 +748,24 @@ public class LogcatParserTest extends TestCase { assertNull(item); } + /** + * Test that after clearing a parser, reusing it produces a new LogcatItem instead of + * appending to the previous one. + */ + public void testClear() { + List<String> lines = Arrays.asList( + "04-25 18:33:28.273 7813 7813 E HelloTag: GetBufferLock timed out for thread 7813 buffer 0x61 usage 0x200 LockState 1", + "04-25 18:33:28.273 7813 7813 E GoodbyeTag: GetBufferLock timed out for thread 7813 buffer 0x61 usage 0x200 LockState 1" + ); + LogcatParser parser = new LogcatParser(); + LogcatItem l1 = parser.parse(lines.subList(0, 1)); + parser.clear(); + LogcatItem l2 = parser.parse(lines.subList(1, 2)); + assertEquals(l1.getEvents().size(), 1); + assertEquals(l2.getEvents().size(), 1); + assertFalse(l1.getEvents().get(0).getTag().equals(l2.getEvents().get(0).getTag())); + } + private Date parseTime(String timeStr) throws ParseException { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); return formatter.parse(timeStr); |