| java.lang.Object org.apache.solr.util.NamedList
NamedList | public class NamedList implements Cloneable,Serializable,Iterable<Map.Entry<String, T>>(Code) | | 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, see
SimpleOrderedMap ,
or simply use a regular
Map
author: yonik version: $Id: NamedList.java 501512 2007-01-30 18:36:32Z yonik $ |
Constructor Summary | |
public | NamedList() | public | NamedList(List nameValuePairs) Creates an instance backed by an explicitly specified list of
pairwise names/values. |
Method Summary | |
public void | add(String name, T val) Adds a name/value pair to the end of the list. | public boolean | addAll(Map<String, T> args) | public boolean | addAll(NamedList<T> nl) Appends the elements of the given NamedList to this one. | public NamedList<T> | clone() Makes a shallow copy of the named list. | public T | get(String name) Gets the value for the first instance of the specified name
found. | public T | get(String name, int start) Gets the value for the first instance of the specified name
found starting at the specified index. | public String | getName(int idx) | public T | getVal(int idx) | public 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. | public Iterator<Map.Entry<String, T>> | iterator() | public void | setName(int idx, String name) Modifies the name of the pair at the specified index. | public T | setVal(int idx, T val) Modifies the value of the pair at the specified index. | public int | size() | public String | toString() |
NamedList | public NamedList()(Code) | | Creates an empty instance
|
NamedList | public NamedList(List nameValuePairs)(Code) | | Creates an instance backed by an explicitly specified list of
pairwise names/values.
Parameters: nameValuePairs - underlying List which should be used to implement a NamedList; modifying this List will affect the NamedList. |
add | public void add(String name, T val)(Code) | | Adds a name/value pair to the end of the list.
|
addAll | public boolean addAll(Map<String, T> args)(Code) | | Iterates over the Map and sequentially adds it's key/value pairs
|
addAll | public boolean addAll(NamedList<T> nl)(Code) | | Appends the elements of the given NamedList to this one.
|
clone | public NamedList<T> clone()(Code) | | Makes a shallow copy of the named list.
|
get | public T get(String name, int start)(Code) | | Gets the value for the first instance of the specified name
found starting at the specified index.
null if not found or if the value stored was null. See Also: NamedList.indexOf |
getName | public String getName(int idx)(Code) | | The name of the pair at the specified List index
null if no name exists |
getVal | public T getVal(int idx)(Code) | | The value of the pair at the specified List index
may be null |
indexOf | public int indexOf(String name, int start)(Code) | | 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 Parameters: start - index to begin searching from The index of the first matching pair, -1 if no match |
setName | public void setName(int idx, String name)(Code) | | Modifies the name of the pair at the specified index.
|
setVal | public T setVal(int idx, T val)(Code) | | Modifies the value of the pair at the specified index.
the value that used to be at index |
size | public int size()(Code) | | The total number of name/value pairs
|
|
|