Skip to content

Commit ea4bbd6

Browse files
authored
fix(util): remove Stream class (#14)
cannot remember how this got here
1 parent e8273f7 commit ea4bbd6

8 files changed

Lines changed: 146 additions & 90 deletions

File tree

src/java/lang/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from java.nio import CharBuffer
4545
from java.util import Iterator, Spliterator
4646
from java.util.function import Consumer
47+
from java.util.stream import IntStream, Stream
4748

4849

4950
class Object(object):
@@ -119,10 +120,12 @@ def charAt(self, index):
119120
# type: (int) -> str
120121
raise NotImplementedError
121122

122-
def chars(self): # type: ignore[no-untyped-def]
123+
def chars(self):
124+
# type: () -> IntStream
123125
pass
124126

125-
def codePoints(self): # type: ignore[no-untyped-def]
127+
def codePoints(self):
128+
# type: () -> IntStream
126129
pass
127130

128131
@staticmethod
@@ -291,7 +294,8 @@ def charAt(self, index):
291294
# type: (int) -> unicode
292295
pass
293296

294-
def chars(self): # type: ignore[no-untyped-def]
297+
def chars(self):
298+
# type: () -> IntStream
295299
pass
296300

297301
def codePointAt(self, index):
@@ -306,7 +310,8 @@ def codePointCount(self, beginIndex, endIndex):
306310
# type: (int, int) -> int
307311
pass
308312

309-
def codePoints(self): # type: ignore[no-untyped-def]
313+
def codePoints(self):
314+
# type: () -> IntStream
310315
pass
311316

312317
@staticmethod
@@ -392,7 +397,8 @@ def length(self):
392397
# type: () -> int
393398
return len(self)
394399

395-
def lines(self): # type: ignore[no-untyped-def]
400+
def lines(self):
401+
# type: () -> Stream
396402
pass
397403

398404
def matches(self, regex):

src/java/util/__init__.py

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"Map",
3232
"Properties",
3333
"Spliterator",
34-
"Stream",
3534
"TimeZone",
3635
"UUID",
3736
]
@@ -54,7 +53,6 @@
5453
Consumer,
5554
Function,
5655
Predicate,
57-
Supplier,
5856
ToDoubleFunction,
5957
ToIntFunction,
6058
ToLongFunction,
@@ -64,6 +62,7 @@
6462
from java.io import InputStream, OutputStream
6563
from java.nio import ByteBuffer
6664
from java.time import Instant, ZonedDateTime, ZoneId
65+
from java.util.stream import Stream
6766

6867

6968
class Collection(object):
@@ -466,58 +465,7 @@ def trySplit(self):
466465
raise NotImplementedError
467466

468467

469-
class Stream(object):
470-
471-
class Builder(Consumer):
472-
def accept(self, t):
473-
# type: (Any) -> None
474-
raise NotImplementedError
475-
476-
def add(self, t):
477-
# type: (Any) -> Stream.Builder
478-
pass
479-
480-
def build(self):
481-
# type: () -> Stream
482-
raise NotImplementedError
483-
484-
@staticmethod
485-
def builder():
486-
# type: () -> Builder
487-
pass
488-
489-
@staticmethod
490-
def concat(a, b):
491-
# type: (Stream, Stream) -> Stream
492-
pass
493-
494-
@staticmethod
495-
def empty():
496-
# type: () -> Stream
497-
pass
498-
499-
@staticmethod
500-
def generate(s):
501-
# type: (Supplier) -> Stream
502-
pass
503-
504-
@staticmethod
505-
def iterate(*args):
506-
# type: (*Any) -> Stream
507-
pass
508-
509-
@staticmethod
510-
def of(*args):
511-
# type: (*Any) -> Stream
512-
pass
513-
514-
@staticmethod
515-
def ofNullable(t):
516-
# type: (Any) -> Stream
517-
pass
518-
519-
520-
class Arrays(Object):
468+
class Arrays(object):
521469
@staticmethod
522470
def asList(a):
523471
# type: (Any) -> List[Any]
@@ -607,6 +555,11 @@ def stream(array, startInclusive=None, endExclusive=None):
607555
# type: (Iterable[Any], Optional[int], Optional[int]) -> Stream
608556
pass
609557

