Skip to content

Commit

Permalink
Polishing #638
Browse files Browse the repository at this point in the history
Improve javadoc.
  • Loading branch information
mp911de committed Oct 29, 2017
1 parent aa65771 commit 51a14a8
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/main/java/io/lettuce/core/ScanIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@
* {@link ScanIterator} uses synchronous command interfaces to scan over keys ({@code SCAN}), sets ({@code SSCAN}), sorted sets
* ({@code ZSCAN}), and hashes ({@code HSCAN}). A {@link ScanIterator} is stateful and not thread-safe. Instances can be used
* only once to iterate over results.
* <p>
* Use {@link ScanArgs#limit(long)} to set the batch size.
* <p>
* Data structure scanning is progressive and stateful and demand-aware. It supports full iterations (until all received cursors
* are exhausted) and premature termination. Subsequent scan commands to fetch the cursor data get only issued if the caller
* signals demand by consuming the {@link ScanIterator}.
*
* @param <T> Element type
* @author Mark Paluch
* @since 4.4
*/
public abstract class ScanIterator<T> implements Iterator<T> {

private ScanIterator() {
}

/**
* Sequentially iterate over keys in the keyspace. This method uses {@code SCAN} to perform an iterative scan.
*
Expand Down Expand Up @@ -89,8 +98,8 @@ private KeyScanCursor<K> getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(commands::scan).orElseGet(commands::scan);
}

return scanArgs.map((scanArgs) -> commands.scan(scanCursor, scanArgs))
.orElseGet(() -> commands.scan(scanCursor));
return scanArgs.map((scanArgs) -> commands.scan(scanCursor, scanArgs)).orElseGet(
() -> commands.scan(scanCursor));
}
};
}
Expand All @@ -100,6 +109,7 @@ private KeyScanCursor<K> getNextScanCursor(ScanCursor scanCursor) {
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the hash to scan.
* @param <K> Key type.
* @param <V> Value type.
* @return a new {@link ScanIterator}.
Expand All @@ -113,6 +123,7 @@ public static <K, V> ScanIterator<KeyValue<K, V>> hscan(RedisHashCommands<K, V>
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the hash to scan.
* @param scanArgs the scan arguments, must not be {@literal null}.
* @param <K> Key type.
* @param <V> Value type.
Expand Down Expand Up @@ -147,8 +158,8 @@ private MapScanCursor<K, V> getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.hscan(key, scanArgs)).orElseGet(() -> commands.hscan(key));
}

return scanArgs.map((scanArgs) -> commands.hscan(key, scanCursor, scanArgs))
.orElseGet(() -> commands.hscan(key, scanCursor));
return scanArgs.map((scanArgs) -> commands.hscan(key, scanCursor, scanArgs)).orElseGet(
() -> commands.hscan(key, scanCursor));
}
};
}
Expand All @@ -158,6 +169,7 @@ private MapScanCursor<K, V> getNextScanCursor(ScanCursor scanCursor) {
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the set to scan.
* @param <K> Key type.
* @param <V> Value type.
* @return a new {@link ScanIterator}.
Expand All @@ -171,6 +183,7 @@ public static <K, V> ScanIterator<V> sscan(RedisSetCommands<K, V> commands, K ke
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the set to scan.
* @param scanArgs the scan arguments, must not be {@literal null}.
* @param <K> Key type.
* @param <V> Value type.
Expand Down Expand Up @@ -204,8 +217,8 @@ private ValueScanCursor<V> getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.sscan(key, scanArgs)).orElseGet(() -> commands.sscan(key));
}

return scanArgs.map((scanArgs) -> commands.sscan(key, scanCursor, scanArgs))
.orElseGet(() -> commands.sscan(key, scanCursor));
return scanArgs.map((scanArgs) -> commands.sscan(key, scanCursor, scanArgs)).orElseGet(
() -> commands.sscan(key, scanCursor));
}
};
}
Expand All @@ -215,6 +228,7 @@ private ValueScanCursor<V> getNextScanCursor(ScanCursor scanCursor) {
* perform an iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the sorted set to scan.
* @param <K> Key type.
* @param <V> Value type.
* @return a new {@link ScanIterator}.
Expand All @@ -228,6 +242,7 @@ public static <K, V> ScanIterator<ScoredValue<V>> zscan(RedisSortedSetCommands<K
* perform an iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
* @param key the sorted set to scan.
* @param scanArgs the scan arguments, must not be {@literal null}.
* @param <K> Key type.
* @param <V> Value type.
Expand Down Expand Up @@ -262,8 +277,8 @@ private ScoredValueScanCursor<V> getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.zscan(key, scanArgs)).orElseGet(() -> commands.zscan(key));
}

return scanArgs.map((scanArgs) -> commands.zscan(key, scanCursor, scanArgs))
.orElseGet(() -> commands.zscan(key, scanCursor));
return scanArgs.map((scanArgs) -> commands.zscan(key, scanCursor, scanArgs)).orElseGet(
() -> commands.zscan(key, scanCursor));
}
};
}
Expand Down

0 comments on commit 51a14a8

Please sign in to comment.