Skip to content

Commit

Permalink
1.5 - Refactoring Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Feb 17, 2019
1 parent cafe912 commit fe7a835
Show file tree
Hide file tree
Showing 39 changed files with 227 additions and 272 deletions.
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
### 1.5

* Change the stream implementation: close it after execution(any terminal method is executed).
* Change the stream implementation: Streams will be automatically closed after execution(any terminal method is executed).

* Remove `Stream.head/tail/headAndTail`.
* Remove `Stream.try` because Streams will be automatically closed after execution.

* Remove `Stream.try` because the all streams will be automatically closed after execution.
* Remove `Stream.head/tail/headAndTail/cached`.

* Rename `Stream.of(File/Path...)` to `Stream.lines(File/Path...)`.

Expand Down
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,33 +180,33 @@ A general programming library in Java/Android. It's easy to learn and simple to
[RemoteExecutor](https://cdn.rawgit.com/landawn/AbacusUtil/master/docs/RemoteExecutor_view.html).

* More:
[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Charsets.html),
[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Ascii.html),
[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/CalendarUnit.html),
[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/NamingPolicy.html),
[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Properties.html),
[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/PropertiesUtil.html),
[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Wrapper.html),
[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/ArrayHashSet.html),
[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/ArrayHashMap.html),
[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/ClassUtil.html),
[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/EscapeUtil.html),
[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/RegExUtil.html),
[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/FilenameUtil.html),
[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/AWSJSONUtil.html),
[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/AddrUtil.html),
[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/WSSecurityUtil.html),
[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/EmailUtil.html),
[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/IEEE754rUtil.html),
[Index](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Index.html),
[Median](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Median.html),
[f](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/f.html),
[Iterables](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Iterables.html),
[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Matth.html),
[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/SafeInitializer.html),
[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Stopwatch.html),
[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/RateLimiter.html),
[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.3.33/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ...
[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Charsets.html),
[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Ascii.html),
[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/CalendarUnit.html),
[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/NamingPolicy.html),
[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Properties.html),
[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/PropertiesUtil.html),
[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Wrapper.html),
[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/ArrayHashSet.html),
[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/ArrayHashMap.html),
[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/ClassUtil.html),
[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/EscapeUtil.html),
[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/RegExUtil.html),
[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/FilenameUtil.html),
[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/AWSJSONUtil.html),
[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/AddrUtil.html),
[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/WSSecurityUtil.html),
[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/EmailUtil.html),
[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/IEEE754rUtil.html),
[Index](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Index.html),
[Median](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Median.html),
[f](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/f.html),
[Iterables](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Iterables.html),
[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Matth.html),
[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/SafeInitializer.html),
[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Stopwatch.html),
[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/RateLimiter.html),
[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.5/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ...


## Download/Installation & [Changes](https://github.com/landawn/AbacusUtil/blob/master/CHANGES.md):
Expand All @@ -216,22 +216,22 @@ A general programming library in Java/Android. It's easy to learn and simple to
* Gradle:
```gradle
// JDK 1.8 or above:
compile 'com.landawn:abacus-util:1.3.33'
compile 'com.landawn:abacus-util:1.5'
// JDK 1.7:
compile 'com.landawn:abacus-util-jdk7:1.3.33'
compile 'com.landawn:abacus-util-jdk7:1.5'
// Android (Java 1.7):
compile 'abacus-android-jdk7:1.3.33'
compile 'abacus-android-jdk7:1.5'
// Android-SE (Java 1.7) - small edition without Stream/Matrix/Sheet/...:
compile 'abacus-android-se-jdk7:1.3.33'
compile 'abacus-android-se-jdk7:1.5'
// Android (Java 1.8 or above):
compile 'com.landawn:abacus-android:1.3.33'
compile 'com.landawn:abacus-android:1.5'
// Android-SE (Java 1.8 or above) - small edition without Stream/Matrix/Sheet/...:
compile 'com.landawn:abacus-android-se:1.3.33'
compile 'com.landawn:abacus-android-se:1.5'
```
### Functional Programming:
(It's very important to learn Lambdas and Stream APIs in Java 8 to get the best user experiences with the APIs provided in AbacusUtil)
Expand Down
Binary file modified docs/BaseStream.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ExceptionalStream.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Stream.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified lib/abacus-util-1.5.jar
Binary file not shown.
Binary file modified lib/abacus-util-jdk7-1.5.jar
Binary file not shown.
32 changes: 16 additions & 16 deletions src/com/landawn/abacus/core/RowDataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3625,7 +3625,7 @@ public <T, E extends Exception> DataSet groupBy(final String columnName, String
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3638,7 +3638,7 @@ public <E extends Exception> DataSet groupBy(final String columnName, String agg
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand All @@ -3651,7 +3651,7 @@ public <K, T, E extends Exception, E2 extends Exception> DataSet groupBy(final S
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3664,7 +3664,7 @@ public <K, E extends Exception, E2 extends Exception> DataSet groupBy(final Stri
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand Down Expand Up @@ -3864,7 +3864,7 @@ public <T, E extends Exception> DataSet groupBy(final String columnName, int fro
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3878,7 +3878,7 @@ public <E extends Exception> DataSet groupBy(final String columnName, int fromRo
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand All @@ -3893,7 +3893,7 @@ public <K, T, E extends Exception, E2 extends Exception> DataSet groupBy(final S
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3908,7 +3908,7 @@ public <K, E extends Exception, E2 extends Exception> DataSet groupBy(final Stri
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand Down Expand Up @@ -3955,7 +3955,7 @@ public <T, E extends Exception> DataSet groupBy(Collection<String> columnNames,
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3968,7 +3968,7 @@ public <E extends Exception> DataSet groupBy(Collection<String> columnNames, Str
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand All @@ -3981,7 +3981,7 @@ public <T, E extends Exception, E2 extends Exception> DataSet groupBy(Collection
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -3994,7 +3994,7 @@ public <E extends Exception, E2 extends Exception> DataSet groupBy(Collection<St
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand Down Expand Up @@ -4309,7 +4309,7 @@ public <T, E extends Exception> DataSet groupBy(Collection<String> columnNames,
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -4323,7 +4323,7 @@ public <E extends Exception> DataSet groupBy(Collection<String> columnNames, int
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand All @@ -4338,7 +4338,7 @@ public <T, E extends Exception, E2 extends Exception> DataSet groupBy(Collection
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<T>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<T>) column.get(i))));
}

return result;
Expand All @@ -4353,7 +4353,7 @@ public <E extends Exception, E2 extends Exception> DataSet groupBy(Collection<St
final List<Object> column = result._columnList.get(result.getColumnIndex(aggregateResultColumnName));

for (int i = 0, len = column.size(); i < len; i++) {
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i)).cached()));
column.set(i, func.apply(Stream.of((List<Object[]>) column.get(i))));
}

return result;
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/ExceptionalStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ public ExceptionalStream<T, E> dropWhile(final Try.Predicate<? super T, ? extend
public boolean hasNext() throws E {
if (hasNext == false) {
if (dropped == false) {
dropped = true;

while (elements.hasNext()) {
next = elements.next();

Expand All @@ -880,8 +882,6 @@ public boolean hasNext() throws E {
break;
}
}

dropped = true;
} else if (elements.hasNext()) {
next = elements.next();
hasNext = true;
Expand Down Expand Up @@ -1422,8 +1422,8 @@ public ExceptionalStream<T, E> skip(final long n) {
@Override
public boolean hasNext() throws E {
if (skipped == false) {
skip(n);
skipped = true;
skip(n);
}

return elements.hasNext();
Expand All @@ -1432,8 +1432,8 @@ public boolean hasNext() throws E {
@Override
public T next() throws E {
if (skipped == false) {
skip(n);
skipped = true;
skip(n);
}

return elements.next();
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/stream/AbstractByteStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,10 @@ public ByteStream zipWith(ByteStream b, ByteStream c, byte valueForNoneA, byte v
// return Pair.of(headd(), taill());
// }

@Override
public ByteStream cached() {
return newStream(toArray(), sorted);
}
// @Override
// public ByteStream cached() {
// return newStream(toArray(), sorted);
// }

@Override
public <K, V> Map<K, V> toMap(ByteFunction<? extends K> keyExtractor, ByteFunction<? extends V> valueMapper) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/stream/AbstractCharStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,10 @@ public CharStream zipWith(CharStream b, CharStream c, char valueForNoneA, char v
return CharStream.zip(this, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}

@Override
public CharStream cached() {
return newStream(toArray(), sorted);
}
// @Override
// public CharStream cached() {
// return newStream(toArray(), sorted);
// }

@Override
public <K, V> Map<K, V> toMap(CharFunction<? extends K> keyExtractor, CharFunction<? extends V> valueMapper) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/stream/AbstractDoubleStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,10 @@ public DoubleStream top(int n) {
return top(n, DOUBLE_COMPARATOR);
}

@Override
public DoubleStream cached() {
return newStream(toArray(), sorted);
}
// @Override
// public DoubleStream cached() {
// return newStream(toArray(), sorted);
// }

@Override
public <K, V> Map<K, V> toMap(DoubleFunction<? extends K> keyExtractor, DoubleFunction<? extends V> valueMapper) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/stream/AbstractFloatStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,10 @@ public FloatStream zipWith(FloatStream b, FloatStream c, float valueForNoneA, fl
return FloatStream.zip(this, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}

@Override
public FloatStream cached() {
return newStream(toArray(), sorted);
}
// @Override
// public FloatStream cached() {
// return newStream(toArray(), sorted);
// }

@Override
public <K, V> Map<K, V> toMap(FloatFunction<? extends K> keyExtractor, FloatFunction<? extends V> valueMapper) {
Expand Down
8 changes: 4 additions & 4 deletions src/com/landawn/abacus/util/stream/AbstractIntStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,10 @@ public IntStream zipWith(IntStream b, IntStream c, int valueForNoneA, int valueF
return IntStream.zip(this, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}

@Override
public IntStream cached() {
return newStream(toArray(), sorted);
}
// @Override
// public IntStream cached() {
// return newStream(toArray(), sorted);
// }

@Override
public <K, V> Map<K, V> toMap(IntFunction<? extends K> keyExtractor, IntFunction<? extends V> valueMapper) {
Expand Down
Loading

0 comments on commit fe7a835

Please sign in to comment.