/** * 判断是否已存 * * @param key * @return */ public boolean isContain(String key) { if (StringUtil.isNotEmpty(key, true) == false) { Log.e(TAG, "isContain StringUtil.isNotEmpty(key, true) == false >> return false;"); return false; } return sp.contains(StringUtil.getTrimedString(key)); }
/** * 保存 * * @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); }
/** * 删除 * * @param key */ public void delete(String key) { if (StringUtil.isNotEmpty(key, true) == false) { Log.e( TAG, "deleteGroup context == null " + " || StringUtil.isNotEmpty(groupName, true) == fal >> return;"); return; } sp.edit().remove(StringUtil.getTrimedString(key)).commit(); }
/** * 保存 * * @param map */ public void saveList(Map<Long, T> map) { if (map == null) { Log.e(TAG, "saveList map == null >> return;"); return; } Set<Long> keySet = map.keySet(); if (keySet != null) { for (long id : keySet) { save("" + id, map.get(id)); } } }
/** * ROOT 获取列表 * * @return */ @SuppressWarnings("unchecked") public Map<String, String> getMap() { try { return (Map<String, String>) sp.getAll(); } catch (Exception e) { Log.e( TAG, "getMap try { return (Map<String, String>) sp.getAll();" + "}catch(Exception e) {\n " + e.getMessage()); } return null; }