ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1685889 - /webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java
Date Tue, 16 Jun 2015 18:44:15 GMT
Author: veithen
Date: Tue Jun 16 18:44:15 2015
New Revision: 1685889

URL: http://svn.apache.org/r1685889
Log:
Enable the remove operation on iterators returned by OMElement#getAllDeclaredNamespaces().

Modified:
    webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java

Modified: webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java?rev=1685889&r1=1685888&r2=1685889&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java
(original)
+++ webservices/axiom/branches/attrs-aspects/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractAttributeIterator.java
Tue Jun 16 18:44:15 2015
@@ -25,8 +25,9 @@ abstract class AbstractAttributeIterator
     private final CoreElement element;
     private final Class<T> type;
     private final Mapper<T,S> mapper;
-    private CoreAttribute attribute;
-    private boolean hasNext;
+    private CoreAttribute currentAttribute;
+    private CoreAttribute nextAttribute;
+    private boolean hasNextCalled;
     
     AbstractAttributeIterator(CoreElement element, Class<T> type, Mapper<T,S>
mapper) {
         this.element = element;
@@ -37,8 +38,8 @@ abstract class AbstractAttributeIterator
     protected abstract boolean matches(T attribute);
 
     public final boolean hasNext() {
-        if (!hasNext) {
-            CoreAttribute attribute = this.attribute;
+        if (!hasNextCalled) {
+            CoreAttribute attribute = currentAttribute;
             do {
                 if (attribute == null) {
                     attribute = element.coreGetFirstAttribute();
@@ -46,15 +47,18 @@ abstract class AbstractAttributeIterator
                     attribute = attribute.coreGetNextAttribute();
                 }
             } while (attribute != null && (!type.isInstance(attribute) || !matches(type.cast(attribute))));
-            this.attribute = attribute;
-            hasNext = true;
+            nextAttribute = attribute;
+            hasNextCalled = true;
         }
-        return attribute != null;
+        return nextAttribute != null;
     }
 
     public final S next() {
         if (hasNext()) {
-            hasNext = false;
+            CoreAttribute attribute = nextAttribute;
+            currentAttribute = attribute;
+            nextAttribute = null;
+            hasNextCalled = false;
             return mapper.map(type.cast(attribute));
         } else {
             throw new NoSuchElementException();
@@ -62,6 +66,11 @@ abstract class AbstractAttributeIterator
     }
 
     public final void remove() {
-        throw new UnsupportedOperationException();
+        if (currentAttribute == null) {
+            throw new IllegalStateException();
+        } else {
+            currentAttribute.coreRemove();
+            currentAttribute = null;
+        }
     }
 }



Mime
View raw message