You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/05/05 07:10:23 UTC
[isis] 01/03: ISIS-2340: enhanced streaming
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit b55cae22745713b27e26e3066e0c68e4ab485a4f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue May 5 06:57:46 2020 +0200
ISIS-2340: enhanced streaming
---
.../isis/core/commons/internal/base/_NullSafe.java | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_NullSafe.java b/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_NullSafe.java
index 11f05ef..34819a4 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_NullSafe.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/internal/base/_NullSafe.java
@@ -18,6 +18,7 @@
*/
package org.apache.isis.core.commons.internal.base;
+import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;
@@ -159,6 +160,36 @@ public final class _NullSafe {
};
}
+ public static Stream<?> streamAutodetect(@Nullable Object pojo) {
+ if(pojo==null) {
+ return Stream.empty();
+ }
+ if(pojo instanceof Collection) {
+ return ((Collection<?>)pojo).stream();
+ }
+ if(pojo instanceof Can) {
+ return ((Can<?>)pojo).stream();
+ }
+ if(pojo.getClass().isArray()) {
+ if(Array.getLength(pojo)==0) return Stream.empty();
+ if(pojo instanceof Object[]) return Stream.of((Object[]) pojo);
+ if(pojo instanceof boolean[]) return Stream.of((boolean[]) pojo);
+ if(pojo instanceof byte[]) return Stream.of((byte[]) pojo);
+ if(pojo instanceof char[]) return Stream.of((char[]) pojo);
+ if(pojo instanceof double[]) return Stream.of((double[]) pojo);
+ if(pojo instanceof float[]) return Stream.of((float[]) pojo);
+ if(pojo instanceof int[]) return Stream.of((int[]) pojo);
+ if(pojo instanceof long[]) return Stream.of((long[]) pojo);
+ if(pojo instanceof short[]) return Stream.of((short[]) pojo);
+ }
+ if(pojo instanceof Iterable) {
+ return stream((Iterable<?>)pojo);
+ }
+ if(pojo instanceof Enumeration) {
+ return stream((Enumeration<?>)pojo);
+ }
+ return Stream.of(pojo);
+ }
// -- ABSENCE/PRESENCE PREDICATES