com.github.paganini2008.devtools.beans.streaming.Select Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devtools-beans-streaming Show documentation
Show all versions of devtools-beans-streaming Show documentation
a useful java tools based on java collection stream framework
package com.github.paganini2008.devtools.beans.streaming;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.github.paganini2008.devtools.collection.ListUtils;
import com.github.paganini2008.devtools.jdbc.ResultSetSlice;
/**
*
* Select
*
* @author Fred Feng
* @version 1.0
*/
public class Select implements Selectable {
private List content;
Select(List content) {
this.content = content;
}
public static Select from(Collection content) {
return new Select(content instanceof List ? (List) content : new ArrayList(content));
}
public Selectable filter(Predicate predicate) {
content = content.stream().filter(predicate).collect(Collectors.toList());
return this;
}
public Selectable distinct() {
content = content.stream().distinct().collect(Collectors.toList());
return this;
}
public Selectable orderBy(Sort sort) {
content.sort(sort);
return this;
}
public Groupable groupBy(Function function, String attributeName) {
return new Groups(content).groupBy(function, attributeName);
}
public List list(int maxResults, int firstResult) {
return ListUtils.slice(content, maxResults, firstResult);
}
public int totalCount() {
return content.size();
}
public ResultSetSlice setTransformer(Transformer transformer) {
return new MemoryResultSetSlice(content, transformer);
}
}