CSVFastHeaderAndTypeAnalyzer { public List<Pair<String, Type>> getHeaders() { if (!analysisPerformed) { analyze(); } return headers; } CSVFastHeaderAndTypeAnalyzer(List<String> sampleLines, Separator separator); void analyze(); boolean isFirstLineAHeader(); List<Pair<String, Type>> getHeaders(); boolean isHeaderInfoReliable();  }
@Test public void should_strip_quotes_in_header() { List<String> list = Arrays.asList("\"user_id\";\"birth\";\"country\";page_visited;first_item", "4dc1548af;11/9/1970;France;6.0;22.0"); Separator separator = new Separator(';'); separator.incrementCount(1); CSVFastHeaderAndTypeAnalyzer analysis = new CSVFastHeaderAndTypeAnalyzer(list, separator); List<String> expectedHeaders = Arrays.asList("user_id", "birth", "country", "page_visited", "first_item"); Assert.assertArrayEquals(expectedHeaders.toArray(), analysis.getHeaders().stream().map(p -> p.getKey()).toArray()); }
@Test public void should_not_detect_first_line_as_column() { List<String> list = Arrays.asList("\"1000800\",\"2.0 PET X8 LIFT SOUR CHERRY\"", "\"1001000\",\"1.0 RGB X12 COCA COLA\"", "\"1001300\",\"2.0 PET X6 LILIA\""); Separator separator = new Separator(','); separator.incrementCount(1); separator.incrementCount(2); separator.incrementCount(3); CSVFastHeaderAndTypeAnalyzer analysis = new CSVFastHeaderAndTypeAnalyzer(list, separator); List<String> expectedHeaders = Arrays.asList("COL1", "COL2"); Assert.assertArrayEquals(expectedHeaders.toArray(), analysis.getHeaders().stream().map(p -> p.getKey()).toArray()); }