Partition.java [src/java/lamps/utils] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lamps.utils;
import csip.Config;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author od
*/
public class Partition {
public static int getThreadCount(int size) {
if (Config.hasProperty("csip.lamps.threads")) {
return Config.getInt("csip.lamps.threads");
}
int threadnr = 1;
//if (size > 30) {
// threadnr = Runtime.getRuntime().availableProcessors() + 1;
//} else
if (size < 6) {
threadnr = 1;
} else {
threadnr = 2;
}
return threadnr;
}
public static <T> List<List<T>> chopIntoParts(final List<T> ls, final int iParts) {
final List<List<T>> lsParts = new ArrayList<>();
final int iChunkSize = ls.size() / iParts;
int iLeftOver = ls.size() % iParts;
int iTake = iChunkSize;
for (int i = 0, iT = ls.size(); i < iT; i += iTake) {
if (iLeftOver > 0) {
iLeftOver--;
iTake = iChunkSize + 1;
} else {
iTake = iChunkSize;
}
lsParts.add(new ArrayList<>(ls.subList(i, Math.min(iT, i + iTake))));
}
return lsParts;
}
}