@Test @SuppressWarnings("unchecked") public void execute() { AbstractSearchableCache<Integer, Item> abstractCache = new AbstractSearchableCache<Integer, Item>( "searchable-cache", key -> null, (key, value) -> { }, indexHandler) { final Map<Integer, Item> items = new HashMap<>(); @Override public void put(Integer key, Item value) { items.put(key, value); indexHandler.add(key, value); } @Override public void put(Integer key, Item value, TimeUnit timeUnit, long duration) { items.put(key, value); indexHandler.add(key, value); } @Override public Item get(Integer key) { return null; } @Override public Item invalidate(Integer key) { final Item value = items.remove(key); indexHandler.remove(key, value); return null; } @Override public boolean contains(Integer key) { return false; } @Override public void clear() { } @Override public long size() { return 0; } @Override public CacheStats stats() { return null; } }; Item item1 = new Item(1); Item item2 = new Item(2); abstractCache.put(1, item1); abstractCache.put(2, item1); List<Integer> keys = new ArrayList<Integer>(); keys.add(1); keys.add(2); List<Item> values = new ArrayList<Item>(); values.add(item1); values.add(item2); doReturn(keys).when(indexHandler).execute(any(Query.class)); doReturn(values).when(filter).filter(anyList()); List<Item> items = abstractCache .execute(CacheQuery.newQuery().setCriteria(criteria).setFilter(filter)); assertTrue(items.contains(item1)); assertTrue(items.contains(item2)); abstractCache.setCacheLoader(key -> null); assertNull(abstractCache.getCacheLoader().load(1)); assertEquals("searchable-cache", abstractCache.getName()); abstractCache.setEvictionListener((key, value) -> { }); }
@SuppressWarnings("unchecked") public List<V> execute(Query query) { List<K> keys = indexHandler.execute(query); List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } if (query.getFilter() != null) { values = (List<V>) query.getFilter().filter((List<Object>) values); } return values; }
AbstractSearchableCache extends AbstractCache<K, V> implements
    SearchableCache<K, V> { @SuppressWarnings("unchecked") public List<V> execute(Query query) { List<K> keys = indexHandler.execute(query); List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } if (query.getFilter() != null) { values = (List<V>) query.getFilter().filter((List<Object>) values); } return values; } }
AbstractSearchableCache extends AbstractCache<K, V> implements
    SearchableCache<K, V> { @SuppressWarnings("unchecked") public List<V> execute(Query query) { List<K> keys = indexHandler.execute(query); List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } if (query.getFilter() != null) { values = (List<V>) query.getFilter().filter((List<Object>) values); } return values; } AbstractSearchableCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      IndexHandler<K, V> indexHandler); }
AbstractSearchableCache extends AbstractCache<K, V> implements
    SearchableCache<K, V> { @SuppressWarnings("unchecked") public List<V> execute(Query query) { List<K> keys = indexHandler.execute(query); List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } if (query.getFilter() != null) { values = (List<V>) query.getFilter().filter((List<Object>) values); } return values; } AbstractSearchableCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      IndexHandler<K, V> indexHandler); @SuppressWarnings("unchecked") List<V> execute(Query query); }
AbstractSearchableCache extends AbstractCache<K, V> implements
    SearchableCache<K, V> { @SuppressWarnings("unchecked") public List<V> execute(Query query) { List<K> keys = indexHandler.execute(query); List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } if (query.getFilter() != null) { values = (List<V>) query.getFilter().filter((List<Object>) values); } return values; } AbstractSearchableCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      IndexHandler<K, V> indexHandler); @SuppressWarnings("unchecked") List<V> execute(Query query);  }