diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 2620b1f07..5435a888b 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -33,7 +33,7 @@ import java.util.function.Predicate; * This interface defines common {@link ChronicleMap} and {@link ChronicleSet}, related to off-heap * memory management and file-mapping. Not usable by itself. */ -public interface ChronicleHash, SC extends HashSegmentContext, +public interface ChronicleHash, SC extends HashSegmentContext, EQC extends ExternalHashQueryContext> extends Closeable { /** * Returns the file this hash container mapped to, i. e. when it is created by @@ -99,7 +99,7 @@ public interface ChronicleHash, SC extends HashSegment * @return {@code true} if the predicate returned {@code true} for all entries of * the {@code ChronicleHash}, {@code false} if it returned {@code false} for the entry */ - boolean forEachEntryWhile(Predicate predicate); + boolean forEachEntryWhile(Predicate predicate); /** * Performs the given action for each entry in this {@code ChronicleHash} until all entries have @@ -112,7 +112,7 @@ public interface ChronicleHash, SC extends HashSegment * * @param action the action to be performed for each entry */ - void forEachEntry(Consumer action); // TODO add substitution and deprecate this + void forEachEntry(Consumer action); /** * Releases the off-heap memory, used by this hash container and resources, used by replication, diff --git a/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java b/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java index 2773df55d..5670014de 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java +++ b/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java @@ -23,11 +23,40 @@ import net.openhft.chronicle.core.io.Closeable; import java.util.function.Consumer; import java.util.function.Predicate; +/** + * Context of {@link ChronicleHash}'s segment. + * + * @param the key type of accessed {@code ChronicleHash} + * @param the entry type + * @see ChronicleHash#segmentContext(int) + */ public interface HashSegmentContext> extends HashContext, Closeable { + /** + * Performs the given action for each entry in this segment until all entries have + * been processed or the action throws an {@code Exception}. Exceptions thrown by the action are + * relayed to the caller. + * + * @param action the action to be performed for each entry in this segment + */ void forEachSegmentEntry(Consumer action); + /** + * Checks the given predicate on each entry in this segment until all entries + * have been processed or the predicate returns {@code false} for some entry, or throws + * an {@code Exception}. Exceptions thrown by the predicate are relayed to the caller. + * + *

If this segment is empty (i. e. {@link #size()} call returns 0), this method returns + * {@code true} immediately. + * + * @param predicate the predicate to be checked for each entry in this segment + * @return {@code true} if the predicate returned {@code true} for all checked entries, + * {@code false} if it returned {@code false} for some entry + */ boolean forEachSegmentEntryWhile(Predicate predicate); + /** + * Returns the number of entries in this segment. + */ long size(); } diff --git a/src/main/java/net/openhft/chronicle/map/MapSegmentContext.java b/src/main/java/net/openhft/chronicle/map/MapSegmentContext.java index 7573ca786..39778aef5 100644 --- a/src/main/java/net/openhft/chronicle/map/MapSegmentContext.java +++ b/src/main/java/net/openhft/chronicle/map/MapSegmentContext.java @@ -20,6 +20,14 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.HashSegmentContext; +/** + * Context of {@link ChronicleMap}'s segment. + * + * @param the key type of accessed {@code ChronicleMap} + * @param the value type of accessed {@code ChronicleMap} + * @param the return type of {@link MapEntryOperations} specified for the queried map + * @see ChronicleMap#segmentContext(int) + */ public interface MapSegmentContext extends HashSegmentContext>, MapContext { } diff --git a/src/main/java/net/openhft/chronicle/set/SetSegmentContext.java b/src/main/java/net/openhft/chronicle/set/SetSegmentContext.java index 7f3264b70..95fd7aed3 100644 --- a/src/main/java/net/openhft/chronicle/set/SetSegmentContext.java +++ b/src/main/java/net/openhft/chronicle/set/SetSegmentContext.java @@ -20,6 +20,13 @@ package net.openhft.chronicle.set; import net.openhft.chronicle.hash.HashSegmentContext; +/** + * Context of {@link ChronicleSet}'s segment. + * + * @param the key type of accessed {@code ChronicleSet} + * @param the return type of {@link SetEntryOperations} specified for the queried set + * @see ChronicleSet#segmentContext(int) + */ public interface SetSegmentContext extends HashSegmentContext>, SetContext { }