public UserIdNameArrayItem addData(long userId, String userName, int career, int level) { UserIdNameArrayItem item = new UserIdNameArrayItem(); item.setUserId(userId); item.setUserName(userName); item.setCareer(career); item.setLevel(level); list.add(item); return item; }
@Override public boolean validate() { for (UserIdNameArrayItem item : list) { if (!item.validate()) { return false; } } return true; }
/** 编码 */ @Override public void encode(Data data) { data.writeInt(list.size()); for (UserIdNameArrayItem item : list) { data.writeLong(item.getUserId()); data.writeString(item.getUserName()); data.writeInt(item.getCareer()); data.writeInt(item.getLevel()); } }
public String toString() { StringBuilder bb = new StringBuilder(); bb.append("["); int i = 0; for (UserIdNameArrayItem item : list) { bb.append("{").append(item.toString()).append("}"); i++; if (i != list.size()) { bb.append(", "); } } bb.append("]"); return bb.toString(); }
/** 解码 */ @Override public void decode(Data data) { int size = data.getInt(); for (int i = 0; i < size; i++) { UserIdNameArrayItem item = UserIdNameArrayItem.create(); item.setUserId(data.getLong()); item.setUserName(data.getString()); item.setCareer(data.getInt()); item.setLevel(data.getInt()); list.add(item); } }