package chat.module.friendcircle;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import chat.module.ConcurrentMapList;
|
import chat.server.im.DataPool;
|
import chat.user.User;
|
import frame.object.data.Entity;
|
import frame.object.data.ID;
|
import frame.util.MapList;
|
|
public class FriendCircle {
|
|
private static ConcurrentMapList<CircleObject> allList;
|
private ConcurrentMapList<CircleObject> itemList;
|
private MapList<User> attentionList;
|
private boolean attention;
|
|
static {
|
allList = new ConcurrentMapList<CircleObject>();
|
}
|
|
public FriendCircle() {
|
itemList = new ConcurrentMapList<CircleObject>();
|
attentionList = new MapList<User>();
|
}
|
|
public void loadOneCricleObject(Entity entity) throws Exception {
|
CircleObject circleObject = new CircleObject(this);
|
circleObject.load(entity);
|
|
String id = circleObject.getId();
|
itemList.add(id, circleObject);
|
|
String ownerId = circleObject.getOwnerId();
|
if (!allList.contains(ownerId)) {
|
allList.add(id, circleObject);
|
}
|
}
|
|
public String createOneCircleObject(DataPool dataPool) {
|
String id = ID.newValue();
|
|
CircleObject result = new CircleObject(this);
|
result.setId(id);
|
result.load(dataPool);
|
|
result.insertToDB();
|
itemList.add(id, result);
|
|
return id;
|
}
|
|
public static List<CircleObject> getCircleObjectList(int pageNo, int pageSize) {
|
List<CircleObject> result = new ArrayList<CircleObject>();
|
|
int begin = pageNo * pageSize;
|
int end = Math.min((begin + pageSize), allList.size());
|
|
CircleObject object;
|
|
for (int i = begin; i < end; i++) {
|
object = allList.get(i);
|
result.add(object);
|
}
|
|
return result;
|
}
|
|
public List<CircleObject> getOneUserCircleObjectList(int pageNo, int pageSize) {
|
List<CircleObject> result = new ArrayList<CircleObject>();
|
|
int begin = pageNo * pageSize;
|
int end = Math.min((begin + pageSize), itemList.size());
|
|
CircleObject object;
|
|
for (int i = begin; i < end; i++) {
|
object = itemList.get(i);
|
result.add(object);
|
}
|
|
return result;
|
}
|
|
public CircleObject getOneCircleObjectList(String circleObjectId) {
|
return itemList.get(circleObjectId);
|
}
|
|
public boolean isAttention() {
|
return attention;
|
}
|
|
public void setAttention(boolean attention) {
|
this.attention = attention;
|
}
|
|
public void addOneAttention(User user) {
|
if (user == null) {
|
return;
|
}
|
|
String userId = user.getId();
|
|
if (!attentionList.contains(userId)) {
|
attentionList.add(userId, user);
|
}
|
}
|
|
public CircleObject getOneCircleObject(String circleObjectId) {
|
return itemList.get(circleObjectId);
|
}
|
|
}
|