diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 9e653321c8a..46d5b87af55 100644 --- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java @@ -1493,10 +1493,10 @@ public class IndexSchema { return Stream.of(Handler.values()) .filter(it -> name == null || it.nameLower.equals(name)) .map(it -> new Pair<>(it.realName, it.fun.apply(this))) - .filter(it->it.getValue() != null) + .filter(it->it.second() != null) .collect(Collectors.toMap( - Pair::getKey, - Pair::getValue, + Pair::first, + Pair::second, (v1, v2) -> v2, LinkedHashMap::new)); } diff --git a/solr/core/src/java/org/apache/solr/util/TestInjection.java b/solr/core/src/java/org/apache/solr/util/TestInjection.java index 2be1df6e732..cc3f85d4472 100644 --- a/solr/core/src/java/org/apache/solr/util/TestInjection.java +++ b/solr/core/src/java/org/apache/solr/util/TestInjection.java @@ -101,8 +101,8 @@ public class TestInjection { public static boolean injectRandomDelayInCoreCreation() { if (randomDelayInCoreCreation != null) { Pair pair = parseValue(randomDelayInCoreCreation); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { int delay = RANDOM.nextInt(randomDelayMaxInCoreCreationInSec); log.info("Inject random core creation delay of {}s", delay); @@ -119,8 +119,8 @@ public class TestInjection { public static boolean injectNonGracefullClose(CoreContainer cc) { if (cc.isShutDown() && nonGracefullClose != null) { Pair pair = parseValue(nonGracefullClose); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { if (RANDOM.nextBoolean()) { throw new TestShutdownFailError("Test exception for non graceful close"); @@ -157,8 +157,8 @@ public class TestInjection { public static boolean injectFailReplicaRequests() { if (failReplicaRequests != null) { Pair pair = parseValue(failReplicaRequests); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { throw new SolrException(ErrorCode.SERVER_ERROR, "Random test update fail"); } @@ -170,8 +170,8 @@ public class TestInjection { public static boolean injectFailUpdateRequests() { if (failUpdateRequests != null) { Pair pair = parseValue(failUpdateRequests); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { throw new SolrException(ErrorCode.SERVER_ERROR, "Random test update fail"); } @@ -183,8 +183,8 @@ public class TestInjection { public static boolean injectNonExistentCoreExceptionAfterUnload(String cname) { if (nonExistentCoreExceptionAfterUnload != null) { Pair pair = parseValue(nonExistentCoreExceptionAfterUnload); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { throw new NonExistentCoreException("Core not found to unload: " + cname); } @@ -196,8 +196,8 @@ public class TestInjection { public static boolean injectUpdateLogReplayRandomPause() { if (updateLogReplayRandomPause != null) { Pair pair = parseValue(updateLogReplayRandomPause); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { long rndTime = RANDOM.nextInt(1000); log.info("inject random log replay delay of {}ms", rndTime); @@ -215,8 +215,8 @@ public class TestInjection { public static boolean injectUpdateRandomPause() { if (updateRandomPause != null) { Pair pair = parseValue(updateRandomPause); - boolean enabled = pair.getKey(); - int chanceIn100 = pair.getValue(); + boolean enabled = pair.first(); + int chanceIn100 = pair.second(); if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) { long rndTime = RANDOM.nextInt(1000); log.info("inject random update delay of {}ms", rndTime); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java index 55d8c83b386..eafad8438ad 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java @@ -385,8 +385,8 @@ public class ZkStateReader implements Closeable { if (securityNodeListener != null) { addSecuritynodeWatcher(pair -> { ConfigData cd = new ConfigData(); - cd.data = pair.getKey() == null || pair.getKey().length == 0 ? EMPTY_MAP : Utils.getDeepCopy((Map) fromJSON(pair.getKey()), 4, false); - cd.version = pair.getValue() == null ? -1 : pair.getValue().getVersion(); + cd.data = pair.first() == null || pair.first().length == 0 ? EMPTY_MAP : Utils.getDeepCopy((Map) fromJSON(pair.first()), 4, false); + cd.version = pair.second() == null ? -1 : pair.second().getVersion(); securityData = cd; securityNodeListener.run(); }); diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Pair.java b/solr/solrj/src/java/org/apache/solr/common/util/Pair.java index f87323c555c..c05e346228d 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Pair.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Pair.java @@ -17,30 +17,36 @@ package org.apache.solr.common.util; import java.io.Serializable; +import java.util.Objects; -public class Pair implements Serializable { - private K key; +public class Pair implements Serializable { + private final T1 first; + private final T2 second; - public K getKey() { - return key; + public T1 first() { + return first; } - private V value; - - public K _1() { - return key; + public T2 second() { + return second; } - public V _2() { - return value; + public Pair(T1 key, T2 value) { + this.first = key; + this.second = value; } - public V getValue() { - return value; + @Override + public boolean equals(Object obj) { + if (obj instanceof Pair) { + Pair that = (Pair) obj; + return Objects.equals(this.first, that.first) && Objects.equals(this.second, that.second); + } + return false; } - public Pair(K key, V value) { - this.key = key; - this.value = value; + @Override + public int hashCode() { + return (this.first == null ? 0 : this.first.hashCode()) ^ (this.second == null ? 0 : this.second.hashCode()); } } \ No newline at end of file