[jboss-cvs] JBossCache/src/org/jboss/cache/notifications ...

Elias Ross genman at noderunner.net
Tue Apr 17 02:09:13 EDT 2007


  User: genman  
  Date: 07/04/17 02:09:13

  Modified:    src/org/jboss/cache/notifications  Notifier.java
  Log:
  JBCACHE-1005 - Clean up warnings generated from genericising of interface
  Use Collections.singletonMap() for cases only a single key/value is used
  
  Revision  Changes    Path
  1.19      +14 -11    JBossCache/src/org/jboss/cache/notifications/Notifier.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Notifier.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/notifications/Notifier.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- Notifier.java	10 Jan 2007 18:02:51 -0000	1.18
  +++ Notifier.java	17 Apr 2007 06:09:13 -0000	1.19
  @@ -29,7 +29,7 @@
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
  -public class Notifier
  +public class Notifier<K, V>
   {
   
      // calling iterator on a Concurrent Set is expensive due to synchronization - same problem
  @@ -51,6 +51,9 @@
      // --- the java.lang.reflect.Methods of CacheListener
      private static Method nodeCreated, nodeModified, nodeRemoved, nodeVisited, nodeEvicted, nodeLoaded, nodePassivated, nodeActivated, nodeMoved, cacheStarted, cacheStopped, viewChange;
   
  +   private static Class emptyMap = Collections.emptyMap().getClass();
  +   private static Class singletonMap = Collections.singletonMap(null, null).getClass();
  +   
      static
      {
         try
  @@ -74,7 +77,6 @@
         }
      }
   
  -
      public Notifier(CacheImpl cache)
      {
         this.cache = cache;
  @@ -178,7 +180,7 @@
       * @param data
       * @param sendImmediately
       */
  -   public void notifyNodeModified(Fqn fqn, boolean pre, CacheListener.ModificationType modificationType, Map<Object, Object> data, boolean sendImmediately)
  +   public void notifyNodeModified(Fqn fqn, boolean pre, CacheListener.ModificationType modificationType, Map<K, V> data, boolean sendImmediately)
      {
         boolean originLocal = cache.getInvocationContext().isOriginLocal();
         Map dataCopy = copy(data);
  @@ -213,7 +215,7 @@
       * @param data
       * @param sendImmediately
       */
  -   public void notifyNodeRemoved(Fqn fqn, boolean pre, Map<Object, Object> data, boolean sendImmediately)
  +   public void notifyNodeRemoved(Fqn fqn, boolean pre, Map<K, V> data, boolean sendImmediately)
      {
         boolean originLocal = cache.getInvocationContext().isOriginLocal();
         Map dataCopy = copy(data);
  @@ -342,21 +344,21 @@
       * @param data
       * @param sendImmediately
       */
  -   public void notifyNodeLoaded(Fqn fqn, boolean pre, Map<Object, Object> data, boolean sendImmediately)
  +   public void notifyNodeLoaded(Fqn fqn, boolean pre, Map<K, V> data, boolean sendImmediately)
      {
  -      Map dataCopy = copy(data);
  +      Map<K, V> dataCopy = copy(data);
         if (sendImmediately)
         {
            resetInvocationContext();
            if (evictionPolicyListener != null)
            {
  -            evictionPolicyListener.nodeLoaded(fqn, pre, dataCopy);
  +            evictionPolicyListener.nodeLoaded(fqn, pre, (Map<Object, Object>) dataCopy);
            }
            if (hasListeners)
            {
               for (CacheListener listener : listeners)
               {
  -               listener.nodeLoaded(fqn, pre, dataCopy);
  +               listener.nodeLoaded(fqn, pre, (Map<Object, Object>) dataCopy);
               }
            }
            restoreInvocationContext();
  @@ -525,10 +527,10 @@
         }
      }
   
  -   private Map copy(Map<Object, Object> data)
  +   private Map<K, V> copy(Map<K, V> data)
      {
         if (safe(data)) return data;
  -      return new MapCopy<Object, Object>(data);
  +      return new MapCopy<K, V>(data);
      }
   
      private void restoreInvocationContext()
  @@ -555,6 +557,7 @@
       * <li>It is null</li>
       * <li>It is an instance of {@link org.jboss.cache.util.MapCopy}, which is immutable</li>
       * <li>It is an instance of {@link java.util.Collections#emptyMap()}, which is also immutable</li>
  +    * <li>It is an instance of {@link java.util.Collections#singletonMap()}, which is also immutable</li>
       * </ul>
       *
       * @param map
  @@ -562,7 +565,7 @@
       */
      private boolean safe(Map map)
      {
  -      return map == null || map instanceof MapCopy || map.getClass().equals(Collections.emptyMap().getClass());
  +      return map == null || map instanceof MapCopy || map.getClass().equals(emptyMap) || map.getClass().equals(singletonMap);
      }
   
      /**
  
  
  



More information about the jboss-cvs-commits mailing list