abacus-stream-lite

Enhancing Java 8 Streams

License

License

GroupId

GroupId

com.landawn
ArtifactId

ArtifactId

abacus-stream-lite
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

abacus-stream-lite
Enhancing Java 8 Streams
Project URL

Project URL

https://github.com/landawn/Abacus-Lightweight-Stream-API
Source Code Management

Source Code Management

https://github.com/landawn/Abacus-Lightweight-Stream-API

Download abacus-stream-lite

How to add to project

<!-- https://jarcasting.com/artifacts/com.landawn/abacus-stream-lite/ -->
<dependency>
    <groupId>com.landawn</groupId>
    <artifactId>abacus-stream-lite</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.landawn/abacus-stream-lite/
implementation 'com.landawn:abacus-stream-lite:1.0.1'
// https://jarcasting.com/artifacts/com.landawn/abacus-stream-lite/
implementation ("com.landawn:abacus-stream-lite:1.0.1")
'com.landawn:abacus-stream-lite:jar:1.0.1'
<dependency org="com.landawn" name="abacus-stream-lite" rev="1.0.1">
  <artifact name="abacus-stream-lite" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.landawn', module='abacus-stream-lite', version='1.0.1')
)
libraryDependencies += "com.landawn" % "abacus-stream-lite" % "1.0.1"
[com.landawn/abacus-stream-lite "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Abacus-Lightweight-Stream-API

Maven Central Javadocs

Stream API from Java 8 rewritten on iterators for Java 7 and Android - Shared functional interfaces with Abacus-Util. Full API documentation is available here.

Includes

  • Very light and simple Stream APIs: Stream/EntryStream/IntStream/LongStream/DoubleStream (without parallel processing, but with a variety of additional methods and with custom operators);

Usage

Stream.of(/* array | list | set | map | anything based on Iterator/Iterable interface */)
    .filter(..)
    .map(..)
    ...
    .sorted()
    .forEach(..);
Stream.of(value1, value2, value3)...
IntStream.range(0, 10)...

Example project: https://github.com/aNNiMON/Android-Java-8-Stream-Example

Key features

Custom operators

Unlike Java 8 streams, Lightweight-Stream-API provides the ability to apply custom operators.

Stream.of(...)
    .chain(new Reverse<>())
    .forEach(...);

public final class Reverse<T> implements UnaryOperator<Stream<T>> {

    @Override
    public Stream<T> apply(Stream<T> stream) {
        final Iterator<? extends T> iterator = stream.getIterator();
        final ArrayDeque<T> deque = new ArrayDeque<T>();
        while (iterator.hasNext()) {
            deque.addFirst(iterator.next());
        }
        return Stream.of(deque.iterator());
    }
}

You can find more examples here.

Additional operators

In addition to backported Java 8 Stream operators, the library provides:

  • skipNull - filters only not null elements

    Stream.of("a", null, "c", "d", null)
        .skipNull() // [a, c, d]
  • sortedBy - sorts by extractor function

    // Java 8
    stream.sorted(Comparator.comparing(Person::getName))
    // LSA
    stream.sortedBy(Person::getName)
  • groupBy - groups by extractor function

    // Java 8
    stream.collect(Collectors.groupingBy(Person::getName)).entrySet().stream()
    // LSA
    stream.groupBy(Person::getName)
  • chunkBy - partitions sorted stream by classifier function

    Stream.of("a", "b", "cd", "ef", "gh", "ij", "klmnn")
        .chunkBy(String::length) // [[a, b], [cd, ef, gh, ij], [klmnn]]
  • sliding - partitions stream into fixed-sized list and sliding over the elements

    Stream.rangeClosed(0, 10)
        .sliding(4, 6) // [[0, 1, 2, 3], [6, 7, 8, 9]]
  • takeWhile / dropWhile - introduced in Java 9, limits/skips stream by predicate function

    Stream.of("a", "b", "cd", "ef", "g")
        .takeWhile(s -> s.length() == 1) // [a, b]
    Stream.of("a", "b", "cd", "ef", "g")
        .dropWhile(s -> s.length() == 1) // [cd, ef, g]
  • scan - iteratively applies accumulation function and returns Stream

    IntStream.range(1, 6)
        .scan((a, b) -> a + b) // [1, 3, 6, 10, 15]
  • indexed - adds an index to every element, result is IntPair

    Stream.of("a", "b", "c")
        .indexed() // [(0 : "a"), (1 : "b"), (2 : "c")]

Download

Releases are available in Maven Central

Maven:

<dependency>
  <groupId>com.landawn</groupId>
  <artifactId>abacus-stream-lite</artifactId>
  <version>0.8.4</version>
</dependency>

or Gradle:

dependencies {
  ...
  compile 'com.landawn:abacus-stream-lite:0.8.4'
  ...
}

Also included version for Java ME. Checkout javame branch.

For use lambda expressions in Java 7 or Android, take a look at Retrolambda repository.

Versions

Version
1.0.1
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1