eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Create primitiveStream methods for IntSet, LongSet and DoubleSet

Open donraab opened this issue 2 years ago • 4 comments

Since 10.0, we have had primitiveStream on IntList, LongList and DoubleList. This makes the following possible:

List<String> list = IntLists.immutable.of(1, 2, 3)
        .primitiveStream()
        .mapToObj(Integer::toString)
        .toList();

Assertions.assertEquals(List.of("1", "2", "3"), list);

There is no equivalent for IntSet, LongSet, and DoubleSet today. This will additionally require creating spliterator() for each of these.

donraab avatar Apr 16 '23 23:04 donraab

Hi @donraab I am happy to take a look at this !

Novmbrain avatar Apr 21 '23 13:04 Novmbrain

Thanks for volunteering @Novmbrain ! I have assigned the issue to you.

donraab avatar Apr 21 '23 15:04 donraab

Hi @donraab , I am working on this issue. So far, I forked the repository, build the project locally and try to understand the mission.

Referring to the way how primitiveStream was implemented on IntList, LongList and DoubleList , I declared an abstract method in primitiveSet.stg and two default methods.

    /**
     * @since 12.0
     */
    Spliterator.Of<name> spliterator();

    /**
     * @since 12.0
     */
    default <name>Stream primitiveStream()
    {
        return StreamSupport.<type>Stream(this.spliterator(), false);
    }

    /**
     * @since 12.0
     */
    default <name>Stream primitiveParallelStream()
    {
        return StreamSupport.<type>Stream(this.spliterator(), true);
   

Afterwards, I implemented the abstract method spliterator() in

  • eclipse-collections-code-generator/src/main/resources/impl/set/immutable/immutablePrimitiveEmptySet.stg
  • eclipse-collections-code-generator/src/main/resources/impl/set/immutable/immutablePrimitiveSingletonSet.stg
  • eclipse-collections-code-generator/src/main/resources/impl/set/mutable/primitiveHashSet.stg
  • eclipse-collections-code-generator/src/main/resources/impl/set/mutable/synchronizedPrimitiveSet.stg
  • eclipse-collections-code-generator/src/main/resources/impl/set/mutable/unmodifiablePrimitiveSet.stg

I guess I still need to update the files under packageeclipse-collections-code-generator/src/main/resources/impl/map,

  • eclipse-collections-code-generator/src/main/resources/impl/map/abstractMutablePrimitiveKeySet.stg
  • eclipse-collections-code-generator/src/main/resources/impl/map/mutable/immutablePrimitiveMapKeySet.stg

Do I misunderstand or miss something?

Thanks and looking forward to your reply :)

Novmbrain avatar May 02 '23 19:05 Novmbrain

Hi @Novmbrain I am happy to work on this can you please give me a clue or something about the package or class I completed the setup of this project in my Local IDE

BrijeshPatra avatar Aug 28 '23 03:08 BrijeshPatra