Class NamedList<T>
- java.lang.Object
- 
- org.apache.solr.common.util.NamedList<T>
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable,- Iterable<Map.Entry<String,T>>,- SimpleMap<T>,- MapSerializable,- MapWriter,- NavigableObject,- org.noggit.JSONWriter.Writable
 - Direct Known Subclasses:
- CloudSolrClient.RouteResponse,- SimpleOrderedMap
 
 public class NamedList<T> extends Object implements Cloneable, Serializable, Iterable<Map.Entry<String,T>>, MapWriter, SimpleMap<T> A simple container class for modeling an ordered list of name/value pairs.Unlike Maps: - Names may be repeated
- Order of elements is maintained
- Elements may be accessed by numeric index
- Names and Values can both be null
 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 regularMap- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classNamedList.NamedListEntry<T>Helper class implementing Map.Entry<String, T> to store the key-value relationship in NamedList (the keys of which are String-s)- 
Nested classes/interfaces inherited from interface org.apache.solr.common.MapWriterMapWriter.EntryWriter
 
- 
 - 
Constructor SummaryConstructors Constructor Description NamedList()Creates an empty instanceNamedList(int sz)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.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description int_size()voidabortableForEach(BiFunction<String,? super T,Boolean> fun)Navigate through all key-values but abort in between if required.voidabortableForEachKey(Function<String,Boolean> fun)iterate through all keys but abort in between if required The default impl is suboptimal.voidadd(String name, T val)Adds a name/value pair to the end of the list.booleanaddAll(Map<String,T> args)Iterates over the Map and sequentially adds its key/value pairsbooleanaddAll(NamedList<? extends T> nl)Appends the elements of the given NamedList to this one.MapasMap(int maxDepth)Map<String,T>asShallowMap()Map<String,T>asShallowMap(boolean allowDps)voidclear()NamedList<T>clone()Makes a shallow copy of the named list.booleanequals(Object obj)ObjectfindRecursive(String... args)Recursively parses the NamedList structure to arrive at a specific element.voidforEach(BiConsumer<String,? super T> action)voidforEachEntry(BiConsumer<String,? super T> fun)Navigate through all keys and valuesvoidforEachKey(Consumer<String> fun)iterate through all keys The default impl is suboptimal.Tget(String name)Gets the value for the first instance of the specified name found.Tget(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 specified nameBooleangetBooleanArg(String name)Used for getting a boolean argument from a NamedList object.NamedList<T>getImmutableCopy()StringgetName(int idx)The name of the pair at the specified List indexTgetOrDefault(String name, T def)Likeget(String)but returns a default value if it would be null.TgetVal(int idx)The value of the pair at the specified List indexinthashCode()intindexOf(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 interfaceTremove(int idx)Removes the name/value pair at the specified index.Tremove(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.BooleanremoveBooleanArg(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.voidsetName(int idx, String name)Modifies the name of the pair at the specified index.TsetVal(int idx, T val)Modifies the value of the pair at the specified index.intsize()The total number of name/value pairsSolrParamstoSolrParams()Create SolrParams from NamedList.StringtoString()voidwriteMap(MapWriter.EntryWriter ew)- 
Methods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.lang.IterableforEach, spliterator
 - 
Methods inherited from interface org.apache.solr.common.NavigableObject_forEachEntry, _forEachEntry, _forEachEntry, _get, _get, _getStr, _getStr
 
- 
 
- 
- 
- 
Constructor Detail- 
NamedListpublic NamedList() Creates an empty instance
 - 
NamedListpublic NamedList(int sz) 
 - 
NamedListpublic NamedList(Map.Entry<String,? extends T>[] nameValuePairs) Creates a NamedList instance containing the "name,value" pairs contained in the Entry[].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)orremove(String).- Parameters:
- nameValuePairs- the name value pairs
 
 - 
NamedListpublic NamedList(Map<String,? extends T> nameValueMap) Creates a NamedList instance containing the "name,value" pairs contained in the Map.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)orremove(String).- Parameters:
- nameValueMap- the name value pairs
 
 
- 
 - 
Method Detail- 
writeMappublic void writeMap(MapWriter.EntryWriter ew) throws IOException 
 - 
sizepublic int size() The total number of name/value pairs
 - 
getNamepublic String getName(int idx) The name of the pair at the specified List index- Returns:
- null if no name exists
 
 - 
getValpublic T getVal(int idx) The value of the pair at the specified List index- Returns:
- may be null
 
 - 
setNamepublic void setName(int idx, String name)Modifies the name of the pair at the specified index.
 - 
setValpublic T setVal(int idx, T val) Modifies the value of the pair at the specified index.- Returns:
- the value that used to be at index
 
 - 
removepublic T remove(int idx) Removes the name/value pair at the specified index.- Returns:
- the value at the index removed
 
 - 
indexOfpublic 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.- Parameters:
- name- name to look for, may be null
- start- index to begin searching from
- Returns:
- The index of the first matching pair, -1 if no match
 
 - 
getpublic T get(String name) Gets the value for the first instance of the specified name found.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). - Specified by:
- getin interface- SimpleMap<T>
- Returns:
- null if not found or if the value stored was null.
- See Also:
- indexOf(java.lang.String, int),- get(String,int)
 
 - 
getOrDefaultpublic T getOrDefault(String name, T def) Likeget(String)but returns a default value if it would be null.
 - 
getpublic T get(String name, int start) Gets the value for the first instance of the specified name found starting at the specified index.NOTE: this runs in linear time (it scans starting at the specified position until it finds the first pair with the specified name). - Returns:
- null if not found or if the value stored was null.
- See Also:
- indexOf(java.lang.String, int)
 
 - 
getAllpublic List<T> getAll(String name) Gets the values for the specified name- Parameters:
- name- Name
- Returns:
- List of values
 
 - 
findRecursivepublic Object findRecursive(String... args) Recursively parses the NamedList structure to arrive at a specific element. As you descend the NamedList tree, the last element can be any type, including NamedList, but the previous elements MUST be NamedList objects themselves. A null value is returned if the indicated hierarchy doesn't exist, but NamedList allows null values so that could be the actual value at the end of the path.This method is particularly useful for parsing the response from Solr's /admin/mbeans handler, but it also works for any complex structure. Explicitly casting the return value is recommended. An even safer option is to accept the return value as an object and then check its type. Usage examples: String coreName = (String) response.findRecursive ("solr-mbeans", "CORE", "core", "stats", "coreName"); long numDoc = (long) response.findRecursive ("solr-mbeans", "CORE", "searcher", "stats", "numDocs"); - Parameters:
- args- One or more strings specifying the tree to navigate.
- Returns:
- the last entry in the given path hierarchy, null if not found.
 
 - 
asMappublic Map asMap(int maxDepth) 
 - 
toSolrParamspublic SolrParams toSolrParams() Create SolrParams from NamedList. Values must beString[]orList(with toString()-appropriate entries), or otherwise have a toString()-appropriate value. Nulls are retained as such in arrays/lists but otherwise will NPE.
 - 
addAllpublic boolean addAll(Map<String,T> args) Iterates over the Map and sequentially adds its key/value pairs
 - 
addAllpublic boolean addAll(NamedList<? extends T> nl) Appends the elements of the given NamedList to this one.
 - 
removepublic 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).
 - 
