Skip to content

Commit 167c908

Browse files
DATAREDIS-756 - Polishing.
Visibility modifications. Original Pull Request: #303
1 parent 0394d5f commit 167c908

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,11 @@ public <S, T> MultiNodeResult<T> executeMultiKeyCommand(MultiKeyClusterCommandCa
288288
int index = 0;
289289
for (byte[] key : keys) {
290290
for (RedisClusterNode node : getClusterTopology().getKeyServingNodes(key)) {
291-
292-
if (nodeKeyMap.containsKey(node)) {
293-
nodeKeyMap.get(node).append(PositionalKey.of(key, index++));
294-
} else {
295-
nodeKeyMap.put(node, PositionalKeys.of(PositionalKey.of(key, index++)));
296-
}
291+
nodeKeyMap.computeIfAbsent(node, val -> PositionalKeys.empty()).append(PositionalKey.of(key, index++));
297292
}
298293
}
299294

300295
Map<NodeExecution, Future<NodeResult<T>>> futures = new LinkedHashMap<>();
301-
302296
for (Entry<RedisClusterNode, PositionalKeys> entry : nodeKeyMap.entrySet()) {
303297

304298
if (entry.getKey().isMaster()) {
@@ -604,7 +598,7 @@ private List<T> toList(Collection<NodeResult<T>> source) {
604598
*/
605599
private static class ResultByReferenceKeyPositionComparator implements Comparator<NodeResult<?>> {
606600

607-
List<ByteArrayWrapper> reference;
601+
private final List<ByteArrayWrapper> reference;
608602

609603
ResultByReferenceKeyPositionComparator(byte[]... keys) {
610604
reference = new ArrayList<>(new ByteArraySet(Arrays.asList(keys)));
@@ -620,11 +614,12 @@ public int compare(NodeResult<?> o1, NodeResult<?> o2) {
620614
* {@link Comparator} for sorting {@link PositionalKey} by external {@link PositionalKeys}.
621615
*
622616
* @author Mark Paluch
617+
* @author Christoph Strobl
623618
* @since 2.0.3
624619
*/
625620
private static class ResultByKeyPositionComparator implements Comparator<PositionalKey> {
626621

627-
PositionalKeys reference;
622+
private final PositionalKeys reference;
628623

629624
ResultByKeyPositionComparator(byte[]... keys) {
630625
reference = PositionalKeys.of(keys);
@@ -641,24 +636,25 @@ public int compare(PositionalKey o1, PositionalKey o2) {
641636
* Value object representing a Redis key at a particular command position.
642637
*
643638
* @author Mark Paluch
639+
* @author Christoph Strobl
644640
* @since 2.0.3
645641
*/
646642
@Getter
647643
@EqualsAndHashCode
648644
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
649-
static class PositionalKey {
645+
private static class PositionalKey {
650646

651647
private final ByteArrayWrapper key;
652648
private final int position;
653649

654-
public static PositionalKey of(byte[] key, int index) {
650+
static PositionalKey of(byte[] key, int index) {
655651
return new PositionalKey(new ByteArrayWrapper(key), index);
656652
}
657653

658654
/**
659655
* @return binary key.
660656
*/
661-
public byte[] getBytes() {
657+
byte[] getBytes() {
662658
return key.getArray();
663659
}
664660
}
@@ -667,24 +663,25 @@ public byte[] getBytes() {
667663
* Mutable data structure to represent multiple {@link PositionalKey}s.
668664
*
669665
* @author Mark Paluch
666+
* @author Christoph Strobl
670667
* @since 2.0.3
671668
*/
672669
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
673-
static class PositionalKeys implements Iterable<PositionalKey> {
670+
private static class PositionalKeys implements Iterable<PositionalKey> {
674671

675672
private final List<PositionalKey> keys;
676673

677674
/**
678675
* Create an empty {@link PositionalKeys}.
679676
*/
680-
public static PositionalKeys empty() {
677+
static PositionalKeys empty() {
681678
return new PositionalKeys(new ArrayList<>());
682679
}
683680

684681
/**
685682
* Create an {@link PositionalKeys} from {@code keys}.
686683
*/
687-
public static PositionalKeys of(byte[]... keys) {
684+
static PositionalKeys of(byte[]... keys) {
688685

689686
List<PositionalKey> result = new ArrayList<>(keys.length);
690687

@@ -698,7 +695,7 @@ public static PositionalKeys of(byte[]... keys) {
698695
/**
699696
* Create an {@link PositionalKeys} from {@link PositionalKey}s.
700697
*/
701-
public static PositionalKeys of(PositionalKey... keys) {
698+
static PositionalKeys of(PositionalKey... keys) {
702699

703700
PositionalKeys result = PositionalKeys.empty();
704701
result.append(keys);
@@ -709,14 +706,14 @@ public static PositionalKeys of(PositionalKey... keys) {
709706
/**
710707
* Append {@link PositionalKey}s to this object.
711708
*/
712-
public void append(PositionalKey... keys) {
709+
void append(PositionalKey... keys) {
713710
this.keys.addAll(Arrays.asList(keys));
714711
}
715712

716713
/**
717714
* @return index of the {@link PositionalKey}.
718715
*/
719-
public int indexOf(PositionalKey key) {
716+
int indexOf(PositionalKey key) {
720717
return keys.indexOf(key);
721718
}
722719

0 commit comments

Comments
 (0)