### Question:
DataDetector implements CellDetector<IntegerRange> { @Override public ValuesWithConfidence<IntegerRange> detect(CellSampler sampler) { int expectedCellCount = getExpectedCount(sampler); NonEmptyPredicate nonEmptyPredicate = new NonEmptyPredicate(); int firstDataRow = -1; for (int r = 0, n = sampler.getBeginningSampleCells().size(); r < n; r++) { List<? extends String> row = sampler.getBeginningSampleCells().get(r); boolean isDataRow = row.size() == expectedCellCount && row.stream().anyMatch(nonEmptyPredicate); if (isDataRow) { firstDataRow = r; break; } } int lastDataRow = -1; for (int r = sampler.getEndingSampleCells().size() - 1; r >= 0; --r) { List<? extends String> row = sampler.getEndingSampleCells().get(r); boolean isDataRow = row.size() == expectedCellCount && row.stream().anyMatch(nonEmptyPredicate); if (isDataRow) { lastDataRow = r + sampler.getEndingSampleLinesIndexOffset(); break; } } float confidence = firstDataRow == -1 ? 0f : 1f; return new ValuesWithConfidence<IntegerRange>(new IntegerRange(firstDataRow, lastDataRow), confidence); }  @Override ValuesWithConfidence<IntegerRange> detect(CellSampler sampler);  }### Answer:
@Test public void testNoHeader() { List<String> rows = CsvTestUtils.createSparseRowData(); CellSampler sampler = new ListCellSampler(rows, rows, Character.valueOf(','), null, true); ValuesWithConfidence<IntegerRange> result = new DataDetector().detect(sampler); Assert.assertEquals(1f, result.getBestConfidence(), 0f); Assert.assertEquals(0, result.getBestValue().getMin().intValue()); Assert.assertEquals(23, result.getBestValue().getMax().intValue()); }
@Test public void testWithHeader() { List<String> rows = CsvTestUtils.createSparseRowData(); CellSampler sampler = new ListCellSampler(rows, rows, Character.valueOf(','), null); ValuesWithConfidence<IntegerRange> result = new DataDetector().detect(sampler); Assert.assertEquals(1f, result.getBestConfidence(), 0f); Assert.assertEquals(2, result.getBestValue().getMin().intValue()); Assert.assertEquals(22, result.getBestValue().getMax().intValue()); }