简单调用简介
Dispatch.stream().count();
Dispatch.stream(1, 2, 3).toList().size();
Dispatch.stream(1, 2, 3).toSet().size();
Dispatch.stream(1, 2, 83).toJoin(Math::addExact);
Dispatch.stream(1, 2, 83).toJoin(Math::subtractExact);
Dispatch.stream(1, 2, 83).toJoin(Math::multiplyExact);
Dispatch.stream(1, 2, 83).toJoin(Math::floorDiv);
Dispatch.stream(1, 2, 83).toJoin(Math::min);
Dispatch.stream(1, 2, 83).toJoin(Math::max);
Dispatch.stream(Arrays.asList(1, 2, 34, 5, 6),
Arrays.asList(1, 2, 34, 5, 6),
Arrays.asList(1, 2, 34, 5, 6),
Arrays.asList(1, 2, 34, 5, 6),
Arrays.asList(1, 2, 34, 5, 6))
.findFirst()
.map(Dispatch::stream)
.get()
.toList();
Dispatch.iterate(0, n -> n + 2, 5)
.forEach(integer -> {
System.out.println("========>" + integer);
});
Dispatch.stream(new Integer[]{1, 2, 3, 4, 5}, new Integer[]{1, 2, 3, 4, 5}, new Integer[]{1, 2, 3, 4, 5})
.flatMap(Dispatch::stream)
.toMap(Integer::intValue, Integer::intValue)
.forEach((k, v) -> {
System.out.println("======>" + k + "=======>" + v);
});
具体逻辑
package com.lemon.covert;
import java.io.Serializable;
import java.util.*;
/**
* Copyright (C), 2016-2020, 阿诺德有限公司
*
* @FileName: Dispatch
* @Author: Arnold
* @Date: 2020/1/10 14:28
* @Description: ${DESCRIPTION}
* @History:
* @Version: 1.0.0
*/
public final class Dispatch<T> {
private static final Dispatch<?> EMPTY = new Dispatch<>();
private static <T> T requireNonNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
private static <T> Dispatch<T> empty() {
@SuppressWarnings("unchecked")
Dispatch<T> t = (Dispatch<T>) EMPTY;
return t;
}
public static <R> Dispatch<R> of(R value) {
return new Dispatch<R>(value);
}
public static <T> Dispatch<T> ofNullable(T value) {
return value == null ? (Dispatch<T>) empty() : of(value);
}
public static <R> DispatchImpl<R> stream(Collection<R> collection) {
return new DispatchImpl<>(new ArrayList<R>(collection));
}
public static <R> DispatchImpl<R> stream(R... values) {
List<R> list = new ArrayList<>();
for (R r : values) {
list.add(r);
}
return new DispatchImpl<>(list);
}
public static <T> DispatchImpl<T> iterate(T seed, final Function<T, T> mapper, int maxSize) {
List<T> list = new ArrayList<>();
list.add(seed);
if (maxSize - 1 > 0) {
for (int i = 0, len = maxSize - 1; i < len; i++) {
list.add(seed = mapper.apply(seed));
}
}
return new DispatchImpl<&