public void setUserData(String key, Object data) { if (data == null) { if (userData != null) { userData.remove(key); if(userData.isEmpty()) { userData = null; } } } else { if (userData == null) { userData = new HashMap<String, Savable>(); } if (data instanceof Savable) { userData.put(key, (Savable) data); } else { userData.put(key, new UserData(UserData.getObjectType(data), data)); } } }
@SuppressWarnings("unchecked") public <T> T getUserData(String key) { if (userData == null) { return null; } Savable s = userData.get(key); if (s instanceof UserData) { return (T) ((UserData) s).getValue(); } else { return (T) s; } }
break; case TYPE_ARRAY: list.add(this.readList(ic, listName + "v" + i).toArray()); break; case TYPE_LIST: list.add(this.readList(ic, listName + "v" + i)); break; case TYPE_MAP: Map<Object, Object> map = new HashMap<Object, Object>(); List<?> keys = this.readList(ic, listName + "v(keys)" + i); List<?> values = this.readList(ic, listName + "v(vals)" + i); for (int j = 0; j < keys.size(); ++j) { map.put(keys.get(j), values.get(j));
} else if(o instanceof Object[]) { oc.write(TYPE_ARRAY, listName + "t" + counter, 0); this.writeList(oc, Arrays.asList((Object[]) o), listName + "v" + counter); } else if(o instanceof List) { oc.write(TYPE_LIST, listName + "t" + counter, 0); this.writeList(oc, (List<?>) o, listName + "v" + counter); } else if(o instanceof Map) { oc.write(TYPE_MAP, listName + "t" + counter, 0); Map<?, ?> map = (Map<?, ?>) o; this.writeList(oc, map.keySet(), listName + "v(keys)" + counter); this.writeList(oc, map.values(), listName + "v(vals)" + counter); } else { throw new UnsupportedOperationException("Unsupported type stored in the list: " + o.getClass());
public void setUserData(String key, Object data) { if (userData == null) { userData = new HashMap<String, Savable>(); } if(data == null){ userData.remove(key); }else if (data instanceof Savable) { userData.put(key, (Savable) data); } else { userData.put(key, new UserData(UserData.getObjectType(data), data)); } }
@SuppressWarnings("unchecked") public <T> T getUserData(String key) { if (userData == null) { return null; } Savable s = userData.get(key); if (s instanceof UserData) { return (T) ((UserData) s).getValue(); } else { return (T) s; } }
break; case TYPE_LIST: value = this.readList(ic, "0"); break; case TYPE_MAP: Map<Object, Object> map = new HashMap<Object, Object>(); List<?> keys = this.readList(ic, "0"); List<?> values = this.readList(ic, "1"); for (int i = 0; i < keys.size(); ++i) { map.put(keys.get(i), values.get(i)); break; case TYPE_ARRAY: value = this.readList(ic, "0").toArray(); break; default:
public void setUserData(String key, Object data) { if (data == null) { if (userData != null) { userData.remove(key); if(userData.isEmpty()) { userData = null; } } } else { if (userData == null) { userData = new HashMap<String, Savable>(); } if (data instanceof Savable) { userData.put(key, (Savable) data); } else { userData.put(key, new UserData(UserData.getObjectType(data), data)); } } }
@SuppressWarnings("unchecked") public <T> T getUserData(String key) { if (userData == null) { return null; } Savable s = userData.get(key); if (s instanceof UserData) { return (T) ((UserData) s).getValue(); } else { return (T) s; } }
} else if(o instanceof Object[]) { oc.write(TYPE_ARRAY, listName + "t" + counter, 0); this.writeList(oc, Arrays.asList((Object[]) o), listName + "v" + counter); } else if(o instanceof List) { oc.write(TYPE_LIST, listName + "t" + counter, 0); this.writeList(oc, (List<?>) o, listName + "v" + counter); } else if(o instanceof Map) { oc.write(TYPE_MAP, listName + "t" + counter, 0); Map<?, ?> map = (Map<?, ?>) o; this.writeList(oc, map.keySet(), listName + "v(keys)" + counter); this.writeList(oc, map.values(), listName + "v(vals)" + counter); } else { throw new UnsupportedOperationException("Unsupported type stored in the list: " + o.getClass());
break; case TYPE_ARRAY: list.add(this.readList(ic, listName + "v" + i).toArray()); break; case TYPE_LIST: list.add(this.readList(ic, listName + "v" + i)); break; case TYPE_MAP: Map<Object, Object> map = new HashMap<Object, Object>(); List<?> keys = this.readList(ic, listName + "v(keys)" + i); List<?> values = this.readList(ic, listName + "v(vals)" + i); for (int j = 0; j < keys.size(); ++j) { map.put(keys.get(j), values.get(j));
break; case TYPE_LIST: value = this.readList(ic, "0"); break; case TYPE_MAP: Map<Object, Object> map = new HashMap<Object, Object>(); List<?> keys = this.readList(ic, "0"); List<?> values = this.readList(ic, "1"); for (int i = 0; i < keys.size(); ++i) { map.put(keys.get(i), values.get(i)); break; case TYPE_ARRAY: value = this.readList(ic, "0").toArray(); break; default: