guava && lamba

guava:

Preconditions.checkArgument(AppUtil.notNullOrDefault(departmentId), "无效的部门id: %s", departmentId);

Preconditions.checkArgument(uid != null && uid.isValid(), "无效的用户: %s", uid);

lamba:

1 Map<Long,Object>

Map<Long,Object> map = new HashMap<>();

map.stream().map(map::get).filter(Objects::nonNull).collect(Collectors.toList());

2 List->Map

Map<Long, DepartmentReferenceRelation> departmentIdToReference = departmentReferenceRelations.stream().collect(Collectors.toMap(DepartmentReferenceRelation::getDepartmentId, d -> d));

3 filter && sort 

transactions.parallelStream().filter(t -> t.getType() == Transaction.GROCERY).sorted(comparing(Transaction::getValue).reversed()).map(Transaction::getId).collect(toList());

4 string -> List<String> -> List<Integer>

List<String> strList = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(str);

strList.stream().map(strItem -> Integer.parseInt(strItem)).collect(Collectors.toList());

5 List<T>->Set<Integer>

 Set<Integer> userAclIdSet = userAclList.stream().map(sysAcl -> sysAcl.getId()).collect(Collectors.toSet());

6 stream of

String categories=Stream.of(productRankDTO.getCategoryPath().split("&gt;")).collect(Collectors.joining(">"));

List<Long> idList = Stream.of(ids.split(",")).map(x -> Long.valueOf(x)).collect(Collectors.toList());

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容