Skip to content

Commit

Permalink
1.5.8
Browse files Browse the repository at this point in the history
 
Close Streams when IllegalArgumentException happens.

Add Stream.window/Fn.window.

Add Stream.asyncRun/asyncCall

Move N.rollup/powerSet/permutations/orderedPermutations/cartesianProduct/parse to Iterables.

Move Optional/OptionalInt/.../Nullable/Holder/... to u.Optional/OptionalInt/.../Nullable/Holder/... avoid to the potential conflict with java Optional/OptionalInt.... To Migrate to this new version by searching and replacing abacus.util.Optional/Nullable/... with abacus.util.u.Optional/Nullable...

Improvements and bug fix.
  • Loading branch information
landawn committed Mar 23, 2019
1 parent 493ac67 commit f321362
Show file tree
Hide file tree
Showing 64 changed files with 995 additions and 1,929 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* Move `Optional/OptionalInt/.../Nullable/Holder/...` to `u.Optional/OptionalInt/.../Nullable/Holder/...` avoid to the potential conflict with java `Optional/OptionalInt...`. To Migrate to this new version by searching and replacing `abacus.util.Optional/Nullable/...` with `abacus.util.u.Optional/Nullable...`.

* Move `StringUtil.repeatQM` to `SQLBuilder.repeatQM`.

* Improvements and bug fix.

