Skip to content

Conversation

@cesarcoatl
Copy link
Member

@cesarcoatl cesarcoatl commented Jan 20, 2026

cannot remember how this got here

Summary by Sourcery

Introduce IntStream and functional int types while moving Stream from java.util to java.util.stream.

New Features:

  • Add IntStream class and nested builder and mapping consumer types in java.util.stream with corresponding type stubs.
  • Add IntConsumer and IntPredicate functional interfaces with runtime implementations and stubs.
  • Add Arrays.toString utility for list-to-string conversion with stubs, and wire Java lang String/CharSequence chars, codePoints, and lines to stream types.

Enhancements:

  • Relocate the Stream definition from java.util to java.util.stream and update imports/exports to reference the new location.
  • Align signatures and exports across runtime and stub modules to reflect new stream and functional interface types.

cannot remember how this got here
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 20, 2026

Reviewer's Guide

Refactors stream-related APIs to live under java.util.stream, introduces IntStream and related functional interfaces, wires String/CharSequence methods to these stream types, and adjusts Arrays utilities and stubs to match the Java standard library surface more closely.

Updated class diagram for java.util.stream and int functional types

classDiagram
    class AutoCloseable {
        <<interface>>
        +close() None
    }

    class BaseStream {
        +close() None
        +isParallel() bool
        +iterator() Iterator
        +onClose(closeHandler Runnable) Any
        +parallel() Any
        +sequential() Any
        +spliterator() Spliterator
        +unordered() Any
    }

    class Stream {
    }

    class Stream_Builder {
        +accept(t Any) None
        +add(t Any) Stream_Builder
        +build() Stream
    }

    class IntStream {
        +close() None
        +isParallel() bool
        +iterator() Iterator
        +onClose(closeHandler Runnable) Any
        +parallel() Any
        +sequential() Any
        +spliterator() Spliterator
        +unordered() Any
    }

    class IntStream_Builder {
        +accept(value int) None
        +add(t int) IntStream_Builder
        +build() IntStream
    }

    class IntStream_IntMapMultiConsumer {
        +accept(value int, ic IntConsumer) None
        +add(t Any) Stream_Builder
        +build() Stream
    }

    class Consumer {
        <<interface>>
        +accept(t Any) None
    }

    class IntConsumer {
        +accept(value int) None
        +andThen(after IntConsumer) IntConsumer
    }

    class IntPredicate {
        +negate() IntPredicate
        +test(value int) bool
    }

    AutoCloseable <|-- BaseStream
    BaseStream <|-- Stream
    BaseStream <|-- IntStream

    Consumer <|-- Stream_Builder
    IntConsumer <|-- IntStream_Builder

    Stream o-- Stream_Builder
    IntStream o-- IntStream_Builder
    IntStream o-- IntStream_IntMapMultiConsumer

    IntStream_IntMapMultiConsumer ..> IntConsumer
    Stream_Builder ..> Stream
    IntStream_Builder ..> IntStream
Loading

Updated class diagram for java.lang String, CharSequence, Arrays and streams

classDiagram
    class CharSequence {
        +charAt(index int) str
        +chars() IntStream
        +codePoints() IntStream
        +length() int
    }

    class String {
        +charAt(index int) unicode
        +chars() IntStream
        +codePointAt(index int) int
        +codePointBefore(index int) int
        +codePointCount(beginIndex int, endIndex int) int
        +codePoints() IntStream
        +length() int
        +lines() Stream
    }

    class Arrays {
        +asList(a Any) List~Any~
        +stream(array Iterable~Any~, startInclusive int, endExclusive int) Stream
        +toString(a List~Any~) str
    }

    class IntStream {
    }

    class Stream {
    }

    CharSequence <|-- String

    CharSequence ..> IntStream : chars, codePoints
    String ..> IntStream : chars, codePoints
    String ..> Stream : lines

    Arrays ..> Stream : stream
    Arrays ..> Stream : stream return
