mirror of https://github.com/apache/lucene.git
SOLR-14343: set initcapacity properly in NamedList
* This is when map or map.entry array is passed in constructor
This commit is contained in:
parent
06fd70fc0f
commit
5630619dfd
|
@ -27,6 +27,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
@ -117,7 +118,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
|||
if (null == nameValueMap) {
|
||||
nvPairs = new ArrayList<>();
|
||||
} else {
|
||||
nvPairs = new ArrayList<>(nameValueMap.size());
|
||||
nvPairs = new ArrayList<>(nameValueMap.size() << 1);
|
||||
for (Map.Entry<String,? extends T> ent : nameValueMap.entrySet()) {
|
||||
nvPairs.add(ent.getKey());
|
||||
nvPairs.add(ent.getValue());
|
||||
|
@ -161,7 +162,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
|||
* @see <a href="https://issues.apache.org/jira/browse/SOLR-912">SOLR-912</a>
|
||||
*/
|
||||
private List<Object> nameValueMapToList(Map.Entry<String, ? extends T>[] nameValuePairs) {
|
||||
List<Object> result = new ArrayList<>();
|
||||
List<Object> result = new ArrayList<>(nameValuePairs.length << 1);
|
||||
for (Map.Entry<String, ?> ent : nameValuePairs) {
|
||||
result.add(ent.getKey());
|
||||
result.add(ent.getValue());
|
||||
|
@ -307,7 +308,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
|||
int sz = size();
|
||||
for (int i = 0; i < sz; i++) {
|
||||
String n = getName(i);
|
||||
if (name==n || (name!=null && name.equals(n))) {
|
||||
if (Objects.equals(name, n)) {
|
||||
result.add(getVal(i));
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +325,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
|||
// Go through the list backwards, removing matches as found.
|
||||
for (int i = sz - 1; i >= 0; i--) {
|
||||
String n = getName(i);
|
||||
if (name==n || (name!=null && name.equals(n))) {
|
||||
if (Objects.equals(name, n)) {
|
||||
remove(i);
|
||||
}
|
||||
}
|
||||
|
@ -702,8 +703,7 @@ public class NamedList<T> implements Cloneable, Serializable, Iterable<Map.Entry
|
|||
* @return List of values
|
||||
*/
|
||||
public List<T> removeAll(String name) {
|
||||
List<T> result = new ArrayList<>();
|
||||
result = getAll(name);
|
||||
List<T> result = getAll(name);
|
||||
if (result.size() > 0 ) {
|
||||
killAll(name);
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue