1 13 14 package org.ejbca.ui.web.admin.rainterface; 15 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Collections ; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 22 import org.ejbca.core.model.ra.UserDataVO; 23 24 25 26 27 32 public class UsersView implements java.io.Serializable { 33 34 35 public UsersView() { 36 users = new ArrayList (); 37 sortby = new SortBy(); 38 } 39 40 public UsersView(UserDataVO importuser, HashMap caidtonamemap){ 41 users = new ArrayList (); 42 sortby = new SortBy(); 43 users.add(new UserView(importuser, caidtonamemap)); 44 45 Collections.sort(users); 46 } 47 48 public UsersView(Collection importusers, HashMap caidtonamemap){ 49 users = new ArrayList (); 50 sortby = new SortBy(); 51 52 setUsers(importusers, caidtonamemap); 53 } 54 56 public void sortBy(int sortby, int sortorder) { 57 this.sortby.setSortBy(sortby); 58 this.sortby.setSortOrder(sortorder); 59 60 Collections.sort(users); 61 } 62 63 public UserView[] getUsers(int index, int size) { 64 int endindex; 65 UserView[] returnval; 66 67 if(index > users.size()) index = users.size()-1; 68 if(index < 0) index =0; 69 70 endindex = index + size; 71 if(endindex > users.size()) endindex = users.size(); 72 73 returnval = new UserView[endindex-index]; 74 75 int end = endindex - index; 76 for(int i = 0; i < end; i++){ 77 returnval[i] = (UserView) users.get(index+i); 78 } 79 80 return returnval; 81 } 82 83 public void setUsers(UserView[] users) { 84 this.users.clear(); 85 if(users !=null && users.length > 0){ 86 for(int i=0; i < users.length; i++){ 87 users[i].setSortBy(this.sortby); 88 this.users.add(users[i]); 89 } 90 } 91 Collections.sort(this.users); 92 } 93 94 public void setUsers(UserDataVO[] users, HashMap caidtonamemap) { 95 UserView user; 96 this.users.clear(); 97 if(users !=null && users.length > 0){ 98 for(int i=0; i< users.length; i++){ 99 user = new UserView(users[i], caidtonamemap); 100 user.setSortBy(this.sortby); 101 this.users.add(user); 102 } 103 Collections.sort(this.users); 104 } 105 } 106 107 public void setUsers(Collection importusers, HashMap caidtonamemap) { 108 109 UserView user; 110 Iterator i; 111 this.users.clear(); 112 if(importusers!=null && importusers.size() > 0){ 113 i=importusers.iterator(); 114 while(i.hasNext()){ 115 UserDataVO nextuser = (UserDataVO) i.next(); 116 user = new UserView(nextuser, caidtonamemap); 117 user.setSortBy(this.sortby); 118 users.add(user); 119 } 120 Collections.sort(users); 121 } 122 } 123 124 public void addUser(UserView user) { 125 user.setSortBy(this.sortby); 126 users.add(user); 127 } 128 129 public int size(){ 130 return users.size(); 131 } 132 133 public void clear(){ 134 this.users.clear(); 135 } 136 private ArrayList users; 138 private SortBy sortby; 139 140 } 141 | Popular Tags |