Separate out ConstantArrayCollection iterator 84/78584/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 25 Nov 2018 16:59:50 +0000 (17:59 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 10 Dec 2018 10:41:27 +0000 (11:41 +0100)
This splits it out into its own static class.

Change-Id: I94a86c65eefdba79db2f5ec3a01b13dbad0b41b0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 7ecb52d8ddaab4e993126edb2c448b41d60a28d5)

common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java

index 1dcfaa2a568b9df60ce4cd07ab966fb8c71428ec..ee683679d0cdce5a822cc84c171c368b19d29356 100644 (file)
@@ -57,22 +57,7 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
     @Nonnull
     @Override
     public Iterator<E> iterator() {
-        return new UnmodifiableIterator<E>() {
-            private int offset = 0;
-
-            @Override
-            public boolean hasNext() {
-                return offset < array.length;
-            }
-
-            @Override
-            public E next() {
-                if (offset >= array.length) {
-                    throw new NoSuchElementException();
-                }
-                return array[offset++];
-            }
-        };
+        return new Itr<>(array);
     }
 
     @Nonnull
@@ -177,4 +162,26 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
         }
         return sb.append(String.valueOf(array[offset])).append(']').toString();
     }
+
+    private static final class Itr<E> extends UnmodifiableIterator<E> {
+        private final E[] array;
+        private int offset = 0;
+
+        Itr(final E[] array) {
+            this.array = array;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return offset < array.length;
+        }
+
+        @Override
+        public E next() {
+            if (offset >= array.length) {
+                throw new NoSuchElementException();
+            }
+            return array[offset++];
+        }
+    }
 }