/** * 保存 * * @param key * @param value */ public void save(String key, T value) { if (StringUtil.isNotEmpty(key, true) == false || value == null) { Log.e(TAG, "save StringUtil.isNotEmpty(key, true) == false || value == null >> return;"); return; } key = StringUtil.getTrimedString(key); sp.edit().remove(key).putString(key, Json.toJSONString(value)).commit(); }
/** * 获取 * * @param key * @return */ public T get(String key) { if (StringUtil.isNotEmpty(key, true) == false) { Log.e( TAG, "get (sp == null" + " || StringUtil.isNotEmpty(key, true) == false >> return null; "); return null; } return Json.parseObject(sp.getString(StringUtil.getTrimedString(key), null), clazz); }
/** * ROOT 获取列表 * * @return */ public List<T> getAllValueList() { Map<String, String> map = getMap(); if (map != null) { List<T> list = new ArrayList<>(); T data; for (String value : map.values()) { data = Json.parseObject(value, clazz); if (data != null) { list.add(data); } } return list; } return null; }