mirror of https://github.com/apache/lucene.git
SOLR-9233: avoid new string creation in CollectionAction
This commit is contained in:
parent
d3fcac779b
commit
153ca1f6c2
|
@ -16,7 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.common.params;
|
package org.apache.solr.common.params;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toMap;
|
||||||
|
|
||||||
public interface CollectionParams {
|
public interface CollectionParams {
|
||||||
/**
|
/**
|
||||||
|
@ -93,31 +99,32 @@ public interface CollectionParams {
|
||||||
MOCK_REPLICA_TASK(false, LockLevel.REPLICA)
|
MOCK_REPLICA_TASK(false, LockLevel.REPLICA)
|
||||||
;
|
;
|
||||||
public final boolean isWrite;
|
public final boolean isWrite;
|
||||||
|
|
||||||
|
public final String lowerName;
|
||||||
public final LockLevel lockLevel;
|
public final LockLevel lockLevel;
|
||||||
|
|
||||||
CollectionAction(boolean isWrite, LockLevel level) {
|
CollectionAction(boolean isWrite, LockLevel level) {
|
||||||
this.isWrite = isWrite;
|
this.isWrite = isWrite;
|
||||||
this.lockLevel = level;
|
this.lockLevel = level;
|
||||||
|
lowerName = toString().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CollectionAction get(String p) {
|
public static CollectionAction get(String p) {
|
||||||
if (p != null) {
|
return actions.get(p == null ? null : p.toLowerCase(Locale.ROOT));
|
||||||
try {
|
|
||||||
return CollectionAction.valueOf(p.toUpperCase(Locale.ROOT));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEqual(String s) {
|
public boolean isEqual(String s) {
|
||||||
if (s == null) return false;
|
return s != null && lowerName.equals(s.toLowerCase(Locale.ROOT));
|
||||||
return toString().equals(s.toUpperCase(Locale.ROOT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toLower() {
|
public String toLower() {
|
||||||
return toString().toLowerCase(Locale.ROOT);
|
return lowerName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
Map<String, CollectionAction> actions = Collections.unmodifiableMap(
|
||||||
|
Stream.of(
|
||||||
|
CollectionAction.values())
|
||||||
|
.collect(toMap(CollectionAction::toLower, Function.<CollectionAction>identity())));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue