stream聚合流
stream聚合流通过map返回实体的某个属性,由于本源是list所以返回的是这个属性的list:
List<String> sqlTpaa= itan.stream().map(i -> {
String istr= i.getValue().toString();
JSONObject jmodel= JSONObject.parseObject(istr);
return jmodel.get("sqlType").toString();
}).collect(Collectors.toList());
System.out.println("=========sqlTpaa"+sqlTpaa);
String mdl=view.getModel();
JSONObject jsonmodel= JSONObject.parseObject(mdl);
Set<Map.Entry<String,Object>> ita= jsonmodel.entrySet();
List<ProDic> paginate = dicService.selectByEventCode(eventcode);
List<ProDicDto> proDicDtos = new ArrayList<>();
Set<Map.Entry<String,Object>> itans=new HashSet<>() ;
for (ProDic pg : paginate){
ProDicDto proDicDto = new ProDicDto();
BeanUtils.copyProperties(pg, proDicDto);
Set<Map.Entry<String,Object>> itan= ita.stream().filter(r -> {
String rv= r.getKey().toString();
return rv.equals("event_property_code") ; }
).collect(Collectors.toSet());
if (itan!=null && itan.size()>0){
Set<Map.Entry<String,Object>> sqlTp= itan.stream().map(i -> {
String istr= i.getValue().toString();
JSONObject jmodel= JSONObject.parseObject(istr);
proDicDto.setSqlType( jmodel.get("sqlType").toString());
return i;
}).collect(Collectors.toSet());
List<String> sqlTpaa= itan.stream().map(i -> {
String istr= i.getValue().toString();
JSONObject jmodel= JSONObject.parseObject(istr);
return jmodel.get("sqlType").toString();
}).collect(Collectors.toList());
System.out.println("=========sqlTpaa"+sqlTpaa);
}else{
proDicDto.setSqlType( "String");
}
proDicDtos.add(proDicDto);
}
stream聚合流中可以直接调用外部函数:
public List<String> getAggregators(String jdbcUrl, String dbVersion) {
if (!CollectionUtils.isEmpty(aggregators)) {
return this.aggregators.stream().map(a -> formatColumn(a.getColumn(), a.getFunc(), jdbcUrl, dbVersion, false)).collect(Collectors.toList());
}
return null;
}
private String formatColumn(String column, String func, String jdbcUrl, String dbVersion, boolean isLable) {
if (isLable) {
return String.join(EMPTY, func.trim(), PARENTHESES_START, column.trim(), PARENTHESES_END);
} else {
StringBuilder sb = new StringBuilder();
if ("COUNTDISTINCT".equals(func.trim().toUpperCase())) {
sb.append("COUNT").append(PARENTHESES_START).append("DISTINCT").append(SPACE);
sb.append(ViewExecuteParam.getField(column, jdbcUrl, dbVersion));
sb.append(PARENTHESES_END);
sb.append(" AS ").append(SqlUtils.getAliasPrefix(jdbcUrl, dbVersion)).append("COUNTDISTINCT").append(PARENTHESES_START);
sb.append(column);
sb.append(PARENTHESES_END).append(SqlUtils.getAliasSuffix(jdbcUrl, dbVersion));
} else {
sb.append(func.trim()).append(PARENTHESES_START);
sb.append(ViewExecuteParam.getField(column, jdbcUrl, dbVersion));
sb.append(PARENTHESES_END);
sb.append(" AS ").append(SqlUtils.getAliasPrefix(jdbcUrl, dbVersion));
sb.append(func.trim()).append(PARENTHESES_START);
sb.append(column);
sb.append(PARENTHESES_END).append(SqlUtils.getAliasSuffix(jdbcUrl, dbVersion));
}
return sb.toString();
}
}