@Test public void shouldDeserializeGivenAmountOfParameterEntriesFromReader() throws Exception { StringReader reader = csvEntriesReader(10).usingDelimiter(";").withEntries(10, "entry_%d", "column1", "column2").build(); CsvListReader csvReader = new CsvListReader(reader, csvPreference(config)); CsvParameterEntryBatchLoader batchLoader = new CsvParameterEntryBatchLoader(csvReader); List<ParameterEntry> entries = new ArrayList<ParameterEntry>(); entries.addAll(batchLoader.nextBatch(5)); entries.addAll(batchLoader.nextBatch(5)); assertThat(entries).hasSize(10); }
@Override public Collection<ParameterEntry> nextBatch(int batchSize) { List<ParameterEntry> entries = new ArrayList<ParameterEntry>(batchSize); try { List<String> line; int entriesRead; for (entriesRead = 0; entriesRead < batchSize; ++entriesRead) { line = reader.read(); if (line == null) { break; } entries.add(new DeserializedParameterEntry(line)); } if (entriesRead < batchSize) { hasMore = false; } } catch (IOException exception) { throw new ParamBatchLoadingException("deserialization error", exception); } return entries; }
CsvParameterEntryBatchLoader implements ParameterEntryBatchLoader { @Override public Collection<ParameterEntry> nextBatch(int batchSize) { List<ParameterEntry> entries = new ArrayList<ParameterEntry>(batchSize); try { List<String> line; int entriesRead; for (entriesRead = 0; entriesRead < batchSize; ++entriesRead) { line = reader.read(); if (line == null) { break; } entries.add(new DeserializedParameterEntry(line)); } if (entriesRead < batchSize) { hasMore = false; } } catch (IOException exception) { throw new ParamBatchLoadingException("deserialization error", exception); } return entries; } }
CsvParameterEntryBatchLoader implements ParameterEntryBatchLoader { @Override public Collection<ParameterEntry> nextBatch(int batchSize) { List<ParameterEntry> entries = new ArrayList<ParameterEntry>(batchSize); try { List<String> line; int entriesRead; for (entriesRead = 0; entriesRead < batchSize; ++entriesRead) { line = reader.read(); if (line == null) { break; } entries.add(new DeserializedParameterEntry(line)); } if (entriesRead < batchSize) { hasMore = false; } } catch (IOException exception) { throw new ParamBatchLoadingException("deserialization error", exception); } return entries; } CsvParameterEntryBatchLoader(CsvListReader reader); }
CsvParameterEntryBatchLoader implements ParameterEntryBatchLoader { @Override public Collection<ParameterEntry> nextBatch(int batchSize) { List<ParameterEntry> entries = new ArrayList<ParameterEntry>(batchSize); try { List<String> line; int entriesRead; for (entriesRead = 0; entriesRead < batchSize; ++entriesRead) { line = reader.read(); if (line == null) { break; } entries.add(new DeserializedParameterEntry(line)); } if (entriesRead < batchSize) { hasMore = false; } } catch (IOException exception) { throw new ParamBatchLoadingException("deserialization error", exception); } return entries; } CsvParameterEntryBatchLoader(CsvListReader reader); @Override boolean hasMore(); @Override Collection<ParameterEntry> nextBatch(int batchSize); @Override void close(); }
CsvParameterEntryBatchLoader implements ParameterEntryBatchLoader { @Override public Collection<ParameterEntry> nextBatch(int batchSize) { List<ParameterEntry> entries = new ArrayList<ParameterEntry>(batchSize); try { List<String> line; int entriesRead; for (entriesRead = 0; entriesRead < batchSize; ++entriesRead) { line = reader.read(); if (line == null) { break; } entries.add(new DeserializedParameterEntry(line)); } if (entriesRead < batchSize) { hasMore = false; } } catch (IOException exception) { throw new ParamBatchLoadingException("deserialization error", exception); } return entries; } CsvParameterEntryBatchLoader(CsvListReader reader); @Override boolean hasMore(); @Override Collection<ParameterEntry> nextBatch(int batchSize); @Override void close();  }