在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:amaembo/streamex开源软件地址:https://github.com/amaembo/streamex开源编程语言:Java 100.0%开源软件介绍:StreamEx 0.8.1Enhancing Java Stream API. This library defines four classes: Full API documentation is available here. Take a look at the Cheatsheet for brief introduction to the StreamEx! Before updating StreamEx check the migration notes and full list of changes. StreamEx library main points are following:
ExamplesCollector shortcut methods (toList, toSet, groupingBy, joining, etc.) List<String> userNames = StreamEx.of(users).map(User::getName).toList();
Map<Role, List<User>> role2users = StreamEx.of(users).groupingBy(User::getRole);
StreamEx.of(1,2,3).joining("; "); // "1; 2; 3" Selecting stream elements of specific type public List<Element> elementsOf(NodeList nodeList) {
return IntStreamEx.range(nodeList.getLength())
.mapToObj(nodeList::item).select(Element.class).toList();
} Adding elements to stream public List<String> getDropDownOptions() {
return StreamEx.of(users).map(User::getName).prepend("(none)").toList();
}
public int[] addValue(int[] arr, int value) {
return IntStreamEx.of(arr).append(value).toArray();
} Removing unwanted elements and using the stream as Iterable: public void copyNonEmptyLines(Reader reader, Writer writer) throws IOException {
for(String line : StreamEx.ofLines(reader).remove(String::isEmpty)) {
writer.write(line);
writer.write(System.lineSeparator());
}
} Selecting map keys by value predicate: Map<String, Role> nameToRole;
public Set<String> getEnabledRoleNames() {
return StreamEx.ofKeys(nameToRole, Role::isEnabled).toSet();
} Operating on key-value pairs: public Map<String, List<String>> invert(Map<String, List<String>> map) {
return EntryStream.of(map).flatMapValues(List::stream).invert().grouping();
}
public Map<String, String> stringMap(Map<Object, Object> map) {
return EntryStream.of(map).mapKeys(String::valueOf)
.mapValues(String::valueOf).toMap();
}
Map<String, Group> nameToGroup;
public Map<String, List<User>> getGroupMembers(Collection<String> groupNames) {
return StreamEx.of(groupNames).mapToEntry(nameToGroup::get)
.nonNullValues().mapValues(Group::getMembers).toMap();
} Pairwise differences: DoubleStreamEx.of(input).pairMap((a, b) -> b-a).toArray(); Support of byte/char/short/float types: short[] multiply(short[] src, short multiplier) {
return IntStreamEx.of(src).map(x -> x*multiplier).toShortArray();
} Define custom lazy intermediate operation recursively: static <T> StreamEx<T> scanLeft(StreamEx<T> input, BinaryOperator<T> operator) {
return input.headTail((head, tail) -> scanLeft(tail.mapFirst(cur -> operator.apply(head, cur)), operator)
.prepend(head));
} And more! LicenseThis project is licensed under Apache License, version 2.0 InstallationReleases are available in Maven Central Before updating StreamEx check the migration notes and full list of changes. MavenAdd this snippet to the pom.xml <dependency>
<groupId>one.util</groupId>
<artifactId>streamex</artifactId>
<version>0.8.1</version>
</dependency> GradleAdd this snippet to the build.gradle implementation 'one.util:streamex:0.8.1' Pull requests are welcome. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论