Reputation: 69
I have this piece of code which was written in Scala:
pushArguments.par.foreach(
recFilesToPush => push(recFilesToPush).par.foreach {
case (subsId, pid, sid) =>
println(s"\n ----------- FINISHED PUSHING -------------- \n sid = $sid \n pid = $pid & subsid = $subsId")
where push method implemented as follow:
def push(desiredPushArguments: List[PusherParams]): ParSeq[(Int, Int, Long)] = {
desiredPushArguments.par.flatMap(
x => {
x.sessionStreamsDelayFromAuth = 0
sendSessionAndReturnDetails(x)
})
}
I have started to translate it to java doing this:
pushArguments.add(new ArrayList<PusherParams>(Arrays.asList(pp)));
pushArguments.parallelStream().forEach(argument->push(argument));
Now when I am stuck on the part where case got 3 values(subsId, pid, sid) which returning from push method which I translated to java (partial) this way:
public ParallelSequence push(List<PusherParams> desiredPusherArguments){
System.out.println("Gaga");
// System.out.println(desiredPusherArguments.parallelStream().flatMap(x -> desiredPusherArguments.stream()));
// System.out.println(desiredPusherArguments.parallelStream().flatMap(x -> {x.sessionStreamsDelayFromAuth,sendSeesionAndReturnDetails(x)} );
}
where ParallelSequence is a class which hold three member varaiables : subsId, pid, sid
but it is not working as expected.
Upvotes: 3
Views: 431
Reputation: 33437
I do not know what you are trying to do but two major problems with your java code
you write public ParallelSequence
push, this means you expected to return ParallelSqeuence
type which is not the case.
You are trying to print object, in this case you need to print each results and need to move print inside lambda expression.
So you can do following to get it run:
public void push(List<PusherParams> desiredPusherArguments){
desiredPusherArguments.parallelStream()
.flatMap(x -> desiredPusherArguments.stream())
.forEach(i -> System.out.println(i.getSomProp()));
}
getSomeProp
is just example and could be any property from your PusherParams
class
Upvotes: 3