SplitIn
Closed this issue · 7 comments
Only a small method and things to split, maybe you should do it as an object.
private List<List> splitIn(List list, int size) {
if (size > list.size()) {
return null;
}
int ad = Math.round(list.size() / size);
List<List<String>> r = new ArrayList<>();
int j = 0;
List<String> g = new ArrayList<>();
for (String text : list) {
g.add(text);
j++;
if (j == ad || j > ad) {
r.add(g);
g = new ArrayList<>();
j = 0;
}
}
if (!r.get(r.size() - 2).equals(g)) {
r.add(g);
}
return r;
}
Hello InProgressingNet,
thanks for you suggestions, but I have a question.
As I can see the method splits a List into smaller Lists, but what is the use case for this method. So can you describe where this would be useful?
That would be very useful for threads. So that you can split a large list of objects into several lists that the threads can then process.
Oh you mean like simultaneously thread handling of huge Lists. Sounds useful. The only downside I would see is the fact that the task should be able to be parallelized. And if you want to save some return value again you need to check for CoModificationException. Wouldn't that be inconvenient?
There are certain ways in Java to work around this exception. You as a good dev know there is a good solution.
I know that I just wanted to point it out to you.
I think there is neat solution in the YAPI now.
Just look in yapi.manager.worker.TaskParalyse.java
. It should have everything you need for Task Paralysation.
The path will change to yapi.manager.worker.TaskParallelization.java