Я пытаюсь проверить, находится ли элемент в строке, просматривая список параллельно, разбивая его:
`открытый класс ParallelSearchComment extends RecursiveTask {
приватный статический финал long serialVersionUID = 1L;
int lo;
int hi;
String com;
String query;
int T;
ParallelSearchComment(String c, int l, int h, String q, int Treshold){
com=c;
lo=l;
hi=h;
query=q;
T=Treshold;
}
private int findMiddle(String text){ // Only split at whitespace chars (or some words would be missed)
int middle = lo + ((hi - lo)/2);
int i= middle;
for (i = middle; i != hi && com.charAt(middle) != ' ' && i-middle <= query.length()+1; i++){
}
middle = i;
return middle;
}
@Override
protected Boolean compute() {
int middle = findMiddle(com);
if (hi - lo < T || hi-middle <= query.length()) {//hi-middle <= query.length()
return com.substring(lo, hi).contains(query);
} else {
ParallelSearchComment left = new ParallelSearchComment(com, lo, middle, query, T);
ParallelSearchComment right = new ParallelSearchComment(com, middle, hi, query, T);
left.fork();
boolean resRight = right.compute();
boolean resLeft = left.join();
return resRight || resLeft;
}
}
static boolean ParallelSearchComment(String c, String query, int T,int p) {
final ForkJoinPool fjPool = new ForkJoinPool(p);
ParallelSearchComment t = new ParallelSearchComment(c, 0, c.length(), query, T);
return fjPool.invoke(t);
}
`