0 Replies - 265 Views - Last Post: 05 June 2019 - 09:48 AM Rate Topic: -----

#1 overwhelmed_student   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 10-May 18

forkjoin

Posted 05 June 2019 - 09:48 AM

Hey guys,
I am trying to understand the whole fork-join process but when I try to implement it in streams I get an error that I don't know how to fix.
Here is my code:
    public FilterT(List<T> list, Predicate<T> predicate) {
        this.list = list;
        this.predicate = predicate;
    }

    @Override
    protected List<T> compute() {
        if (list.size() > 50) {
            List<FilterT<T>> filterT = splitProblem();
            filterT.forEach(FilterT::fork);
            return (List<T>) filterT.stream().map(FilterT::join).filter(predicate);
        } else {
            return (List<T>) list.stream().filter(predicate);

        }
    }


And this is my table:
    public Table<T> filter(Predicate<T> predicate) {
        return new Table<>(
                new ForkJoinPool().invoke(new FilterT<>(this.list, predicate))
        );
    }


splitProblem() simply divides the list in two equal parts. I get an error in
            return (List<T>) filterT.stream().map(FilterT::join).filter(predicate);


It says Predicate<? super jave.util.List<T>> in Stream cannot be applied to Predicate<T>. Why not? I specifically implemented the method filter(Predicate<T>). It should work so I guess I missed s step to get to Table. Can anyone help?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1