[weld-commits] Weld SVN: r6230 - in core/trunk/impl/src/main/java/org/jboss/weld: introspector/jlr and 1 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Fri May 14 07:26:08 EDT 2010
Author: dallen6
Date: 2010-05-14 07:26:08 -0400 (Fri, 14 May 2010)
New Revision: 6230
Added:
core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
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/introspector/jlr/WeldMethodImpl.java
Log:
WELD-476 First phase complete; application now deploys on GF with default memory
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java 2010-05-13 16:10:10 UTC (rev 6229)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractBean.java 2010-05-14 11:26:08 UTC (rev 6230)
@@ -55,6 +55,7 @@
import org.jboss.weld.metadata.cache.MergedStereotypes;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.util.Beans;
+import org.jboss.weld.util.collections.ImmutableArraySet;
import org.jboss.weld.util.reflection.Reflections;
import org.slf4j.cal10n.LocLogger;
@@ -115,6 +116,7 @@
initName();
initScope();
checkDelegateInjectionPoints();
+ this.qualifiers = new ImmutableArraySet<Annotation>(qualifiers);
}
protected void initStereotypes()
@@ -168,15 +170,18 @@
{
if (getWeldAnnotated().isAnnotationPresent(Typed.class))
{
- this.types = getTypedTypes(Reflections.buildTypeMap(getWeldAnnotated().getTypeClosure()), getWeldAnnotated().getJavaClass(), getWeldAnnotated().getAnnotation(Typed.class));
+ this.types = new ImmutableArraySet<Type>(getTypedTypes(Reflections.buildTypeMap(getWeldAnnotated().getTypeClosure()), getWeldAnnotated().getJavaClass(), getWeldAnnotated().getAnnotation(Typed.class)));
}
else
{
- this.types = new HashSet<Type>(getWeldAnnotated().getTypeClosure());
if (getType().isInterface())
{
- this.types.add(Object.class);
+ this.types = new ImmutableArraySet<Type>(getWeldAnnotated().getTypeClosure(), Object.class);
}
+ else
+ {
+ this.types = new ImmutableArraySet<Type>(getWeldAnnotated().getTypeClosure());
+ }
}
}
@@ -201,7 +206,7 @@
protected void initQualifiers()
{
this.qualifiers = new HashSet<Annotation>();
- this.qualifiers.addAll(getWeldAnnotated().getMetaAnnotations(Qualifier.class));
+ qualifiers.addAll(getWeldAnnotated().getMetaAnnotations(Qualifier.class));
initDefaultQualifiers();
log.trace(QUALIFIERS_USED, qualifiers, this);
}
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-13 16:10:10 UTC (rev 6229)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java 2010-05-14 11:26:08 UTC (rev 6230)
@@ -23,7 +23,6 @@
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;
@@ -39,15 +38,11 @@
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.collections.Arrays2;
-import org.jboss.weld.util.collections.HashSetSupplier;
+import org.jboss.weld.util.collections.ImmutableArraySet;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
-import com.google.common.collect.ClassToInstanceMap;
-import com.google.common.collect.HashBiMap;
+import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.MutableClassToInstanceMap;
-import com.google.common.collect.SetMultimap;
/**
* Represents functionality common for all annotated items, mainly different
@@ -131,12 +126,12 @@
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 SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
+ private final ArrayListMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
private final Class<T> rawType;
private final Type[] actualTypeArguments;
private final Type type;
- private final Set<Type> typeClosure;
+ private final ImmutableArraySet<Type> typeClosure;
private final boolean proxyable;
/**
@@ -155,12 +150,13 @@
throw new WeldException(ANNOTATION_MAP_NULL);
}
this.annotationMap = annotationMap;
- this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
+ this.metaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
for (Annotation annotation : annotationMap.values())
{
addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getTypeStore().get(annotation.annotationType()), false);
}
+ this.metaAnnotationMap.trimToSize();
if (declaredAnnotationMap == null)
{
@@ -176,7 +172,7 @@
{
this.actualTypeArguments = new Type[0];
}
- this.typeClosure = typeClosure;
+ this.typeClosure = new ImmutableArraySet<Type>(typeClosure);
this.proxyable = Proxies.isTypesProxyable(typeClosure);
}
@@ -187,13 +183,14 @@
throw new WeldException(ANNOTATION_MAP_NULL);
}
this.annotationMap = annotationMap;
- this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
+ this.metaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
for (Annotation annotation : annotationMap.values())
{
addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
addMetaAnnotations(metaAnnotationMap, annotation, typeStore.get(annotation.annotationType()), false);
}
-
+ this.metaAnnotationMap.trimToSize();
+
if (declaredAnnotationMap == null)
{
throw new WeldException(DECLARED_ANNOTATION_MAP_NULL);
@@ -261,12 +258,12 @@
public Set<Annotation> getAnnotations()
{
- return Collections.unmodifiableSet(new HashSet<Annotation>(annotationMap.values()));
+ return new ImmutableArraySet<Annotation>(annotationMap.values());
}
public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
- return Collections.unmodifiableSet(metaAnnotationMap.get(metaAnnotationType));
+ return new ImmutableArraySet<Annotation>(metaAnnotationMap.get(metaAnnotationType));
}
@Deprecated
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-13 16:10:10 UTC (rev 6229)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java 2010-05-14 11:26:08 UTC (rev 6230)
@@ -48,6 +48,7 @@
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.Names;
+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;
@@ -673,25 +674,25 @@
@SuppressWarnings("unchecked")
public Set<AnnotatedConstructor<T>> getConstructors()
{
- return new HashSet(constructors);
+ return new ImmutableArraySet(constructors);
}
@SuppressWarnings("unchecked")
public Set<AnnotatedField<? super T>> getFields()
{
- return new HashSet(fields);
+ return new ImmutableArraySet(fields);
}
@SuppressWarnings("unchecked")
public Set<AnnotatedMethod<? super T>> getMethods()
{
- return new HashSet(methods);
+ return new ImmutableArraySet(methods);
}
@SuppressWarnings("unchecked")
public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
- return Collections.unmodifiableSet(new HashSet(declaredMetaAnnotationMap.get(metaAnnotationType)));
+ return new ImmutableArraySet(declaredMetaAnnotationMap.get(metaAnnotationType));
}
public boolean isDiscovered()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-05-13 16:10:10 UTC (rev 6229)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java 2010-05-14 11:26:08 UTC (rev 6230)
@@ -94,8 +94,8 @@
{
super(annotationMap, declaredAnnotationMap, classTransformer, method, rawType, type, typeClosure, declaringClass);
this.method = method;
- this.parameters = new ArrayList<WeldParameter<?, X>>();
- this.annotatedParameters = ArrayListMultimap.<Class<? extends Annotation>, WeldParameter<?, X>> create();
+ this.parameters = new ArrayList<WeldParameter<?, X>>(method.getParameterTypes().length);
+ this.annotatedParameters = ArrayListMultimap.<Class<? extends Annotation>, WeldParameter<?, X>> create(2, method.getParameterTypes().length);
if (annotatedMethod == null)
{
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java 2010-05-14 11:26:08 UTC (rev 6230)
@@ -0,0 +1,247 @@
+/*
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * <p>
+ * A {@link Set} which is immutable and backed by a simple array of elements.
+ * This provides all the behaviors of a set except for those methods which would
+ * otherwise modify the contents of the set.
+ * </p>
+ * <p>
+ * The primary use of this set is for those cases where small sets exists and
+ * will not be changed. The savings in memory is significant compared to hash
+ * sets which may contain many empty buckets.
+ * </p>
+ *
+ * @author David Allen
+ */
+public class ImmutableArraySet<E> implements Set<E>
+{
+
+ private Object[] elements;
+
+ public ImmutableArraySet(Collection<E> initialElements)
+ {
+ addElements(initialElements, initialElements.size());
+ }
+
+ public ImmutableArraySet(Collection<E> initialElements, E lastElement)
+ {
+ addElements(initialElements, initialElements.size() + 1);
+ this.elements[initialElements.size()] = lastElement;
+ }
+
+ protected void addElements(Collection<E> otherSet, int desiredSize)
+ {
+ boolean realSet = otherSet instanceof Set<?>;
+ Iterator<E> setIterator = otherSet.iterator();
+ int i = 0;
+ elements = new Object[desiredSize];
+ while (setIterator.hasNext())
+ {
+ E element = setIterator.next();
+ if (realSet || !contains(element))
+ {
+ elements[i++] = element;
+ }
+ }
+ // Compute the reduction due to duplicates, if any
+ int reduceBy = otherSet.size() - i - 1;
+ if (reduceBy > 0)
+ {
+ Object[] newElements = new Object[desiredSize - reduceBy];
+ System.arraycopy(elements, 0, newElements, 0, desiredSize - reduceBy);
+ elements = newElements;
+ }
+ }
+
+ public boolean add(E e)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean contains(Object o)
+ {
+ for (int i = 0; i < elements.length; i++)
+ {
+ if (elements[i] == null)
+ {
+ break; // End of valid values
+ }
+ if ((o == elements[i]) || (o.equals(elements[i])))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ for (Object object : c)
+ {
+ if (contains(object))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isEmpty()
+ {
+ return elements == null ? true : elements.length == 0;
+ }
+
+ class UnmodifiableIterator implements Iterator<E>
+ {
+ private int currentElement = 0;
+
+ public boolean hasNext()
+ {
+ return elements == null ? false : currentElement < elements.length;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ return (E) elements[currentElement++];
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ public Iterator<E> iterator()
+ {
+ return new UnmodifiableIterator();
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return elements == null ? 0 : elements.length;
+ }
+
+ public Object[] toArray()
+ {
+ return elements == null ? new Object[0] : elements.length == 0 ? elements : Arrays.copyOf(elements, elements.length);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T[] toArray(T[] a)
+ {
+ int elementQuantity = size();
+ if (a.length < elementQuantity)
+ {
+ return (T[]) Arrays.copyOf(elements, elements.length, a.getClass());
+ }
+ if (elementQuantity > 0)
+ {
+ System.arraycopy(elements, 0, a, 0, elementQuantity);
+ }
+ for (int i = elementQuantity; i < a.length; i++)
+ {
+ a[i] = null;
+ }
+ return a;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof Set<?>)
+ {
+ int elementQuantity = size();
+ Object[] otherArray = ((Set<?>) obj).toArray();
+ if (elementQuantity != otherArray.length)
+ {
+ return false;
+ }
+ boolean arraysEqual = true;
+ for (int i = 0; i < elementQuantity; i++)
+ {
+ boolean objFound = false;
+ for (int j = 0; j < otherArray.length; j++)
+ {
+ if (elements[i].equals(otherArray[j]))
+ {
+ objFound = true;
+ break;
+ }
+ }
+ if (!objFound)
+ {
+ arraysEqual = false;
+ break;
+ }
+ }
+ return arraysEqual;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Arrays.toString(elements);
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/collections/ImmutableArraySet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list