558+
@staticmethod
559+
def toString(a):
560+
# type: (List[Any]) -> Union[str, unicode]
561+
pass
562+
610563

611564
class AbstractCollection(Object, Collection):
612565
def add(self, e):

src/java/util/function/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"BinaryOperator",
66
"Consumer",
77
"Function",
8+
"IntConsumer",
9+
"IntPredicate",
810
"Predicate",
911
"Supplier",
1012
"ToDoubleFunction",
@@ -92,6 +94,26 @@ def identity():
9294
pass
9395

9496

97+
class IntConsumer(object):
98+
def accept(self, value):
99+
# type: (int) -> None
100+
raise NotImplementedError
101+
102+
def andThen(self, after):
103+
# type: (IntConsumer) -> IntConsumer
104+
pass
105+
106+
107+
class IntPredicate(object):
108+
def negate(self):
109+
# type: () -> IntPredicate
110+
pass
111+
112+
def test(self, value):
113+
# type: (int) -> bool
114+
raise NotImplementedError
115+
116+
95117
class Predicate(object):
96118
@staticmethod
97119
def isEqual(targetRef):

src/java/util/stream/__init__.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
__all__ = ["BaseStream", "Collector", "Stream"]
1+
__all__ = ["BaseStream", "Collector", "IntStream", "Stream"]
22

33
from typing import Any, Iterable, Set
44

55
from java.lang import AutoCloseable, Enum, Runnable
66
from java.util import Iterator, Spliterator
7-
from java.util.function import BiConsumer, BinaryOperator, Consumer, Function, Supplier
7+
from java.util.function import (
8+
BiConsumer,
9+
BinaryOperator,
10+
Consumer,
11+
Function,
12+
IntConsumer,
13+
Supplier,
14+
)
815

916

1017
class BaseStream(AutoCloseable):
@@ -75,6 +82,59 @@ def supplier(self):
7582
pass
7683

7784

85+
class IntStream(BaseStream):
86+
87+
class Builder(IntConsumer):
88+
def accept(self, value):
89+
# type: (int) -> None
90+
raise NotImplementedError
91+
92+
def add(self, t):
93+
# type: (int) -> IntStream.Builder
94+
pass
95+
96+
def build(self):
97+
# type: () -> IntStream
98+
raise NotImplementedError
99+
100+
class IntMapMultiConsumer(object):
101+
def accept(self, value, ic):
102+
# type: (int, IntConsumer) -> None
103+
raise NotImplementedError
104+
105+
def close(self):
106+
# type: () -> None
107+
pass
108+
109+
def isParallel(self):
110+
# type: () -> bool
111+
return True
112+
113+
def iterator(self):
114+
# type: () -> Iterator
115+
pass
116+
117+
def onClose(self, closeHandler):
118+
# type: (Runnable) -> Any
119+
pass
120+
121+
def parallel(self):
122+
# type: () -> Any
123+
pass
124+
125+
def sequential(self):
126+
# type: () -> Any
127+
pass
128+
129+
def spliterator(self):
130+
# type: () -> Spliterator
131+
pass
132+
133+
def unordered(self):
134+
# type: () -> Any
135+
pass
136+
137+
78138
class Stream(BaseStream):
79139

80140
class Builder(Consumer):

stubs/stubs/java/lang/__init__.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from java.lang.reflect import Type
55
from java.nio import CharBuffer
66
from java.util import Iterator, Spliterator
77
from java.util.function import Consumer
8+
from java.util.stream import IntStream, Stream
89

910
class Object:
1011
def __init__(self) -> None: ...
@@ -30,8 +31,8 @@ class AutoCloseable:
3031

