1700483529
代码清单37-3 用户操作类
1700483530
1700483531
public class UserProvider implements IUserProvider{
1700483532
1700483533
//用户列表
1700483534
1700483535
private ArrayList<User>userList;
1700483536
1700483537
//构造函数传递用户列表
1700483538
1700483539
public UserProvider(ArrayList<User>_userList){
1700483540
1700483541
this.userList=_userList;
1700483542
1700483543
}
1700483544
1700483545
//年龄大于指定年龄的用户
1700483546
1700483547
public ArrayList<User>findUserByAgeThan(int age){
1700483548
1700483549
ArrayList<User>result=new ArrayList<User>();
1700483550
1700483551
for(User u:userList){
1700483552
1700483553
if(u.getAge()>age){//符合条件的用户
1700483554
1700483555
result.add(u);
1700483556
1700483557
}
1700483558
1700483559
}
1700483560
1700483561
return result;
1700483562
1700483563
}
1700483564
1700483565
//姓名等于指定姓名的用户
1700483566
1700483567
public ArrayList<User>findUserByNameEqual(String name){
1700483568
1700483569
ArrayList<User>result=new ArrayList<User>();
1700483570
1700483571
for(User u:userList){
1700483572
1700483573
if(u.getName().equals(name)){//符合条件
1700483574
1700483575
result.add(u);
1700483576
1700483577
}
1700483578
[
上一页 ]
[ :1.700483529e+09 ]
[
下一页 ]