Skip to content

Instantly share code, notes, and snippets.

@Arbow
Created April 24, 2009 01:47
Show Gist options
  • Save Arbow/100879 to your computer and use it in GitHub Desktop.
Save Arbow/100879 to your computer and use it in GitHub Desktop.
public <T extends Room> List<Integer> getBatchPlayerAmountOfRooms(List<T> rooms) {
if (rooms == null || rooms.size() == 0)
return new ArrayList<Integer>(0);
Collection<String> uidList = FPUtils.map(rooms, new FPUtils.MapFunc<T, String>() {
@Override
public String map(T room) {
return roomCacheKey(room);
}
});
final Map<String, Integer> cacheAmountList = FPUtils.map2(uidList, new FPUtils.MapFunc<String, Integer>() {
@Override
public Integer map(String roomUid) {
return getLocalRoomPlayerAmountCache().get(roomUid);
}
});
Collection<String> needfetchUids = FPUtils.filterMap(cacheAmountList,
new FPUtils.MapEntryFilterFunc<String, Integer>() {
@Override
public boolean filter(Entry<String, Integer> entry) {
return entry.getValue() == null;
}
}).keySet();
Map<RoomState, Integer> fetchResult = loadBatchPlayerAmountOfRooms(needfetchUids);
FPUtils.foreach(fetchResult.entrySet(), new FPUtils.ForeachFunc<Entry<RoomState, Integer>>() {
@Override
public void visit(Entry<RoomState, Integer> entry) {
cacheAmountList.put(entry.getKey().getRoomUid(), entry.getValue());
}
});
return new ArrayList<Integer>(cacheAmountList.values());
}
protected Map<RoomState, Integer> loadBatchPlayerAmountOfRooms(Collection<String> roomUids) {
Collection<RoomState> states = RoomState.loadBatch(roomUids, cacheClient, this);
return FPUtils.map2(states, new FPUtils.MapFunc<RoomState, Integer>() {
@Override
public Integer map(RoomState obj) {
return obj.getPlayerAmount();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment