我只是写了一个小方法来计算手机短信的页数.我没有选择使用Math.ceil,老实说它似乎非常难看.
这是我的代码:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String message = "today we stumbled upon a huge performance leak while optimizing a raycasting algorithm. Much to our surprise, the Math.floor() method took almost half of the calculation time: 3 floor operations took the same amount of time as one trilinear interpolation. Since we could not belive that the floor-method could produce such a enourmous overhead, …Run Code Online (Sandbox Code Playgroud) 我想要一些类似于scala分组函数的东西.基本上,一次挑选2个元素并处理它们.以下是相同的参考:
Lambdas确实提供了诸如groupingBy和partitioningBy之类的东西,但它们似乎都没有像Scala中的分组函数那样做.任何指针将不胜感激.
假设我有以下存储库:
public interface UserRepository extends JpaRepository<User, Long> {
@Query("select u from User u")
Stream<User> streamAllPaged(Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)
我想进行搜索:
public Page<User> findAllUsers(Pageable page) {
Page<User> page = null;
try (Stream<User> users = userRepository.streamAllPaged(page)) {
Set<User> users = users.filter(u -> user.getName().equals("foo"))
.collect(Collectors.toSet());
//create page from set?
}
}
Run Code Online (Sandbox Code Playgroud)
显然我可以使用子列表并手动插入页面大小等但我想应该有更"标准"的方法来做到这一点?