All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.common.IdentityCache Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.common;

import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

public class IdentityCache implements Cache {

   private final Map cache;

   public IdentityCache() {
      this(32);
   }

   public IdentityCache(int capacity) {
      this.cache = new IdentityHashMap();
   }

   @Override
   public synchronized void clear() {
      cache.clear();
   }

   @Override
   public synchronized int size() {
      return cache.size();
   }

   @Override
   public synchronized Set keySet() {
      return cache.keySet();
   }

   @Override
   public synchronized V fetch(K key) {
      return cache.get(key);
   }

   @Override
   public synchronized V cache(K key, V value) {
      return cache.put(key, value);
   }

   @Override
   public synchronized V take(K key) {
      return cache.remove(key);
   }

   @Override
   public synchronized boolean contains(K key) {
      return cache.containsKey(key);
   }

   @Override
   public synchronized boolean isEmpty() {
      return cache.isEmpty();
   }
   
   @Override
   public synchronized String toString() {
      return String.valueOf(cache);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy