- package com.suntek.mobilemeeting.comparator;
- import java.util.Comparator;
- import com.suntek.mobilemeeting.model.User;
- /**
- * 根据用户离线时间定制的比较器
- *
- * @author by wwj
- *
- */
- public class OfflineUserComparator implements Comparator {
- @Override
- public int compare(Object obj1, Object obj2) {
- User user1 = (User) obj1;
- User user2 = (User) obj2;
- int flag = user2.getLeftTime().compareTo(user1.getLeftTime());
- return flag;
- }
- }
这样使用:
- // 离线
- JSONArray offlineArray = json
- .optJSONArray(StringUtil.RES_OFF_USER_INFO);
- offlineUsers.clear();
- for (int i = 0; offlineArray != null
- && i < offlineArray.length(); i++) {
- JSONObject temp = (JSONObject) offlineArray.get(i);
- User user = new User();
- user.setUserId(temp.optString(StringUtil.USER_USERID));
- user.setSerialNo(temp
- .optString(StringUtil.USER_SERIAL_NO));
- user.setUserName(temp.optString(StringUtil.USER_NAME));
- user.setTelephone(temp
- .optString(StringUtil.USER_TELEPHONE));
- user.setStatus(-1);
- user.setJoinDateTime(temp
- .optString(StringUtil.USER_JOIN_DATE_TIME));
- user.setLeftTime(temp
- .optString(StringUtil.USER_LEFT_TIME));
- user.setGroupNo(temp.optInt(StringUtil.USER_GROUP_NO));
- user.setSubConfName(temp
- .optString(StringUtil.USER_SUB_CONF_NAME));
- offlineUsers.add(user);
- }
- OfflineUserComparator offlineUserComparator = new OfflineUserComparator();
- Collections.sort(offlineUsers, offlineUserComparator);