赞
踩
将string和 controlPersonList中的Id和Name作比较。
Matcher类的matches()方法是全字段匹配,find()方法是模糊搜搜匹配
- @Override
- public void doSearch(String string, List<ControlPerson> controlPersonList, List<ControlCar> controlCarsList) {
- List<ControlPerson> personSearchResult = new ArrayList<>();
- List<ControlCar> carSearchResult = new ArrayList<>();
-
- Pattern pattern = Pattern.compile(string);
-
- for(int i = 0; i<controlPersonList.size(); i++){
- Matcher matcher1 = pattern.matcher(controlPersonList.get(i).getId());
- Matcher matcher2 = pattern.matcher(controlPersonList.get(i).getName());
- if(matcher1.matches() || matcher2.matches()){
- personSearchResult.add(controlPersonList.get(i));
- }
- }
- for(int i = 0; i<controlCarsList.size(); i++){
- Matcher matcher3 = pattern.matcher(controlCarsList.get(i).getPlate());
- if(matcher3.matches()){
- carSearchResult.add(controlCarsList.get(i));
- }
- }
- iFilterControlDataView.initPersonList(personSearchResult);
- iFilterControlDataView.initCarList(carSearchResult);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。