java list过滤另一个list,
目录
1.对象结构2.根据字段名获取价值3。对目录过滤4.精确匹配5.模糊匹配
反射对效率有影响慎用!!!
1.对象结构
公类业务部{私串年;//年私弦月;//月私有字符串deptName//部门名称私有字符串deptLeader//部门负责人私双jyz//经营值私人双rev//收入私人双倍exp//支出私人双重工作时间;//填报工时私人双倍sWorkTime//标准工时私有双参数;//经营参数public void set year(字符串year){ this。年份=年份;} public void set month(字符串月){ this。月=月;} public void setDeptName(String deptName){ this。deptName=deptName} public void setDeptLeader(String deptLeader){ this。deptLeader=deptLeader} public void setJyz(Double jyz){ this。jyz=jyz} public String get year(){ return year;} public String get month(){ return month;} public String getDeptName(){ return deptName;}公共字符串getDeptLeader(){ return deptLeader;} public Double getJyz(){ return jyz;} public Double getRev(){ return rev;} public Double getExp(){ return exp;} public Double gettWorkTime(){ return tWorkTime;} public Double get work time(){ returns work time;} public Double get param(){ return param;} public void set rev(双rev){ this。rev=rev} public void setExp(Double exp){ this。exp=exp} public void setwork time(Double twork time){ this。工作时间=工作时间;} public void设置工作时间(Double swork time){ this。s工作时间=s工作时间;}公共void set param(Double param){ this。param=param} public E E get(字符串名){ Class cl=this。getclass();field[]fields=cl。getdeclaredfields();尝试{ for(Field Field : fields){ Field。设置可访问性(true);if (field.getName().equals(name)){ return(E)字段。get(这个);} } } catch(IllegalAccessException e){ e . printstacktrace();}返回null}}
2.根据字段名获取value
public E E get(字符串名){ Class cl=this。getclass();field[]fields=cl。getdeclaredfields();尝试{ for(Field Field : fields){ Field。设置可访问性(true);if (field.getName().equals(name)){ return(E)字段。get(这个);} } } catch(IllegalAccessException e){ e . printstacktrace();}返回null}
3.对list过滤
列出businessDeptList=this。我的查询();//筛选符合条件的listif(businessDeptList。size()0){ businessDeptList=this。filter exact( year ,year,businessDeptList);businessDeptList=this。filter exact( month ,month,businessDeptList);businessDeptList=this。过滤器模糊( deptName ,deptName,businessDeptList);businessDeptList=this。过滤模糊(部门领导,部门领导,业务部门列表);如果(!字符串实用程序。isempty(jyz)){ businessDeptList=this。filter exact( jyz ,Double.parseDouble(jyz),businessDeptList);}如果(!字符串实用程序。isempty(param)){ businessDeptList=this。filter exact( param ,Double.parseDouble(param),businessDeptList);}如果(!字符串实用程序。isempty(sWorkTime)){ businessDeptList=this。filter exact( sWorkTime ,Double.parseDouble(sWorkTime),businessDeptList);}如果(!字符串实用程序。isempty(rev)){ businessDeptList=this。filter exact( rev ,Double.parseDouble(rev),businessDeptList);}如果(!字符串实用程序。isempty(exp)){ businessDeptList=this。filter exact( exp ,Double.parseDouble(exp),businessDeptList);}如果(!字符串实用程序。isempty(two ktime)){ businessDeptList=this。精确筛选(两个ktime ,双精度。parse double(两个ktime),businessDeptList);}}
4.精确匹配
//精确匹配private TListBusinessDept filter exact(String name,T t,list business dept business depts){ if(T . tostring().isEmpty()){返回业务部门;} list营业部list=new ArrayList营业部();如果(业务部门。size()0){ for(int I=0;ibusinessdepts。size();i ){if(businessDepts.get(i)).获取(名称)。equals(t)){ list。添加(业务部门。get(I));} } }返回列表;}
5.模糊匹配
//模糊匹配private ListBusinessDept filter vague(String name,String s,ListBusinessDept business depts){ if(s . isempty()){ return business depts;} list营业部list=new ArrayList营业部();如果(业务部门。size()0){ for(int I=0;ibusinessdepts。size();i ){if(businessDepts.get(i)).获取(名称)。toString().包含个){列表。添加(业务部门。get(I));} } }返回列表;}到此这篇关于爪哇利用反射对目录对象做过滤的文章就介绍到这了,更多相关目录对象过滤内容请搜索盛行信息技术以前的文章或继续浏览下面的相关文章希望大家以后多多支持盛行它!
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。