org.rapidoid.fluent.Do Maven / Gradle / Ivy
The newest version!
package org.rapidoid.fluent;
import org.rapidoid.fluent.dox.*;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/*
* #%L
* rapidoid-fluent
* %%
* Copyright (C) 2014 - 2017 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* @author Nikolche Mihajlovski
* @since 5.0.0
*/
public class Do {
public static Stream stream(Iterable items) {
return items != null ? StreamSupport.stream(items.spliterator(), false) : Stream.empty();
}
public static Stream stream(Stream stream) {
return stream != null ? stream : Stream.empty();
}
@SafeVarargs
@SuppressWarnings("unchecked")
public static Stream streamOf(T... items) {
return items != null ? Stream.of(items) : Stream.empty();
}
@SafeVarargs
@SuppressWarnings("unchecked")
public static DoMap map(T... items) {
return new DoMap(streamOf(items));
}
public static DoMap map(Iterable items) {
return new DoMap(stream(items));
}
@SuppressWarnings("unchecked")
public static DoMapBi map(Map items) {
return new DoMapBi(items != null ? items : Collections.EMPTY_MAP);
}
public static DoGroup group(Iterable items) {
return new DoGroup(stream(items));
}
@SuppressWarnings("unchecked")
public static DoGroupBi group(Map items) {
return new DoGroupBi(items != null ? items : Collections.EMPTY_MAP);
}
public static DoReduce reduce(Iterable items) {
return new DoReduce(stream(items));
}
}