@@ -39,9 +39,8 @@ def _iterator(iterable):
3939 return
4040
4141 @staticmethod
42- def cloneSplit (iterable , count ):
43- it = ParallelUtils ._iterator (iterable )
44- return [it for _ in range (count )]
42+ def sameSplit (iterable , count ):
43+ return [ParallelUtils ._iterator (iterable ) for _ in range (count )]
4544
4645 @staticmethod
4746 def split (iterable , count ):
@@ -67,7 +66,7 @@ class ParallelStream(Stream):
6766 def __init__ (self , iterable ):
6867
6968 self .__streams = [StreamThread (Stream (it ))
70- for it in ParallelUtils .split (iterable , self .PROCESS )]
69+ for it in ParallelUtils .sameSplit (iterable , self .PROCESS )]
7170
7271 for _stream in self .__streams :
7372 _stream .start ()
@@ -117,6 +116,9 @@ def forEach(self, function):
117116 for _stream in self .__streams :
118117 _stream .forEach (function )
119118
119+ for _stream in self .__streams :
120+ _stream .join ()
121+
120122 return self
121123
122124 def anyMatch (self , predicate ):
@@ -127,8 +129,8 @@ def anyMatch(self, predicate):
127129 for _stream in self .__streams :
128130 _stream .join ()
129131
130- results = [_stream .getResult (). get ()
131- for _stream in self .__streams if _stream . getResult (). isPresent () ]
132+ results = [_stream .getResult ()
133+ for _stream in self .__streams ]
132134
133135 return Stream (results ).anyMatch (lambda x : x )
134136
@@ -140,8 +142,8 @@ def allMatch(self, predicate):
140142 for _stream in self .__streams :
141143 _stream .join ()
142144
143- results = [_stream .getResult (). get ()
144- for _stream in self .__streams if _stream . getResult (). isPresent () ]
145+ results = [_stream .getResult ()
146+ for _stream in self .__streams ]
145147
146148 return Stream (results ).allMatch (lambda x : x )
147149
@@ -153,10 +155,10 @@ def noneMatch(self, predicate):
153155 for _stream in self .__streams :
154156 _stream .join ()
155157
156- results = [_stream .getResult (). get ()
157- for _stream in self .__streams if _stream . getResult (). isPresent () ]
158+ results = [_stream .getResult ()
159+ for _stream in self .__streams ]
158160
159- return Stream (results ).noneMatch (lambda x : x )
161+ return Stream (results ).allMatch (lambda x : x )
160162
161163 def findAny (self ):
162164
@@ -210,18 +212,18 @@ def max(self, comparator=None):
210212
211213 return Stream (results ).max (comparator )
212214
213- def sum (self , comparator = None ):
215+ def sum (self ):
214216
215217 for _stream in self .__streams :
216- _stream .sum (comparator )
218+ _stream .sum ()
217219
218220 for _stream in self .__streams :
219221 _stream .join ()
220222
221223 results = [_stream .getResult ().get ()
222224 for _stream in self .__streams if _stream .getResult ().isPresent ()]
223225
224- return Stream (results ).sum (comparator )
226+ return Stream (results ).sum ()
225227
226228 def count (self ):
227229
@@ -277,8 +279,19 @@ def toSet(self):
277279 def get (self ):
278280 return self .__streams
279281
282+ def terminate (self ):
283+ for _stream in self .__streams :
284+ _stream .terminate ()
285+
280286 def __eq__ (self , other ):
281- return self .toSet () == other . toSet ( )
287+ return self .toSet () == set ( other )
282288
283289 def __iter__ (self ):
284- return iter (self .toList ())
290+
291+ def _iter (iters ):
292+ for it in iters :
293+ for elem in it :
294+ yield elem
295+ self .terminate ()
296+
297+ return _iter (self .__streams )
0 commit comments