Loading

File-Level Changes

Change Details Files
Introduce IntStream primitive stream type and supporting functional interfaces, and wire them through String/CharSequence APIs.
  • Add IntStream class extending BaseStream with Builder and IntMapMultiConsumer inner classes and basic stream-like methods, and export it from java.util.stream
  • Add IntConsumer and IntPredicate interfaces in java.util.function along with their stubs, and update imports to use IntConsumer in stream-related code
  • Update CharSequence and String implementations so chars() and codePoints() return IntStream and lines() returns Stream, and mirror these signatures in the type stubs
src/java/util/stream/__init__.py
stubs/stubs/java/util/stream/__init__.pyi
src/java/util/function/__init__.py
stubs/stubs/java/util/function/__init__.pyi
src/java/lang/__init__.py
stubs/stubs/java/lang/__init__.pyi
Relocate Stream definition from java.util to java.util.stream and adjust exports/imports accordingly.
  • Remove the Stream class and its static factory methods from java.util implementation and type stubs
  • Ensure java.util imports Stream from java.util.stream instead of defining or re-exporting it directly, and update all/public API to stop listing Stream there
  • Update java.util.stream exports and stubs so Stream is consistently defined and referenced from that module
src/java/util/__init__.py
stubs/stubs/java/util/__init__.pyi
src/java/util/stream/__init__.py
stubs/stubs/java/util/stream/__init__.pyi
Adjust Arrays utility class hierarchy and add a toString helper.
  • Change Arrays to inherit directly from object instead of Object in the implementation and stub to better match intended design
  • Add a static Arrays.toString(List[Any]) method in the implementation and stub with appropriate return typing
src/java/util/__init__.py
stubs/stubs/java/util/__init__.pyi

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In IntStream.isParallel you’re returning True unconditionally while the rest of the API is mostly placeholders; consider either raising NotImplementedError or matching the existing Stream behavior to avoid misleading semantics.
  • In IntStream.IntMapMultiConsumer, the add/build methods deal in Stream.Builder/Stream rather than IntStream types; double-check that this is intentional and not a copy-paste mismatch with the IntStream-focused API.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `IntStream.isParallel` you’re returning `True` unconditionally while the rest of the API is mostly placeholders; consider either raising `NotImplementedError` or matching the existing `Stream` behavior to avoid misleading semantics.
- In `IntStream.IntMapMultiConsumer`, the `add`/`build` methods deal in `Stream.Builder`/`Stream` rather than `IntStream` types; double-check that this is intentional and not a copy-paste mismatch with the `IntStream`-focused API.

## Individual Comments

### Comment 1
<location> `src/java/util/stream/__init__.py:100-96` </location>
<code_context>
+            # type: () -> IntStream
+            raise NotImplementedError
+
+    class IntMapMultiConsumer(object):
+        def accept(self, value, ic):
+            # type: (int, IntConsumer) -> None
+            raise NotImplementedError
+
+        def add(self, t):
+            # type: (Any) -> Stream.Builder
+            pass
+
+        def build(self):
+            # type: () -> Stream
+            raise NotImplementedError
</code_context>

<issue_to_address>
**question:** IntMapMultiConsumer.add returning Stream.Builder looks inconsistent with the surrounding API and its purpose.

The `add` method’s `Stream.Builder` return type doesn’t align with an `IntStream`/`IntConsumer`-oriented helper. For a `mapMulti`-style consumer, you’d normally expose an `IntConsumer`-like API, not a builder. If this is meant to be a consumer, consider dropping the `add`/`build` methods and the builder return type; if it’s meant to be a builder, the naming and `accept` signature should be adjusted, and the return type might better be `IntStream.Builder` or another more appropriate type.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cesarcoatl cesarcoatl merged commit ea4bbd6 into main Jan 20, 2026
5 checks passed
@cesarcoatl cesarcoatl deleted the fix/util/delete-Stream branch January 20, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants