You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/05/30 18:16:41 UTC

svn commit: r1796910 - in /pivot/trunk/core: src/org/apache/pivot/util/EmptyIterator.java test/org/apache/pivot/util/test/EmptyIteratorTest.java

Author: rwhitcomb
Date: Tue May 30 18:16:41 2017
New Revision: 1796910

URL: http://svn.apache.org/viewvc?rev=1796910&view=rev
Log:
PIVOT-999:  Take advantage of default interface methods in Java 8:
Remove the "remove()" method in EmptyIterator because it is
already implemented by the default.

Add some more explanatory Javadoc also.

Add a test class for EmptyIterator to make sure this all works.

Added:
    pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java
Modified:
    pivot/trunk/core/src/org/apache/pivot/util/EmptyIterator.java

Modified: pivot/trunk/core/src/org/apache/pivot/util/EmptyIterator.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/EmptyIterator.java?rev=1796910&r1=1796909&r2=1796910&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/EmptyIterator.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/EmptyIterator.java Tue May 30 18:16:41 2017
@@ -20,7 +20,13 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
- * A no-op iterator.
+ * A no-op iterator, for which {@link #hasNext} always returns <tt>false</tt>
+ * and {@link #next} throws {@link NoSuchElementException}.
+ * <p> This is used (for instance) for {@link org.apache.pivot.collections.HashMap}
+ * when a hash bucket list is empty, so that iteration through the bucket list
+ * doesn't have to be special-cased.
+ * <p>Note: for Java 8 we have taken out the implementation of the <tt>remove()</tt>
+ * method because the interface now implements it as we need it as a default method.
  */
 public class EmptyIterator<T> implements Iterator<T> {
     @Override
@@ -33,8 +39,4 @@ public class EmptyIterator<T> implements
         throw new NoSuchElementException();
     }
 
-    @Override
-    public void remove() {
-        throw new UnsupportedOperationException();
-    }
 }

Added: pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java?rev=1796910&view=auto
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java (added)
+++ pivot/trunk/core/test/org/apache/pivot/util/test/EmptyIteratorTest.java Tue May 30 18:16:41 2017
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.apache.pivot.util.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.junit.Test;
+
+import org.apache.pivot.util.EmptyIterator;
+
+
+public class EmptyIteratorTest {
+    @Test
+    public void basicTest() {
+        Iterator<String> iter = new EmptyIterator<String>();
+        assertTrue(!iter.hasNext());
+        try {
+            iter.next();
+            assertTrue(false);
+        } catch (NoSuchElementException nsee) {
+            assertTrue(true);
+        }
+    }
+
+    @Test
+    public void removeTest() {
+        Iterator<String> iter = new EmptyIterator<String>();
+        try {
+            iter.remove();
+            assertTrue(false);
+        } catch (UnsupportedOperationException uoe) {
+            assertTrue(true);
+        }
+    }
+}