Expand Down
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,32 +183,32 @@ 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.5.7/com/landawn/abacus/util/Charsets.html),
[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Ascii.html),
[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/CalendarUnit.html),
[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/NamingPolicy.html),
[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Properties.html),
[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/PropertiesUtil.html),
[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Wrapper.html),
[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ArrayHashSet.html),
[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ArrayHashMap.html),
[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/ClassUtil.html),
[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/EscapeUtil.html),
[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/RegExUtil.html),
[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/FilenameUtil.html),
[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/AWSJSONUtil.html),
[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/AddrUtil.html),
[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/WSSecurityUtil.html),
[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/EmailUtil.html),
[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/IEEE754rUtil.html),
[Index](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Index.html),
[Median](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Median.html),
[f](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/f.html),
[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Matth.html),
[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/SafeInitializer.html),
[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Stopwatch.html),
[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/RateLimiter.html),
[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.5.7/com/landawn/abacus/util/Traverser.html)(from Apache commons, Google Guava...) ...
[Charsets](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Charsets.html),
[Ascii](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Ascii.html),
[CalendarUnit](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/CalendarUnit.html),
[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/NamingPolicy.html),
[Properties](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Properties.html),
[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/PropertiesUtil.html),
[Wrapper](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Wrapper.html),
[ArrayHashSet](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/ArrayHashSet.html),
[ArrayHashMap](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/ArrayHashMap.html),
[ClassUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/ClassUtil.html),
[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/EscapeUtil.html),
[RegExUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/RegExUtil.html),
[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/FilenameUtil.html),
[AWSJSONUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/AWSJSONUtil.html),
[AddrUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/AddrUtil.html),
[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/WSSecurityUtil.html),
[EmailUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/EmailUtil.html),
[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/IEEE754rUtil.html),
[Index](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Index.html),
[Median](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Median.html),
[f](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/f.html),
[Matth](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Matth.html),
[SafeInitializer](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/SafeInitializer.html),
[Stopwatch](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/Stopwatch.html),
[RateLimiter](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/com/landawn/abacus/util/RateLimiter.html),
[Traverser](https://static.javadoc.io/com.landawn/abacus-util/1.5.8/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 @@ -218,22 +218,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.5.7'
compile 'com.landawn:abacus-util:1.5.8'
// JDK 1.7:
compile 'com.landawn:abacus-util-jdk7:1.5.7'
compile 'com.landawn:abacus-util-jdk7:1.5.8'
// Android (Java 1.7):
compile 'abacus-android-jdk7:1.5.7'
compile 'abacus-android-jdk7:1.5.8'
// Android-SE (Java 1.7) - small edition without Stream/Matrix/Sheet/...:
compile 'abacus-android-se-jdk7:1.5.7'
compile 'abacus-android-se-jdk7:1.5.8'
// Android (Java 1.8 or above):
compile 'com.landawn:abacus-android:1.5.7'
compile 'com.landawn:abacus-android:1.5.8'
// Android-SE (Java 1.8 or above) - small edition without Stream/Matrix/Sheet/...:
compile 'com.landawn:abacus-android-se:1.5.7'
compile 'com.landawn:abacus-android-se:1.5.8'
```
### 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/StringUtil.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.8.jar
Binary file not shown.
Binary file modified lib/abacus-util-jdk7-1.5.8.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions src/com/landawn/abacus/util/CQLBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ static Map<String, Expression> named(final Collection<String> propNames) {
return m;
}

public static String repeatQM(int n) {
return SQLBuilder.repeatQM(n);
}

public CQLBuilder into(final String tableName) {
if (op != OperationType.ADD) {
throw new AbacusException("Invalid operation: " + op);
Expand Down
109 changes: 94 additions & 15 deletions src/com/landawn/abacus/util/ExceptionalStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.Executor;

import com.landawn.abacus.exception.DuplicatedResultException;
import com.landawn.abacus.exception.UncheckedSQLException;
Expand Down Expand Up @@ -62,19 +63,6 @@
* @author Haiyang Li
*/
public class ExceptionalStream<T, E extends Exception> implements AutoCloseable {
@SuppressWarnings("rawtypes")
private static final ExceptionalStream EMPTY = new ExceptionalStream(new ExceptionalIterator() {
@Override
public boolean hasNext() throws Exception {
return false;
}

@Override
public Object next() throws Exception {
throw new NoSuchElementException();
}
}, null);

private final ExceptionalIterator<T, E> elements;
private final boolean sorted;
private final Comparator<? super T> comparator;
Expand All @@ -94,7 +82,7 @@ public Object next() throws Exception {
}

public static <T, E extends Exception> ExceptionalStream<T, E> empty() {
return EMPTY;
return new ExceptionalStream<>(ExceptionalIterator.EMPTY, null);
}

public static <T, E extends Exception> ExceptionalStream<T, E> just(final T e) {
Expand Down Expand Up @@ -2848,6 +2836,74 @@ public <R> R __(Try.Function<? super ExceptionalStream<T, E>, R, ? extends E> tr
return transfer.apply(this);
}

/**
*
* @param action a terminal operation should be called.
* @return
*/
public ContinuableFuture<Void> asyncRun(final Try.Consumer<? super ExceptionalStream<T, E>, E> action) {
checkArgNotNull(action, "action");

return ContinuableFuture.run(new Try.Runnable<E>() {
@Override
public void run() throws E {
action.accept(ExceptionalStream.this);
}
});
}

/**
*
* @param action a terminal operation should be called.
* @param executor
* @return
*/
public ContinuableFuture<Void> asyncRun(final Try.Consumer<? super ExceptionalStream<T, E>, E> action, final Executor executor) {
checkArgNotNull(action, "action");
checkArgNotNull(executor, "executor");

return ContinuableFuture.run(new Try.Runnable<E>() {
@Override
public void run() throws E {
action.accept(ExceptionalStream.this);
}
}, executor);
}

/**
*
* @param action a terminal operation should be called.
* @return
*/
public <R> ContinuableFuture<R> asyncCall(final Try.Function<? super ExceptionalStream<T, E>, R, E> action) {
checkArgNotNull(action, "action");

return ContinuableFuture.call(new Try.Callable<R, E>() {
@Override
public R call() throws E {
return action.apply(ExceptionalStream.this);
}
});
}

/**
*
* @param action a terminal operation should be called.
* @param executor
* @return
*/
public <R> ContinuableFuture<R> asyncCall(final Try.Function<? super ExceptionalStream<T, E>, R, E> action, final Executor executor) {
checkArgNotNull(action, "action");
checkArgNotNull(executor, "executor");

return ContinuableFuture.call(new Try.Callable<R, E>() {
@Override
public R call() throws E {
return action.apply(ExceptionalStream.this);
}
}, executor);
}

public ExceptionalStream<T, E> onClose(final Try.Runnable<? extends E> closeHandler) {
checkArgNotNull(closeHandler, "closeHandler");

Expand Down Expand Up @@ -2876,10 +2932,20 @@ public void run() throws E {

@Override
public synchronized void close() throws E {
if (isClosed || N.isNullOrEmpty(closeHandlers)) {
if (isClosed) {
return;
}

if (N.isNullOrEmpty(closeHandlers)) {
isClosed = true;
return;
}

// // Only mark the stream closed if closeHandlers are not empty.
// if (isClosed || N.isNullOrEmpty(closeHandlers)) {
// return;
// }

isClosed = true;

Throwable ex = null;
Expand Down Expand Up @@ -3008,6 +3074,19 @@ public static final class StreamE<T, E extends Exception> extends ExceptionalStr

static abstract class ExceptionalIterator<T, E extends Exception> {

@SuppressWarnings("rawtypes")
private static final ExceptionalIterator EMPTY = new ExceptionalIterator() {
@Override
public boolean hasNext() throws Exception {
return false;
}

@Override
public Object next() throws Exception {
throw new NoSuchElementException();
}
};

/**
* Lazy evaluation.
*
Expand Down
34 changes: 34 additions & 0 deletions src/com/landawn/abacus/util/SQLBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,40 @@ static Map<String, Expression> named(final Collection<String> propNames) {
return m;
}

private static final Map<Integer, String> QM_CACHE = new HashMap<>();

static {
for (int i = 0; i <= 30; i++) {
QM_CACHE.put(i, StringUtil.repeat("?", i, ", "));
}

QM_CACHE.put(100, StringUtil.repeat("?", 100, ", "));
QM_CACHE.put(200, StringUtil.repeat("?", 200, ", "));
QM_CACHE.put(300, StringUtil.repeat("?", 300, ", "));
QM_CACHE.put(500, StringUtil.repeat("?", 500, ", "));
QM_CACHE.put(1000, StringUtil.repeat("?", 1000, ", "));
}

/**
* Repeat question mark({@code ?}) {@code n} times with delimiter {@code ", "}.
* <br />
* It's designed for batch SQL builder.
*
* @param n
* @return
*/
public static String repeatQM(int n) {
N.checkArgNotNegative(n, "count");

String result = QM_CACHE.get(n);

if (result == null) {
result = StringUtil.repeat("?", n, ", ");
}

return result;
}

public SQLBuilder into(final String tableName) {
if (op != OperationType.ADD) {
throw new AbacusException("Invalid operation: " + op);
Expand Down
35 changes: 0 additions & 35 deletions src/com/landawn/abacus/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -93,20 +92,6 @@ public abstract class StringUtil {
sharedStringConstructor = tmpConstructor;
}

private static final Map<Integer, String> QM_CACHE = new HashMap<>();

static {
for (int i = 0; i <= 30; i++) {
QM_CACHE.put(i, StringUtil.repeat("?", i, ", "));
}

QM_CACHE.put(100, StringUtil.repeat("?", 100, ", "));
QM_CACHE.put(200, StringUtil.repeat("?", 200, ", "));
QM_CACHE.put(300, StringUtil.repeat("?", 300, ", "));
QM_CACHE.put(500, StringUtil.repeat("?", 500, ", "));
QM_CACHE.put(1000, StringUtil.repeat("?", 1000, ", "));
}

private StringUtil() {
// Singleton. Utility class.
}
Expand Down Expand Up @@ -445,26 +430,6 @@ public static String repeat(String str, final int n, String delimiter) {
return newString(cbuf, true);
}

/**
* Repeat question mark({@code ?}) {@code n} times with delimiter {@code ", "}.
* <br />
* It's designed for SQL builder.
*
* @param n
* @return
*/
public static String repeatQM(int n) {
N.checkArgNotNegative(n, "count");

String result = QM_CACHE.get(n);

if (result == null) {
result = StringUtil.repeat("?", n, ", ");
}

return result;
}

public static char toLowerCase(final char ch) {
return Character.toLowerCase(ch);
}
Expand Down
Loading

0 comments on commit f321362

Please sign in to comment.