org.apache.solr.util
Class NamedList

java.lang.Object
  extended by org.apache.solr.util.NamedList
All Implemented Interfaces:
Serializable, Cloneable

public class NamedList
extends Object
implements Cloneable, Serializable

A simple container class for modeling an ordered list of name/value pairs.

Unlike Maps:

:TODO: In the future, it would be nice if this extended Map or Collection, had iterators, used java5 generics, had a faster lookup for large lists, etc... It could also have an interface, and multiple implementations. One might have indexed lookup, one might not.

Version:
$Id: NamedList.java 472574 2006-11-08 18:25:52Z yonik $
Author:
yonik
See Also:
Serialized Form

Field Summary
protected  List nvPairs
           
 
Constructor Summary
NamedList()
          Creates an empty instance
NamedList(List nameValuePairs)
          Creates an instance backed by an explicitly specified list of pairwise names/values.
 
Method Summary
 void add(String name, Object val)
          Adds a name/value pair to the end of the list.
 boolean addAll(Map args)
          Iterates over the Map and sequentially adds it's key/value pairs
 boolean addAll(NamedList nl)
          Appends the elements of the given NamedList to this one.
 NamedList clone()
          Makes a shallow copy of the named list.
 Object get(String name)
          Gets the value for the first instance of the specified name found.
 Object get(String name, int start)
          Gets the value for the first instance of the specified name found starting at the specified index.
 String getName(int idx)
          The name of the pair at the specified List index
 Object getVal(int idx)
          The value of the pair at the specified List index
 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.
 void setName(int idx, String name)
          Modifies the name of the pair at the specified index.
 void setVal(int idx, Object val)
          Modifies the value of the pair at the specified index.
 int size()
          The total number of name/value pairs
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nvPairs

protected final List nvPairs
Constructor Detail

NamedList

public NamedList()
Creates an empty instance


NamedList

public NamedList(List nameValuePairs)
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.
Method Detail

size

public int size()
The total number of name/value pairs


getName

public String getName(int idx)
The name of the pair at the specified List index

Returns:
null if no name exists

getVal

public Object getVal(int idx)
The value of the pair at the specified List index

Returns:
may be null

add

public void add(String name,
                Object val)
Adds a name/value pair to the end of the list.


setName

public void setName(int idx,
                    String name)
Modifies the name of the pair at the specified index.


setVal

public void setVal(int idx,
                   Object val)
Modifies the value of the pair at the specified index.


indexOf

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.

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

get

public Object get(String name)
Gets the value for the first instance of the specified name found.

Returns:
null if not found or if the value stored was null.
See Also:
indexOf(java.lang.String, int), get(String,int)

get

public Object get(String name,
                  int start)
Gets the value for the first instance of the specified name found starting at the specified index.

Returns:
null if not found or if the value stored was null.
See Also:
indexOf(java.lang.String, int)

toString

public String toString()
Overrides:
toString in class Object

addAll

public boolean addAll(Map args)
Iterates over the Map and sequentially adds it's key/value pairs


addAll

public boolean addAll(NamedList nl)
Appends the elements of the given NamedList to this one.


clone

public NamedList clone()
Makes a shallow copy of the named list.

Overrides:
clone in class Object


Copyright © 2006 - 2006 The Apache Software Foundation