use of suite.text.TwoPassIndexer.Reference in project suite by stupidsing.
the class TwoPassIndexerTest method test.
@Test
public void test() {
List<String> filenames = //
FileUtil.findPaths(Paths.get("src/test/java")).map(//
Path::toAbsolutePath).map(//
Path::toString).filter(//
filename -> filename.endsWith(".java")).toList();
TwoPassIndexer indexer = new TwoPassIndexer();
for (String filename : filenames) indexer.pass0(filename, FileUtil.read(filename));
for (String filename : filenames) indexer.pass1(filename, FileUtil.read(filename));
Map<String, List<Reference>> map = indexer.getReferencesByWord();
List<Entry<String, List<Reference>>> entries = //
List_.sort(//
map.entrySet(), (e0, e1) -> e1.getValue().size() - e0.getValue().size());
System.out.println("Most popular key words:");
for (int i = 0; i < 32; i++) {
Entry<String, List<Reference>> entry = entries.get(i);
System.out.println(String.format("%-5d \"%s\"", entry.getValue().size(), entry.getKey()));
}
System.out.println();
for (Reference key : indexer.search("IOException")) System.out.println("IOException found in " + key);
}