[jboss-cvs] JBossAS SVN: r93170 - in projects/annotations/trunk/core/src: main/java/org/jboss/annotations/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 3 10:46:50 EDT 2009


Author: jesper.pedersen
Date: 2009-09-03 10:46:50 -0400 (Thu, 03 Sep 2009)
New Revision: 93170

Modified:
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
   projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java
Log:
[JBANN-16] Add a merge method to AnnotationRepository

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-09-03 14:44:16 UTC (rev 93169)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationRepository.java	2009-09-03 14:46:50 UTC (rev 93170)
@@ -73,4 +73,10 @@
     *         if no annotations exists
     */
    public Collection<Annotation> getAnnotation(String annotation);
+
+   /**
+    * Merge an annotation repository
+    * @param ar The annotation repository
+    */
+   public void merge(AnnotationRepository ar);
 }

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-09-03 14:44:16 UTC (rev 93169)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AnnotationRepositoryImpl.java	2009-09-03 14:46:50 UTC (rev 93170)
@@ -29,6 +29,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -234,6 +235,68 @@
    }
 
    /**
+    * Merge an annotation repository
+    * @param ar The annotation repository
+    */
+   public void merge(AnnotationRepository ar)
+   {
+      if (ar != null && ar instanceof AnnotationRepositoryImpl)
+      {
+         AnnotationRepositoryImpl ari = (AnnotationRepositoryImpl)ar;
+         ConcurrentMap<String, Collection<String>> ac = ari.getAnnotationToClasses();
+         ConcurrentMap<String, ClassInfo> ci = ari.getClassInfo();
+
+         Iterator<Map.Entry<String, Collection<String>>> ait = ac.entrySet().iterator();
+         while (ait.hasNext())
+         {
+            Map.Entry<String, Collection<String>> entry = ait.next();
+            String a = entry.getKey();
+            Collection<String> v = entry.getValue();
+
+            if (!annotationToClasses.containsKey(a))
+            {
+               annotationToClasses.put(a, v);
+            }
+            else
+            {
+               Collection<String> classes = annotationToClasses.get(a);
+               classes.addAll(v);
+            }
+         }
+
+         Iterator<Map.Entry<String, ClassInfo>> cit = ci.entrySet().iterator();
+         while (cit.hasNext())
+         {
+            Map.Entry<String, ClassInfo> entry = cit.next();
+            String key = entry.getKey();
+
+            if (!classInfo.containsKey(key))
+            {
+               classInfo.put(key, entry.getValue());
+            }
+         }
+      }
+   }
+
+   /**
+    * Get the annotation to classes datastructure
+    * @return The structure
+    */
+   ConcurrentMap<String, Collection<String>> getAnnotationToClasses()
+   {
+      return annotationToClasses;
+   }
+
+   /** 
+    * Get the class information datastructure
+    * @return The strcuture 
+    */
+   ConcurrentMap<String, ClassInfo> getClassInfo()
+   {
+      return classInfo;
+   }
+
+   /**
     * Fold annotations onto children
     * @param annotations The annotations that should folded onto each child
     * @param ci The parent class information

Modified: projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java
===================================================================
--- projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java	2009-09-03 14:44:16 UTC (rev 93169)
+++ projects/annotations/trunk/core/src/test/java/org/jboss/annotations/test/AnnotationRepositoryTests.java	2009-09-03 14:46:50 UTC (rev 93170)
@@ -354,4 +354,73 @@
          // Ok
       }
    }
+
+   /**
+    * Merge: Empty
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testMergeEmpty() throws Throwable
+   {
+      URL archive = getURL("classempty.jar");
+      AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
+
+      assertNotNull(ar1);
+
+      assertTrue(ar1.getSize() == 0);
+
+      AnnotationRepository ar2 = scanner.scan(new URL[] {archive});
+
+      ar1.merge(ar2);
+
+      assertTrue(ar1.getSize() == 0);
+   }
+
+   /**
+    * Merge
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testMergeFullEmpty() throws Throwable
+   {
+      URL archive1 = getURL("classlevel.jar");
+      AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive1});
+
+      assertNotNull(ar1);
+      assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
+
+      URL archive2 = getURL("classempty.jar");
+      AnnotationRepositoryImpl ar2 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive2});
+
+      assertNotNull(ar2);
+      assertTrue("Size=" + ar2.getSize(), ar2.getSize() == 0);
+
+      ar1.merge(ar2);
+
+      assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
+   }
+
+   /**
+    * Merge
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testMergeEmptyFull() throws Throwable
+   {
+      URL archive1 = getURL("classempty.jar");
+      AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive1});
+
+      assertNotNull(ar1);
+      assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 0);
+
+      URL archive2 = getURL("classlevel.jar");
+      AnnotationRepositoryImpl ar2 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive2});
+
+      assertNotNull(ar2);
+      assertTrue("Size=" + ar2.getSize(), ar2.getSize() == 1);
+
+      ar1.merge(ar2);
+
+      assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
+   }
 }




More information about the jboss-cvs-commits mailing list