Implement lazy iterators/streams for ConsistentMap
Change-Id: Id643726441c99186667c104cfdd1dab95b06cf87
diff --git a/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java b/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
index 1f6579b1..304764e 100644
--- a/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
@@ -24,6 +24,8 @@
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
import com.google.common.util.concurrent.MoreExecutors;
@@ -34,7 +36,7 @@
* @param <K> type of key
* @param <V> type of value
*/
-public interface ConsistentMap<K, V> extends DistributedPrimitive {
+public interface ConsistentMap<K, V> extends DistributedPrimitive, Iterable<Map.Entry<K, Versioned<V>>> {
/**
* Returns the number of entries in the map.
@@ -283,6 +285,17 @@
boolean replace(K key, long oldVersion, V newValue);
/**
+ * Streams entries from the map.
+ * <p>
+ * This method is optimized for large maps.
+ *
+ * @return the map entry stream
+ */
+ default Stream<Entry<K, Versioned<V>>> stream() {
+ return StreamSupport.stream(spliterator(), false);
+ }
+
+ /**
* Registers the specified listener to be notified whenever the map is updated.
*
* @param listener listener to notify about map events