Skip to content

Commit ea7ff4e

Browse files
committed
lib: Add "getCount" to ProgressLogger. #TASK-6217
1 parent d1304c8 commit ea7ff4e

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎commons-lib/src/main/java/org/opencb/commons/ProgressLogger.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected synchronized void log(long count, String extraMessage, long currentTim
205205
// Remove old points that are outside the progress rate window
206206
times.removeFirst();
207207
}
208-
long totalCount = getTotalCount();
208+
long totalCount = this.totalCount;
209209

210210
StringBuilder sb = new StringBuilder(message).append(count);
211211
if (totalCount > 0) {
@@ -284,10 +284,6 @@ private void updateFutureTotalCount() {
284284
}
285285
}
286286

287-
private long getTotalCount() {
288-
return this.totalCount;
289-
}
290-
291287
private void updateBatchSize() {
292288
batchSize = Math.max((double) totalCount / numLinesLog, MIN_BATCH_SIZE);
293289
}
@@ -299,6 +295,10 @@ private static Future<Long> getFuture(Callable<Long> totalCountCallable) {
299295
return future;
300296
}
301297

298+
public long getCount() {
299+
return count.get();
300+
}
301+
302302
public <T> Task<T, T> asTask() {
303303
return asTask(null);
304304
}

‎commons-lib/src/main/java/org/opencb/commons/io/DataReader.java‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818

1919
import org.opencb.commons.run.Task;
2020

21-
import java.util.Collections;
22-
import java.util.Iterator;
23-
import java.util.List;
24-
import java.util.NoSuchElementException;
21+
import java.util.*;
22+
import java.util.function.Consumer;
2523
import java.util.stream.Stream;
2624
import java.util.stream.StreamSupport;
2725

@@ -163,4 +161,16 @@ public T next() {
163161
};
164162
}
165163

164+
@Override
165+
default void forEach(Consumer<? super T> action) {
166+
forEach(action, 1);
167+
}
168+
169+
default void forEach(Consumer<? super T> action, int batchSize) {
170+
Objects.requireNonNull(action);
171+
for (Iterator<T> iterator = this.iterator(batchSize); iterator.hasNext();) {
172+
T t = iterator.next();
173+
action.accept(t);
174+
}
175+
}
166176
}

0 commit comments

Comments
 (0)