[java-opensaml COMMIT] in /trunk/opensaml-core/src: main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList...
noreply at shibboleth.net
noreply at shibboleth.net
Fri Jan 11 22:18:34 EST 2013
Author: scantor
Date: Fri Jan 11 22:18:33 2013
New Revision: 3142
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3142&view=rev
Log:
Update to rev. 743 to port up bug fixes JXT-82 and JXT-83.
Modified:
trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java
trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectChildrenList.java
trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenListTest.java
Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java?rev=3142&r1=3141&r2=3142&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java Fri Jan 11 22:18:33 2013
@@ -22,13 +22,19 @@
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import javax.xml.namespace.QName;
import net.shibboleth.utilities.java.support.collection.LazyList;
import net.shibboleth.utilities.java.support.collection.LazyMap;
+import net.shibboleth.utilities.java.support.logic.Constraint;
import org.opensaml.core.xml.XMLObject;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
/**
* A list which indexes XMLObjects by their schema type and element QName for quick retrival based on those items.
@@ -39,14 +45,14 @@
public class IndexedXMLObjectChildrenList<ElementType extends XMLObject> extends XMLObjectChildrenList<ElementType> {
/** Index of objects by type and name. */
- private Map<QName, List<ElementType>> objectIndex;
+ private final Map<QName, List<ElementType>> objectIndex;
/**
* Constructor.
*
* @param parent the parent of the {@link XMLObject}s added to the list
*/
- public IndexedXMLObjectChildrenList(XMLObject parent) {
+ public IndexedXMLObjectChildrenList(@Nonnull final XMLObject parent) {
super(parent);
objectIndex = new LazyMap<QName, List<ElementType>>();
}
@@ -57,20 +63,20 @@
* @param parent the parent of all elements
* @param col collection to add to this list
*/
- public IndexedXMLObjectChildrenList(XMLObject parent, Collection<ElementType> col) {
+ public IndexedXMLObjectChildrenList(@Nonnull final XMLObject parent, @Nonnull final Collection<ElementType> col) {
super(parent);
+ Constraint.isNotNull(col, "Initial collection cannot be null");
+
objectIndex = new LazyMap<QName, List<ElementType>>();
- addAll(col);
- }
-
- /**
- * Inserts the specified element at the specified position in this list. Shifts the element currently at that
- * position (if any) and any subsequent elements to the right (adds one to their indices).
- *
- * @param index index of element to add
- * @param element element to be stored at the specified position
- */
- public void add(int index, ElementType element) {
+
+ // This does call our add, which handles the null case properly, but
+ // I didn't want to depend on that implementation. Keeping the fail silently
+ // behavior means not using an Immutable collection copy.
+ addAll(Collections2.filter(col, Predicates.notNull()));
+ }
+
+ /** {@inheritDoc} */
+ public void add(int index, @Nullable final ElementType element) {
super.add(index, element);
indexElement(element);
}
@@ -82,22 +88,36 @@
}
/**
- * Retrieves all the SAMLObjects that have given schema type or element name.
+ * Retrieves all the SAMLObjects that have given schema type or element name, or a
+ * null if no such objects exist.
*
* @param typeOrName the schema type or element name
*
* @return list of SAMLObjects that have given schema type or element name or null
*/
- public List<ElementType> get(QName typeOrName) {
+ @Nonnull public List<ElementType> get(@Nonnull final QName typeOrName) {
+ checkAndCreateIndex(typeOrName);
return objectIndex.get(typeOrName);
}
/**
- * Indexes the given SAMLObject by type and element name.
+ * Check for the existence of an index for the specified QName and create it
+ * if it doesn't exist.
+ *
+ * @param index the index to check
+ */
+ protected void checkAndCreateIndex(QName index) {
+ if (!objectIndex.containsKey(index)) {
+ objectIndex.put(index, new LazyList<ElementType>());
+ }
+ }
+
+ /**
+ * Indexes the given SAMLObject by type and element name. A null input is ignored.
*
* @param element the SAMLObject to index
[... 481 lines stripped ...]
More information about the commits
mailing list