[weld-commits] Weld SVN: r6358 - in core/trunk/impl/src/main/java/org/jboss/weld: util/collections and 1 other directory.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Fri May 28 14:10:02 EDT 2010


Author: dallen6
Date: 2010-05-28 14:10:01 -0400 (Fri, 28 May 2010)
New Revision: 6358

Added:
   core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySetSupplier.java
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
Log:
Changed a couple ArrayListMultimaps back to SetMultimaps where sets should still be used

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java	2010-05-28 12:31:09 UTC (rev 6357)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java	2010-05-28 18:10:01 UTC (rev 6358)
@@ -23,6 +23,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -37,12 +38,14 @@
 import org.jboss.weld.metadata.TypeStore;
 import org.jboss.weld.resources.ClassTransformer;
 import org.jboss.weld.util.Proxies;
+import org.jboss.weld.util.collections.ArraySetSupplier;
 import org.jboss.weld.util.collections.Arrays2;
 import org.jboss.weld.util.collections.ImmutableArraySet;
 import org.jboss.weld.util.reflection.HierarchyDiscovery;
 
-import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
 
 /**
  * Represents functionality common for all annotated items, mainly different
@@ -126,7 +129,7 @@
    private final Map<Class<? extends Annotation>, Annotation> annotationMap;
    // The meta-annotation map (annotation type -> set of annotations containing
    // meta-annotation) of the item
-   private final ArrayListMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
+   private final SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
    
    private final Class<T> rawType;
    private final Type[] actualTypeArguments; 
@@ -150,13 +153,13 @@
          throw new WeldException(ANNOTATION_MAP_NULL);
       }
       this.annotationMap = annotationMap;
-      this.metaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
+      this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), ArraySetSupplier.<Annotation>instance());
       for (Annotation annotation : annotationMap.values())
       {
          addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
          addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getTypeStore().get(annotation.annotationType()), false);
       }
-      this.metaAnnotationMap.trimToSize();
+      ArraySetSupplier.trimSetsToSize(metaAnnotationMap);
       
       if (declaredAnnotationMap == null)
       {
@@ -183,13 +186,14 @@
          throw new WeldException(ANNOTATION_MAP_NULL);
       }
       this.annotationMap = annotationMap;
-      this.metaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
+      this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), ArraySetSupplier.<Annotation>instance());
       for (Annotation annotation : annotationMap.values())
       {
          addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
          addMetaAnnotations(metaAnnotationMap, annotation, typeStore.get(annotation.annotationType()), false);
+         this.annotationMap.put(annotation.annotationType(), annotation);
       }
-      this.metaAnnotationMap.trimToSize();
+      ArraySetSupplier.trimSetsToSize(metaAnnotationMap);
 
       if (declaredAnnotationMap == null)
       {

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java	2010-05-28 12:31:09 UTC (rev 6357)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java	2010-05-28 18:10:01 UTC (rev 6358)
@@ -48,12 +48,15 @@
 import org.jboss.weld.introspector.WeldMethod;
 import org.jboss.weld.resources.ClassTransformer;
 import org.jboss.weld.util.Names;
+import org.jboss.weld.util.collections.ArraySetSupplier;
 import org.jboss.weld.util.collections.ImmutableArraySet;
 import org.jboss.weld.util.reflection.HierarchyDiscovery;
 import org.jboss.weld.util.reflection.Reflections;
 import org.jboss.weld.util.reflection.SecureReflections;
 
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
 
 /**
  * Represents an annotated class
@@ -120,7 +123,7 @@
 
    // The meta-annotation map (annotation type -> set of annotations containing
    // meta-annotation) of the item
-   private final ArrayListMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
+   private final SetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
 
    private final boolean discovered;
 
@@ -352,13 +355,14 @@
       this.declaredAnnotatedMethods.trimToSize();
       this.declaredMethodsByAnnotatedParameters.trimToSize();
 
-      this.declaredMetaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
+      this.declaredMetaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), ArraySetSupplier.<Annotation>instance());
       for (Annotation declaredAnnotation : declaredAnnotationMap.values())
       {
          addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, declaredAnnotation.annotationType().getAnnotations(), true);
          addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, classTransformer.getTypeStore().get(declaredAnnotation.annotationType()), true);
          this.declaredMetaAnnotationMap.put(declaredAnnotation.annotationType(), declaredAnnotation);
       }
+      ArraySetSupplier.trimSetsToSize(declaredMetaAnnotationMap);
    }
 
    @SuppressWarnings("unchecked")

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java	2010-05-28 12:31:09 UTC (rev 6357)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySet.java	2010-05-28 18:10:01 UTC (rev 6358)
@@ -146,6 +146,11 @@
       return elements.toArray(a);
    }
 
+   public void trimToSize()
+   {
+      elements.trimToSize();
+   }
+
    // Needed to provide set equals semantics
    @Override
    public boolean equals(Object obj)

Added: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySetSupplier.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySetSupplier.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySetSupplier.java	2010-05-28 18:10:01 UTC (rev 6358)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.util.collections;
+
+import java.util.Set;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.SetMultimap;
+
+/**
+ * Provides new instances of {@link ArraySet} to Google collections.
+ * 
+ * @author David Allen
+ *
+ */
+public class ArraySetSupplier<V> implements Supplier<Set<V>>
+{
+   private static final Supplier<?> INSTANCE = new ArraySetSupplier<Object>();
+   
+   private ArraySetSupplier() {}
+
+   @SuppressWarnings("unchecked")
+   public static <V> Supplier<Set<V>> instance()
+   {
+      return (Supplier<Set<V>>) INSTANCE;
+   }
+   
+   public Set<V> get()
+   {
+      return new ArraySet<V>();
+   }
+
+   /**
+    * Helper method which will trim each set in the multimap to its current size.
+    * @param <K> Key type
+    * @param <V> Value type
+    * @param multimap the set multimap using ArraySet<V> as the values
+    */
+   public static <K, V> void trimSetsToSize(SetMultimap<K, V> multimap)
+   {
+      for (K key : multimap.keySet())
+      {
+         if (multimap.get(key) instanceof ArraySet<?>)
+         {
+            ((ArraySet<?>)multimap.get(key)).trimToSize();
+         }
+      }
+   }
+}


Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ArraySetSupplier.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the weld-commits mailing list