diff --git a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java index b0b4213e1..dad365456 100644 --- a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java +++ b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java @@ -612,7 +612,7 @@ public class ClusterCommandExecutor implements DisposableBean { */ private static class ResultByReferenceKeyPositionComparator implements Comparator> { - List reference; + private final List reference; ResultByReferenceKeyPositionComparator(byte[]... keys) { reference = new ArrayList(new ByteArraySet(Arrays.asList(keys))); @@ -632,7 +632,7 @@ public class ClusterCommandExecutor implements DisposableBean { */ private static class ResultByKeyPositionComparator implements Comparator { - PositionalKeys reference; + private final PositionalKeys reference; ResultByKeyPositionComparator(byte[]... keys) { reference = PositionalKeys.of(keys); @@ -649,6 +649,7 @@ public class ClusterCommandExecutor implements DisposableBean { * Value object representing a Redis key at a particular command position. * * @author Mark Paluch + * @author Christoph Strobl * @since 2.0.3 */ @@ -657,40 +658,43 @@ public class ClusterCommandExecutor implements DisposableBean { private final ByteArrayWrapper key; private final int position; - public PositionalKey(ByteArrayWrapper key, int position) { + PositionalKey(ByteArrayWrapper key, int position) { this.key = key; this.position = position; } - public static PositionalKey of(byte[] key, int index) { + static PositionalKey of(byte[] key, int index) { return new PositionalKey(new ByteArrayWrapper(key), index); } /** * @return binary key. */ - public byte[] getBytes() { + byte[] getBytes() { return key.getArray(); } @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; + } PositionalKey that = (PositionalKey) o; - if (position != that.position) + if (!ObjectUtils.nullSafeEquals(this.position, that.position)) { return false; - return key.equals(that.key); + } + return ObjectUtils.nullSafeEquals(this.key, that.key); } @Override public int hashCode() { - int result = key.hashCode(); - result = 31 * result + position; + int result = ObjectUtils.nullSafeHashCode(key); + result = 31 * result + ObjectUtils.nullSafeHashCode(position); return result; } } @@ -705,21 +709,21 @@ public class ClusterCommandExecutor implements DisposableBean { private final List keys; - public PositionalKeys(List keys) { + PositionalKeys(List keys) { this.keys = keys; } /** * Create an empty {@link PositionalKeys}. */ - public static PositionalKeys empty() { + static PositionalKeys empty() { return new PositionalKeys(new ArrayList()); } /** * Create an {@link PositionalKeys} from {@code keys}. */ - public static PositionalKeys of(byte[]... keys) { + static PositionalKeys of(byte[]... keys) { List result = new ArrayList(keys.length); @@ -733,7 +737,7 @@ public class ClusterCommandExecutor implements DisposableBean { /** * Create an {@link PositionalKeys} from {@link PositionalKey}s. */ - public static PositionalKeys of(PositionalKey... keys) { + static PositionalKeys of(PositionalKey... keys) { PositionalKeys result = PositionalKeys.empty(); result.append(keys); @@ -744,14 +748,14 @@ public class ClusterCommandExecutor implements DisposableBean { /** * Append {@link PositionalKey}s to this object. */ - public void append(PositionalKey... keys) { + void append(PositionalKey... keys) { this.keys.addAll(Arrays.asList(keys)); } /** * @return index of the {@link PositionalKey}. */ - public int indexOf(PositionalKey key) { + int indexOf(PositionalKey key) { return keys.indexOf(key); }