Coder Social home page Coder Social logo

ztream's Introduction

Ztream

github star

Java Stream 增强

🍊Maven

<dependency>
    <groupId>io.github.taowater</groupId>
    <artifactId>ztream</artifactId>
    <version>LATEST</version>
</dependency>

示例

收集

// stream
List<String> userNames = Stream.of(users).map(User::getName).collect(Collectors.toList());
// ztream(java16+stream已支持)
List<String> userNames = Ztream.of(users).map(User::getName).toList();
// ztream
List<String> userNames = Ztream.of(users).collect(User::getName);
// 收集为set
Set<String> userNames = Ztream.of(users).toSet(User::getName);
// 制定收集集合类型
Set<String> userNames = Ztream.of(users).collect(User::getName, TreeSet::new);

group/toMap

// stream value或key为空会报异常
Map<String, Integer> map = Stream.of(list).collect(Collectors.toMap(Student::getName, Student::getAge));
// ztream value或key允许为空
Map<String, Integer> map = Ztream.of(list).toMap(Student::getName, Student::getAge);
// 指定map类型
Map<String, Integer> map = Ztream.of(list).toMap(Student::getName, Student::getAge, LinkedHashMap::new);
// stream
Map<String, List<Student>> group = Stream.of(list).collect(Collectors.groupingBy(Student::getName));
// ztream
Map<String, List<Student>> group = Ztream.of(list).groupBy(Student::getName);

v0.1.0 支持分组和映射的中间操作
Ztream.of(list)
.hash(Student::getName, Student::getAge)
.flip() // 对key value进行反转
.forEach((k, v) -> {
	// doSomeThing
});

带索引的遍历 forEach/peek/map

Ztream.(list).

forEach((e, i) ->{
// doSomeThing
// });

字符属性join

//stream略
// ztream 默认,分隔
String str = Ztream.of(list).join(Student::getName);
// 制定分隔符
String str = Ztream.of(list).join(Student::getName, "#");

数字属性操作

    //stream略
// ztream - 需要该属性为Number类型
Integer max = Ztream.of(list).max(Student::getAge);
Integer sum = Ztream.of(list).sum(Student::getAge);
Integer min = Ztream.of(list).min(Student::getAge);
Integer avg = Ztream.of(list).avg(Student::getAge);

过滤/排序

//stream略
// ztream - 类似mybatis-plus的操作
List<Student> list = Ztream.of(list)
        .eq(Student::getAge, "王武")
        .like(Student::getName, "朱")
        .ge(Student::getAge, 23)
        .toList();
// 按年龄升序
List<Student> list = Ztream.of(list).asc(Student::getAge).toList();
// 按年龄逆序
List<Student> list = Ztream.of(list).desc(Student::getAge).toList();

// 先按年龄降序(null排前),年龄相同按名称升序(null排后)
List<Student> list = Ztream.of(list).sort(r -> r
        .desc(Student::getAge, true)
        .asc(Student::getName, false)
).toList();

就先这么多吧累了

ztream's People

Contributors

taowater avatar

Stargazers

 avatar  avatar  avatar lcc avatar 梅奕 avatar roy avatar 李贤敏 avatar  avatar JL avatar  avatar

Watchers

 avatar

Forkers

yswtrue

ztream's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.