public List groupBy(List list,String flag,String... sortName) throws Exception{
Map<String,List<Object>> tMap = new HashMap<String,List<Object>>();
for(Object t : list){
String filedKey ="";
for(String filedName : sortName){
Field field = t.getClass().getDeclaredField(filedName);
filedKey = field.get(t)+","+filedKey;
System.out.println("filedName======"+filedKey);
}

if(tMap.containsKey(filedKey)){
tMap.get(filedKey).add(t);
}else{
List tList1 = new ArrayList();
tList1.add(t);
tMap.put(filedKey,tList1);
}
}

Field fields[]=list.get(0).getClass().getDeclaredFields();//获得对象所有属性
Field field=null;
for (int i = 0; i < fields.length; i++) {
field=fields[i];
field.setAccessible(true);
}
List<CoastClaimResult> claimList = new ArrayList<CoastClaimResult>();
for(Map.Entry<String,List<Object>> entry : tMap.entrySet()){
BigDecimal billedAmt=new BigDecimal(0);
List<String> distinctCountList = new ArrayList<String>();
CoastClaimResult result = new CoastClaimResult();
System.out.println("Key = " + entry.getKey());
for(Object t : entry.getValue()){
System.out.println(t.toString());

String bill = (String) t.getClass().getDeclaredField("amount"+flag).get(t);
billedAmt.add(new BigDecimal(bill));

String claimNo = (String) t.getClass().getDeclaredField("claimNo").get(t);
if(!distinctCountList.contains(claimNo)){
distinctCountList.add(claimNo);
}

/*String paid = (String) t.getClass().getDeclaredField("amountpaid").get(t);
paidAmt.add(new BigDecimal(paid));*/
}
for(String filedName : sortName){
Field f = CoastClaimResult.class.getClass().getDeclaredField("filedName");
f.setAccessible(true);
f.set(CoastClaimResult.class, (String) list.get(0).getClass().getDeclaredField("filedName").get(list.get(0)));
}
result.setExt1(new BigDecimal(distinctCountList.size()));
if(flag.equals("billed")){
result.setBilledAmt(billedAmt);
result.setTitleCategory("BILLED");
}else{
result.setPaidAmt(billedAmt);
result.setTitleCategory("PAID");
}

// result.setPaidAmt(paidAmt);
claimList.add(result);


// System.out.println(polNo.toString());
}

return claimList;
}

groupBy的更多相关文章

  1. GroupBy(..)的四种声明方式的理解及调用

    这里我们以 List<Student> studs作为 source,但是注意,studs中的学生可以是分别属于不同的班级和年级 先看GroupBy的第一种声明: public stati ...

  2. C# List泛型集合中的GroupBy<>用法

    //根据子项目id得到flowjump实体类 flowJumps = this.FlowJumps; //按工序groupby flowjumps IEnumerable<IGrouping&l ...

  3. entity framework 新手入门篇(3)-entity framework实现orderby,count,groupby,like,in,分页等

    前面我们已经学习了entityframework的基本的增删改查,今天,我们将在EF中实现一些更加贴近于实际功能的SQL方法. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和 ...

  4. Lambda GroupBy Sum

    DataTable dt = new DataTable(); dt.AsEnumerable().GroupBy(r => r["ShopName"]) .Select(g ...

  5. Atitit  数据存储的分组聚合 groupby的实现attilax总结

    Atitit  数据存储的分组聚合 groupby的实现attilax总结 1. 聚合操作1 1.1. a.标量聚合 流聚合1 1.2. b.哈希聚合2 1.3. 所有的最优计划的选择都是基于现有统计 ...

  6. MongoDB数据库GroupBy查询使用Spring-data-mongondb的实现

    以前用MongoDB数据库都是简单的查询,直接用Query就可以,最近项目中用到了分组查询,完全不一样.第一次遇到,搞了好几天终于有点那意思了. 先上代码: import java.math.BigD ...

  7. HIVE: collect_set(输出未包含在groupby的字段);

    今天帮同事测试,发现代码里有个好用的hive 函数: 1. collect_set 可以输出未包含在groupby里的字段.条件是,这个字段值对应于主键是唯一的. select a, collect_ ...

  8. Groupby - collection processing

    Groupby - collection processing Iterator and Iterable have most of the most useful methods when deal ...

  9. Linq 中按照多个值进行分组(GroupBy)

    Linq 中按照多个值进行分组(GroupBy) .GroupBy(x => new { x.Age, x.Sex }) group emp by new { emp.Age, emp.Sex ...

  10. Linq_Lambda GroupBy使用笔记

    今天看MVC遇到了GroupBY的Lambda表达式..有兴趣详细的看下去..得此笔记..记录之... 不罗嗦..上代码... //得到List<GroupEmail>对象 数据源 var ...

随机推荐

  1. SQL server 2012序列号 注册码 z

    MICROSOFT SQL SERVER 2012 企业核心版激活码序列号: FH666-Y346V-7XFQ3-V69JM-RHW28 MICROSOFT SQL SERVER 2012 商业智能版 ...

  2. HDU-1036 Average is not Fast Enough!

    Average is not Fast Enough! http://acm.hdu.edu.cn/showproblem.php?pid=1036 Problem Description A rel ...

  3. HDU-5347 MZL's chemistry

    http://acm.hdu.edu.cn/showproblem.php?pid=5347 MZL's chemistry Time Limit: 2000/1000 MS (Java/Others ...

  4. Java笔记(四)……常量与变量

    常量 常量表示不会改变的数值. Java中常量的分类: 整数常量:所有整数 小数常量:所有小数 布尔型常量:较为特有,只有两个数值,true false 字符常量:将一个数字字母或者符号用单引号(' ...

  5. Java笔记(三)……基础语法

    关键字 标识符 在程序中自定义的一些名称 由26个英文字母大小写,数字:0-9,符号:_ $组成 定义合法标识符规则: 数字不可以开头. 不可以使用关键字. Java中严格区分大小写. 注意:在起名字 ...

  6. Codeforces 650C Table Compression (并查集)

    题意:M×N的矩阵 让你保持每行每列的大小对应关系不变,将矩阵重写,重写后的最大值最小. 思路:离散化思想+并查集,详见代码 好题! #include <iostream> #includ ...

  7. git日常操作

    0.准备工作 0.1 git安装 http://git-scm.com/download/   图形客户端建议使用source tree,中文界面 http://www.sourcetreeapp.c ...

  8. Esper系列(四)Output

    功能 控制Esper事件流计算结果的输入形式.时间点及频率: 格式 1  ";

  9. ORA-01653:表空间扩展失败的问题(开启表空间自动扩展)

    ----查询表空间使用情况---使用DBA权限登陆SELECT UPPER(F.TABLESPACE_NAME) "表空间名",D.TOT_GROOTTE_MB "表空间 ...

  10. A Tour of Go For

    Go has only one looping construct, the for loop. The basic for loop looks as it does in C or Java, e ...