public class NamedList<T> extends Object implements Cloneable, Serializable, Iterable<Map.Entry<String,T>>
Unlike Maps:
A NamedList provides fast access by element number, but not by name.
When a NamedList is serialized, order is considered more important than access
by key, so ResponseWriters that output to a format such as JSON will normally
choose a data structure that allows order to be easily preserved in various
clients (i.e. not a straight map).
If access by key is more important for serialization, see SimpleOrderedMap
,
or simply use a regular Map
Modifier and Type | Class and Description |
---|---|
static class |
NamedList.NamedListEntry<T>
Helper class implementing Map.Entry<String, T> to store the key-value
relationship in NamedList (the keys of which are String-s)
|
Constructor and Description |
---|
NamedList()
Creates an empty instance
|
NamedList(int sz) |
NamedList(List<Object> nameValuePairs)
Deprecated.
Use
NamedList(java.util.Map.Entry[]) for the NamedList instantiation |
NamedList(Map.Entry<String,? extends T>[] nameValuePairs)
Creates a NamedList instance containing the "name,value" pairs contained in the
Entry[].
|
NamedList(Map<String,? extends T> nameValueMap)
Creates a NamedList instance containing the "name,value" pairs contained in the
Map.
|
Modifier and Type | Method and Description |
---|---|
void |
add(String name,
T val)
Adds a name/value pair to the end of the list.
|
boolean |
addAll(Map<String,T> args)
Iterates over the Map and sequentially adds its key/value pairs
|
boolean |
addAll(NamedList<T> nl)
Appends the elements of the given NamedList to this one.
|
Map |
asMap(int maxDepth) |
Map<String,T> |
asShallowMap() |
void |
clear() |
NamedList<T> |
clone()
Makes a shallow copy of the named list.
|
boolean |
equals(Object obj) |
Object |
findRecursive(String... args)
Recursively parses the NamedList structure to arrive at a specific element.
|
void |
forEach(BiConsumer<String,T> action) |
T |
get(String name)
Gets the value for the first instance of the specified name
found.
|
T |
get(String name,
int start)
Gets the value for the first instance of the specified name
found starting at the specified index.
|
List<T> |
getAll(String name)
Gets the values for the the specified name
|
Boolean |
getBooleanArg(String name)
Used for getting a boolean argument from a NamedList object.
|
NamedList |
getImmutableCopy() |
String |
getName(int idx)
The name of the pair at the specified List index
|
T |
getVal(int idx)
The value of the pair at the specified List index
|
int |
hashCode() |
int |
indexOf(String name,
int start)
Scans the list sequentially beginning at the specified index and
returns the index of the first pair with the specified name.
|
Iterator<Map.Entry<String,T>> |
iterator()
Support the Iterable interface
|
T |
remove(int idx)
Removes the name/value pair at the specified index.
|
T |
remove(String name)
NOTE: this runs in linear time (it scans starting at the
beginning of the list until it finds the first pair with
the specified name).
|
List<T> |
removeAll(String name)
Removes and returns all values for the specified name.
|
Boolean |
removeBooleanArg(String name)
Used for getting a boolean argument from a NamedList object.
|
Collection<String> |
removeConfigArgs(String name)
Used for getting one or many arguments from NamedList objects that hold
configuration parameters.
|
void |
setName(int idx,
String name)
Modifies the name of the pair at the specified index.
|
T |
setVal(int idx,
T val)
Modifies the value of the pair at the specified index.
|
int |
size()
The total number of name/value pairs
|
String |
toString() |
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public NamedList()
public NamedList(int sz)
public NamedList(Map.Entry<String,? extends T>[] nameValuePairs)
Modifying the contents of the Entry[] after calling this constructor may change
the NamedList (in future versions of Solr), but this is not guaranteed and should
not be relied upon. To modify the NamedList, refer to add(String, Object)
or remove(String)
.
nameValuePairs
- the name value pairspublic NamedList(Map<String,? extends T> nameValueMap)
Modifying the contents of the Map after calling this constructor may change
the NamedList (in future versions of Solr), but this is not guaranteed and should
not be relied upon. To modify the NamedList, refer to add(String, Object)
or remove(String)
.
nameValueMap
- the name value pairs@Deprecated public NamedList(List<Object> nameValuePairs)
NamedList(java.util.Map.Entry[])
for the NamedList instantiationWhen using this constructor, runtime type safety is only guaranteed if all even numbered elements of the input list are of type "T".
nameValuePairs
- underlying List which should be used to implement a NamedListpublic int size()
public String getName(int idx)
public T getVal(int idx)
public void setName(int idx, String name)
public T setVal(int idx, T val)
public T remove(int idx)
public int indexOf(String name, int start)
name
- name to look for, may be nullstart
- index to begin searching frompublic T get(String name)
NOTE: this runs in linear time (it scans starting at the beginning of the list until it finds the first pair with the specified name).
indexOf(java.lang.String, int)
,
get(String,int)
public T get(String name, int start)
NOTE: this runs in linear time (it scans starting at the specified position until it finds the first pair with the specified name).
indexOf(java.lang.String, int)
public List<T> getAll(String name)
name
- Namepublic Object findRecursive(String... args)
args
- One or more strings specifying the tree to navigate.public NamedList getImmutableCopy()
public Map asMap(int maxDepth)
public boolean addAll(Map<String,T> args)
public boolean addAll(NamedList<T> nl)
public T remove(String name)
public List<T> removeAll(String name)
removeConfigArgs(String)
or removeBooleanArg(String)
methods will probably work better.name
- Namepublic Boolean removeBooleanArg(String name)
removeAll(String)
and removeConfigArgs(String)
for additional ways of gathering
configuration information from a NamedList.name
- The key to look up in the NamedList.SolrException
- If multiple values are found for the name or the value found is
not a Boolean or a String.public Boolean getBooleanArg(String name)
remove(String)
, removeAll(String)
and removeConfigArgs(String)
for additional ways of gathering
configuration information from a NamedList.name
- The key to look up in the NamedList.SolrException
- If multiple values are found for the name or the value found is
not a Boolean or a String.public Collection<String> removeConfigArgs(String name) throws SolrException
Collection
.
Parameter order will be preserved if the returned collection is handled as
an ArrayList
. Throws SolrException if any of the values associated
with the name are not strings or arrays of strings. If exception is
thrown, the NamedList is not modified. Returns an empty collection if no
matches found. If you need to remove and retrieve all matching items from
the NamedList regardless of data type, use removeAll(String)
instead.
The removeBooleanArg(String)
method can be used for retrieving a
boolean argument.name
- The key to look up in the NamedList.SolrException
- If values are found for the input key that are not strings or
arrays of strings.public void clear()
public void forEach(BiConsumer<String,T> action)
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.