コード例 #1
0
 /**
  * Unregisters the object associated with the specified class and context.
  *
  * @param clazz the class
  * @param context the context
  */
 public void unregister(Class<?> clazz, K context) {
   Cache<K, T> cache = getCache(clazz);
   if (cache != null) {
     cache.setObject(context, null);
     if (cache.size() == 0) {
       _cache.remove(clazz);
     }
   }
 }
コード例 #2
0
 /**
  * Remove all registrations for the designated class.
  *
  * @param clazz the class
  */
 @SuppressWarnings("unchecked")
 public void remove(Class<?> clazz) {
   Cache<K, T> cache = getCache(clazz);
   if (cache != null) {
     Object[] keys = cache.keySet().toArray();
     for (Object context : keys) {
       cache.setObject((K) context, null);
     }
   }
   _cache.remove(clazz);
 }
コード例 #3
0
  /**
   * Registers an object with the specified clazz and object.
   *
   * @param clazz the class which is used as the key.
   * @param object the object, or the value of the mapping
   * @param context the secondary key. It is used to register multiple objects to the same primary
   *     key (the clazz parameter in this case).
   */
  public void register(Class<?> clazz, T object, K context) {
    if (clazz == null) {
      throw new IllegalArgumentException("Parameter clazz cannot be null");
    }

    // register primitive type automatically
    if (TypeUtils.isPrimitiveWrapper(clazz)) {
      Class<?> primitiveType = TypeUtils.convertWrapperToPrimitiveType(clazz);
      register(primitiveType, object, context);
    }

    Cache<K, T> cache = initCache(clazz);
    cache.setObject(context, object);
  }