3132
class CharSequence:
3233
def charAt(self, index: int) -> str: ...
33-
def chars(self) -> None: ...
34-
def codePoints(self) -> None: ...
34+
def chars(self) -> IntStream: ...
35+
def codePoints(self) -> IntStream: ...
3536
@staticmethod
3637
def compare(cs1: CharSequence, cs2: CharSequence) -> int: ...
3738
def length(self) -> int: ...
@@ -88,11 +89,11 @@ class String(unicode):
8889
def __new__(cls, *args: Any) -> Any: ...
8990
def __init__(self, *args: Any) -> None: ...
9091
def charAt(self, index: int) -> unicode: ...
91-
def chars(self) -> None: ...
92+
def chars(self) -> IntStream: ...
9293
def codePointAt(self, index: int) -> int: ...
9394
def codePointBefore(self, index: int) -> int: ...
9495
def codePointCount(self, beginIndex: int, endIndex: int) -> int: ...
95-
def codePoints(self) -> None: ...
96+
def codePoints(self) -> IntStream: ...
9697
@staticmethod
9798
def compare(cs1: CharSequence, cs2: CharSequence) -> int: ...
9899
def compareTo(self, anotherString: String) -> int: ...
@@ -121,7 +122,7 @@ class String(unicode):
121122
self, arg: Union[int, String], fromIndex: Optional[int] = ...
122123
) -> int: ...
123124
def length(self) -> int: ...
124-
def lines(self) -> None: ...
125+
def lines(self) -> Stream: ...
125126
def matches(self, regex: String) -> bool: ...
126127
def notify(self) -> None: ...
127128
def notifyAll(self) -> None: ...

stubs/stubs/java/util/__init__.pyi

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ from java.util.function import (
99
Consumer,
1010
Function,
1111
Predicate,
12-
Supplier,
1312
ToDoubleFunction,
1413
ToIntFunction,
1514
ToLongFunction,
1615
)
16+
from java.util.stream import Stream
1717

1818
class Collection:
1919
def add(self, e: Any) -> bool: ...
@@ -143,28 +143,7 @@ class Spliterator:
143143
def tryAdvance(self, action: Consumer) -> bool: ...
144144
def trySplit(self) -> Spliterator: ...
145145

146-
class Stream:
147-
class Builder(Consumer):
148-
def accept(self, t: Any) -> None: ...
149-
def add(self, t: Any) -> Stream.Builder: ...
150-
def build(self) -> Stream: ...
151-
152-
@staticmethod
153-
def builder() -> Builder: ...
154-
@staticmethod
155-
def concat(a: Stream, b: Stream) -> Stream: ...
156-
@staticmethod
157-
def empty() -> Stream: ...
158-
@staticmethod
159-
def generate(s: Supplier) -> Stream: ...
160-
@staticmethod
161-
def iterate(*args: Any) -> Stream: ...
162-
@staticmethod
163-
def of(*args: Any) -> Stream: ...
164-
@staticmethod
165-
def ofNullable(t: Any) -> Stream: ...
166-
167-
class Arrays(Object):
146+
class Arrays:
168147
@staticmethod
169148
def asList(a: Any) -> List[Any]: ...
170149
@staticmethod
@@ -211,6 +190,8 @@ class Arrays(Object):
211190
startInclusive: Optional[int] = ...,
212191
endExclusive: Optional[int] = ...,
213192
) -> Stream: ...
193+
@staticmethod
194+
def toString(a: List[Any]) -> Union[str, unicode]: ...
214195

215196
class AbstractCollection(Object, Collection):
216197
def add(self, e: Any) -> bool: ...

stubs/stubs/java/util/function/__init__.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class Function:
3232
@staticmethod
3333
def identity() -> Function: ...
3434

35+
class IntConsumer:
36+
def accept(self, value: int) -> None: ...
37+
def andThen(self, after: IntConsumer) -> IntConsumer: ...
38+
39+
class IntPredicate:
40+
def negate(self) -> IntPredicate: ...
41+
def test(self, value: int) -> bool: ...
42+
3543
class Predicate:
3644
@staticmethod
3745
def isEqual(targetRef: Object) -> Predicate: ...

0 commit comments

Comments
 (0)