removeAllpublic List<T> removeAll(String name) Removes and returns all values for the specified name. Returns null if no matches found. This method will return all matching objects, regardless of data type. If you are parsing Solr config options, theremoveConfigArgs(String)orremoveBooleanArg(String)methods will probably work better.- Parameters:
- name- Name
- Returns:
- List of values
 
 - 
removeBooleanArgpublic Boolean removeBooleanArg(String name) Used for getting a boolean argument from a NamedList object. If the name is not present, returns null. If there is more than one value with that name, or if the value found is not a Boolean or a String, throws an exception. If there is only one value present, and it is a Boolean or a String, the value is removed and returned as a Boolean. If an exception is thrown, the NamedList is not modified. SeeremoveAll(String)andremoveConfigArgs(String)for additional ways of gathering configuration information from a NamedList.- Parameters:
- name- The key to look up in the NamedList.
- Returns:
- The boolean value found.
- Throws:
- SolrException- If multiple values are found for the name or the value found is not a Boolean or a String.
 
 - 
getBooleanArgpublic Boolean getBooleanArg(String name) Used for getting a boolean argument from a NamedList object. If the name is not present, returns null. If there is more than one value with that name, or if the value found is not a Boolean or a String, throws an exception. If there is only one value present, and it is a Boolean or a String, the value is returned as a Boolean. The NamedList is not modified. Seeremove(String),removeAll(String)andremoveConfigArgs(String)for additional ways of gathering configuration information from a NamedList.- Parameters:
- name- The key to look up in the NamedList.
- Returns:
- The boolean value found.
- Throws:
- SolrException- If multiple values are found for the name or the value found is not a Boolean or a String.
 
 - 
removeConfigArgspublic Collection<String> removeConfigArgs(String name) throws SolrException Used for getting one or many arguments from NamedList objects that hold configuration parameters. Finds all entries in the NamedList that match the given name. If they are all strings or arrays of strings, remove them from the NamedList and return the individual elements as aCollection. Parameter order will be preserved if the returned collection is handled as anArrayList. 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, useremoveAll(String)instead. TheremoveBooleanArg(String)method can be used for retrieving a boolean argument.- Parameters:
- name- The key to look up in the NamedList.
- Returns:
- A collection of the values found.
- Throws:
- SolrException- If values are found for the input key that are not strings or arrays of strings.
 
 - 
clearpublic void clear() 
 - 
abortableForEachpublic void abortableForEach(BiFunction<String,? super T,Boolean> fun) Description copied from interface:SimpleMapNavigate through all key-values but abort in between if required. The default impl is suboptimal. Proper implementations must do it more efficiently- Specified by:
- abortableForEachin interface- SimpleMap<T>
- Parameters:
- fun- Consume each entry and return a boolean to signal whether to proceed or not. If true, continue, if false stop
 
 - 
abortableForEachKeypublic void abortableForEachKey(Function<String,Boolean> fun) Description copied from interface:SimpleMapiterate through all keys but abort in between if required The default impl is suboptimal. Proper implementations must do it more efficiently- Specified by:
- abortableForEachKeyin interface- SimpleMap<T>
- Parameters:
- fun- Consume each key and return a boolean to signal whether to proceed or not. If true, continue. If false stop
 
 - 
forEachKeypublic void forEachKey(Consumer<String> fun) Description copied from interface:SimpleMapiterate through all keys The default impl is suboptimal. Proper implementations must do it more efficiently- Specified by:
- forEachKeyin interface- SimpleMap<T>
 
 - 
forEachpublic void forEach(BiConsumer<String,? super T> action) 
 - 
_sizepublic int _size() - Specified by:
- _sizein interface- NavigableObject
 
 - 
forEachEntrypublic void forEachEntry(BiConsumer<String,? super T> fun) Description copied from interface:SimpleMapNavigate through all keys and values- Specified by:
- forEachEntryin interface- SimpleMap<T>
 
 
- 
 
-