[java-xmltooling COMMIT] in /branches/REL_1: doc/RELEASE-NOTES.txt src/main/java/org/opensaml/xml/util/IndexedXMLObje...
noreply at shibboleth.net
noreply at shibboleth.net
Sat Oct 22 19:54:14 BST 2011
Author: putmanb
Date: Sat Oct 22 19:54:13 2011
New Revision: 743
URL: http://svn.shibboleth.net/view/java-xmltooling?rev=743&view=rev
Log:
JXT-82: ListView's clear empties the whole backingList instead of only the entries it's responsible for
Modified:
branches/REL_1/doc/RELEASE-NOTES.txt
branches/REL_1/src/main/java/org/opensaml/xml/util/IndexedXMLObjectChildrenList.java
branches/REL_1/src/test/java/org/opensaml/xml/util/IndexedXMLObjectChildrenListTest.java
Modified: branches/REL_1/doc/RELEASE-NOTES.txt
URL: http://svn.shibboleth.net/view/java-xmltooling/branches/REL_1/doc/RELEASE-NOTES.txt?rev=743&r1=742&r2=743&view=diff
==============================================================================
--- branches/REL_1/doc/RELEASE-NOTES.txt (original)
+++ branches/REL_1/doc/RELEASE-NOTES.txt Sat Oct 22 19:54:13 2011
@@ -3,6 +3,7 @@
[JXT-78] - XSBoolean does not extend XMLObject
[JXT-79] - Disable RSA v1.5 key transport in favor of RSA-OAEP for all data encryption key types
[JXT-80] - Update 3rd party runtime library dependencies
+[JXT-82] - ListView's clear empties the whole backingList instead of only the entries it's responsible for
[JXT-83] - IndexedXMLObjectChildrenList ListView indexOf and lastIndexOf methods operate on the wrong data
Changes in Release 1.3.2
Modified: branches/REL_1/src/main/java/org/opensaml/xml/util/IndexedXMLObjectChildrenList.java
URL: http://svn.shibboleth.net/view/java-xmltooling/branches/REL_1/src/main/java/org/opensaml/xml/util/IndexedXMLObjectChildrenList.java?rev=743&r1=742&r2=743&view=diff
==============================================================================
--- branches/REL_1/src/main/java/org/opensaml/xml/util/IndexedXMLObjectChildrenList.java (original)
+++ branches/REL_1/src/main/java/org/opensaml/xml/util/IndexedXMLObjectChildrenList.java Sat Oct 22 19:54:13 2011
@@ -84,10 +84,24 @@
*
* @param typeOrName the schema type or element name
*
- * @return list of SAMLObjects that have given schema type or element name or null
+ * @return list of SAMLObjects that have given schema type or element name, which may be empty.
+ * Will not be null.
*/
public List<ElementType> get(QName typeOrName) {
+ checkAndCreateIndex(typeOrName);
return objectIndex.get(typeOrName);
+ }
+
+ /**
+ * 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>());
+ }
}
/**
@@ -115,12 +129,7 @@
* @param element the element to be indexed
*/
protected void indexElement(QName index, ElementType element) {
- List<ElementType> objects = objectIndex.get(index);
- if (objects == null) {
- objects = new LazyList<ElementType>();
- objectIndex.put(index, objects);
- }
-
+ List<ElementType> objects = get(index);
objects.add(element);
}
@@ -183,14 +192,8 @@
* @param element the element to be removed from that index
*/
protected void removeElementFromIndex(QName index, ElementType element) {
- List<ElementType> objects = objectIndex.get(index);
- if (objects != null) {
- objects.remove(element);
- }
-
- if (objects.size() == 0) {
- objectIndex.remove(index);
- }
+ List<ElementType> objects = get(index);
+ objects.remove(element);
}
/**
@@ -220,10 +223,7 @@
* @return a view of this list that contains only the elements stored under the given index
*/
public List<? extends ElementType> subList(QName index) {
- if (!objectIndex.containsKey(index)) {
- objectIndex.put(index, new LazyList<ElementType>());
- }
-
+ checkAndCreateIndex(index);
return new ListView<ElementType>(this, index);
}
}
@@ -258,6 +258,7 @@
indexList = backingList.get(index);
}
+ /** {@inheritDoc} */
public boolean add(ElementType o) {
boolean result = backingList.add(o);
indexList = backingList.get(index);
@@ -283,7 +284,10 @@
/** {@inheritDoc} */
public void clear() {
- backingList.clear();
+ // Create a copy of the current list to avoid a potential concurrent modification error.
+ LazyList<ElementType> copy = new LazyList<ElementType>();
+ copy.addAll(indexList);
+ backingList.removeAll(copy);
indexList = backingList.get(index);
}
@@ -364,6 +368,7 @@
return indexList.toArray();
}
+ /** {@inheritDoc} */
public <T extends Object> T[] toArray(T[] a) {
return indexList.toArray(a);
}
Modified: branches/REL_1/src/test/java/org/opensaml/xml/util/IndexedXMLObjectChildrenListTest.java
[... 56 lines stripped ...]
More information about the commits
mailing list