private JsonPath pathFromCache(String path, Predicate[] filters) { Cache cache = CacheProvider.getCache(); String cacheKey = Utils.concat(path, new LinkedList<Predicate>(asList(filters)).toString()); JsonPath jsonPath = cache.get(cacheKey); if (jsonPath == null) { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); } return jsonPath; }
@Override public <T> T read(String path, Predicate... filters) { notEmpty(path, "path can not be null or empty"); Cache cache = CacheProvider.getCache(); path = path.trim(); LinkedList filterStack = new LinkedList<Predicate>(asList(filters)); String cacheKey = Utils.concat(path, filterStack.toString()); JsonPath jsonPath = cache.get(cacheKey); if(jsonPath != null){ return read(jsonPath); } else { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); return read(jsonPath); } }
@Override public Object readRoot(String[] paths, Predicate... filters) { if (null == paths || paths.length == 0) { throw new IllegalArgumentException(); } final Cache cache = CacheProvider.getCache(); final List<Predicate> filterStack = new LinkedList<Predicate>(asList(filters)); ; Object ret = null; Object rootObj = null; for (String path : paths) { path = path.trim(); String cacheKey = Utils.concat(path, filterStack.toString()); JsonPath jsonPath = cache.get(cacheKey); if (jsonPath == null) { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); } ret = jsonPath.readRoot(rootObj, json, configuration); rootObj = ret; } return ret; }
@Override public <T> T read(String path, Predicate... filters) { notEmpty(path, "path can not be null or empty"); // KR throw exception if config points to readRoot() if (configuration.getComputeRoot()) { throw new IllegalArgumentException("Invalid configuration, readRoot + read not supported."); } Cache cache = CacheProvider.getCache(); path = path.trim(); LinkedList filterStack = new LinkedList<Predicate>(asList(filters)); String cacheKey = Utils.concat(path, filterStack.toString()); JsonPath jsonPath = cache.get(cacheKey); if(jsonPath != null){ return read(jsonPath); } else { jsonPath = compile(path, filters); cache.put(cacheKey, jsonPath); return read(jsonPath); } }