groupBy
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的更多相关文章
- GroupBy(..)的四种声明方式的理解及调用
这里我们以 List<Student> studs作为 source,但是注意,studs中的学生可以是分别属于不同的班级和年级 先看GroupBy的第一种声明: public stati ...
- C# List泛型集合中的GroupBy<>用法
//根据子项目id得到flowjump实体类 flowJumps = this.FlowJumps; //按工序groupby flowjumps IEnumerable<IGrouping&l ...
- entity framework 新手入门篇(3)-entity framework实现orderby,count,groupby,like,in,分页等
前面我们已经学习了entityframework的基本的增删改查,今天,我们将在EF中实现一些更加贴近于实际功能的SQL方法. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和 ...
- Lambda GroupBy Sum
DataTable dt = new DataTable(); dt.AsEnumerable().GroupBy(r => r["ShopName"]) .Select(g ...
- Atitit 数据存储的分组聚合 groupby的实现attilax总结
Atitit 数据存储的分组聚合 groupby的实现attilax总结 1. 聚合操作1 1.1. a.标量聚合 流聚合1 1.2. b.哈希聚合2 1.3. 所有的最优计划的选择都是基于现有统计 ...
- MongoDB数据库GroupBy查询使用Spring-data-mongondb的实现
以前用MongoDB数据库都是简单的查询,直接用Query就可以,最近项目中用到了分组查询,完全不一样.第一次遇到,搞了好几天终于有点那意思了. 先上代码: import java.math.BigD ...
- HIVE: collect_set(输出未包含在groupby的字段);
今天帮同事测试,发现代码里有个好用的hive 函数: 1. collect_set 可以输出未包含在groupby里的字段.条件是,这个字段值对应于主键是唯一的. select a, collect_ ...
- Groupby - collection processing
Groupby - collection processing Iterator and Iterable have most of the most useful methods when deal ...
- Linq 中按照多个值进行分组(GroupBy)
Linq 中按照多个值进行分组(GroupBy) .GroupBy(x => new { x.Age, x.Sex }) group emp by new { emp.Age, emp.Sex ...
- Linq_Lambda GroupBy使用笔记
今天看MVC遇到了GroupBY的Lambda表达式..有兴趣详细的看下去..得此笔记..记录之... 不罗嗦..上代码... //得到List<GroupEmail>对象 数据源 var ...
随机推荐
- uDig介绍
一 安装配置Java平台此步骤不必多说,如果您是Java开发者可以跳过.如果您的机器上没有Java平台,那么请到http://java.sun.com下载jdk,当下最新的版本是1.6.安装jdk,请 ...
- 【转】小解DCT与DFT
这学期当本科生数字图像处理的助教老师,为使学生更好地理解DCF和DFT之间的关系给出三题,大家可以思考一下,看一下自己对这些最简单的变换是否真正理解. 1.求解序列f(n)=[2,3,3,4,4,3, ...
- Html笔记(四)图像
图像标签: <img> <img src="../dir/file" alt="说明文字" height width border/> ...
- FP树(附)
Apriori算法和FPTree算法都是数据挖掘中的关联规则挖掘算法,处理的都是最简单的单层单维布尔关联规则. 转自http://blog.csdn.net/sealyao/article/detai ...
- python seq
missing parentheses in call to print ==> python高版本 print("") name 'raw_input' is not d ...
- 最常用的Java库一览
本文由 ImportNew - 邢 敏 翻译自 programcreek.欢迎加入翻译小组.转载请见文末要求. 写在前面: 1) 本文列出的名单是根据我自己的调查,并结合个人的经验.有可能是它们不恰恰 ...
- javascript function对象
<html> <body> <script type="text/javascript"> Function.prototype.get_my_ ...
- oc学习之路----APNS消息推送从证书到代码(2015年4月26号亲试可用)
前言:看这篇博客之前要准备:首先的有一个99刀的个人开发者账号或者199刀的企业开发者账号,其次你用的是apns消息推送,(本人之前四处打听有没有其他消息推送的方法:收获如下:首先如果想做到apns的 ...
- JavaScript- 获得TreeView CheckBox里选中项的值
获得TreeView CheckBox里选中项的值,对JSDOM控制还不是很熟,感觉不太容易.试了很多次终于成功了. 代码如下 <body> <form id="form1 ...
- Android应用换肤总结
换肤,我们都很熟悉,像XP的主题,塞班的主题.看过国外的一些技术博客,就会发现国内和国外对软件的,或者说移动开发的软件的需求的不同.国外用户注重社交.邮件等功能,国内用户则重视音乐.小说.皮肤等功能, ...