Package cool.solr.search.solr.util
Class NamedLists
- java.lang.Object
-
- cool.solr.search.solr.util.NamedLists
-
public final class NamedLists extends Object
Utility class for working withNamedList. All methods of this class are null-safe: if the named list isnull, the methods will simply returnnull.The convenience methods that take a number of path elements as an argument all work by first navigating to the given nested
NamedListand then returning the requested element of that list. Note that if any of the lists in the given path contains anullvalue for the path element, or no value of that name, the methods returnnull.All methods of this class throw a
NamedListEntryClassCastExceptionif an element does not have the expected type.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tget(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, int index)Gets the element at the specified index from the given list.static <T> Tget(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, String name)Gets the element of the specified name from the given list.static <T> Tget(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, String... names)Gets a nested element from the given list.static <T> Collection<T>getCollection(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets theCollectionof the specified name from the given list.static <T> Collection<T>getCollection(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets a collection from the given list.static <T> List<T>getList(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets theListof the specified name from the given list.static <T> List<T>getList(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets a list from the given list.static <T> Set<T>getSet(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets theSetof the specified name from the given list.static <T> Set<T>getSet(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets a set from the given list.static StringgetString(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets the string value of the specified name from the given list.static StringgetString(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets a string value from the given list.static Set<String>keys(org.apache.solr.common.util.NamedList<?> namedList)Returns the set of keys in the given named list.static org.apache.solr.common.util.NamedList<?>navigate(org.apache.solr.common.util.NamedList<?> namedList, int index)Gets the nestedNamedListstored at the given index.static org.apache.solr.common.util.NamedList<?>navigate(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets the nestedNamedListstored under the given name.static org.apache.solr.common.util.NamedList<?>navigate(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets the nestedNamedListstored under the given path.
-
-
-
Method Detail
-
navigate
public static org.apache.solr.common.util.NamedList<?> navigate(org.apache.solr.common.util.NamedList<?> namedList, String name)Gets the nestedNamedListstored under the given name.- Parameters:
namedList- the list.name- the name of the element in the list.- Returns:
- the nested
NamedList, ornullif no element with the given name exists in the list or the value isnull.
-
navigate
public static org.apache.solr.common.util.NamedList<?> navigate(org.apache.solr.common.util.NamedList<?> namedList, String... names)Gets the nestedNamedListstored under the given path. See the class documentation for notes on convenience methods that take a path as their argument.
-
navigate
public static org.apache.solr.common.util.NamedList<?> navigate(org.apache.solr.common.util.NamedList<?> namedList, int index)Gets the nestedNamedListstored at the given index. Note that unlikeNamedList.getVal(int), this method will returnnullif the given index is invalid instead of throwing anIndexOutOfBoundsException.- Parameters:
namedList- the list.index- the index of the element.- Returns:
- the nested
NamedList, ornullif the element at the given index isnullor if the given index is not a valid index.
-
keys
public static Set<String> keys(org.apache.solr.common.util.NamedList<?> namedList)
Returns the set of keys in the given named list.- Parameters:
namedList- the list.- Returns:
- The set of keys, or
nullifnamedListwasnull. - Since:
- 1.1
-
getSet
public static <T> Set<T> getSet(org.apache.solr.common.util.NamedList<?> namedList, String name)
Gets theSetof the specified name from the given list.- Type Parameters:
T- the type of the elements in the returned set. Note that this type is not checked by this method, so aClassCastExceptionmay occur when trying to actually access the elements of the set if they're not of the expected class.- Parameters:
namedList- the list.name- the name of the element in the list.- Returns:
- the set, or
nullif the list does not contain an element with the given name or the value isnull.
-
getSet
public static <T> Set<T> getSet(org.apache.solr.common.util.NamedList<?> namedList, String... names)
Gets a set from the given list. See the class documentation for notes on convenience methods that take a path as their argument.- See Also:
getSet(NamedList, String)
-
getList
public static <T> List<T> getList(org.apache.solr.common.util.NamedList<?> namedList, String name)
Gets theListof the specified name from the given list.- Type Parameters:
T- the type of the elements in the returned list. Note that this type is not checked by this method, so aClassCastExceptionmay occur when trying to actually access the elements of the list if they're not of the expected class.- Parameters:
namedList- the list.name- the name of the element in the list.- Returns:
- the list, or
nullif the list does not contain an element with the given name or the value isnull.
-
getList
public static <T> List<T> getList(org.apache.solr.common.util.NamedList<?> namedList, String... names)
Gets a list from the given list. See the class documentation for notes on convenience methods that take a path as their argument.- See Also:
getList(NamedList, String)
-
getCollection
public static <T> Collection<T> getCollection(org.apache.solr.common.util.NamedList<?> namedList, String name)
Gets theCollectionof the specified name from the given list.- Type Parameters:
T- the type of the elements in the returned collection. Note that this type is not checked by this method, so aClassCastExceptionmay occur when trying to actually access the elements of the collection if they're not of the expected class.- Parameters:
namedList- the list.name- the name of the element in the list.- Returns:
- the collection, or
nullif the list does not contain an element with the given name or the value isnull.
-
getCollection
public static <T> Collection<T> getCollection(org.apache.solr.common.util.NamedList<?> namedList, String... names)
Gets a collection from the given list. See the class documentation for notes on convenience methods that take a path as their argument.- See Also:
getCollection(NamedList, String)
-
getString
public static String getString(org.apache.solr.common.util.NamedList<?> namedList, String name)
Gets the string value of the specified name from the given list.- Parameters:
namedList- the list.name- the name of the element in the list.- Returns:
- the string, or
nullif the list does not contain an element with the given name or the value isnull.
-
getString
public static String getString(org.apache.solr.common.util.NamedList<?> namedList, String... names)
Gets a string value from the given list. See the class documentation for notes on convenience methods that take a path as their argument.- See Also:
getString(NamedList, String)
-
get
public static <T> T get(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, String name)Gets the element of the specified name from the given list.- Parameters:
namedList- the list.elementClass- the class of the element expected in the list under the given name.name- the name of the list entry to return.- Returns:
- the first element found in the list under the given name, or
nullif no element with the given name exists in the list or the value ifnull. - Throws:
NamedListEntryClassCastException- if the value stored in the list is not an instance of classelementClass.
-
get
public static <T> T get(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, String... names)Gets a nested element from the given list. See the class documentation for notes on convenience methods that take a path as their argument.- See Also:
get(NamedList, Class, String)
-
get
public static <T> T get(org.apache.solr.common.util.NamedList<?> namedList, Class<T> elementClass, int index)Gets the element at the specified index from the given list.- Parameters:
namedList- the list.elementClass- the class of the element expected in the list at the specified index.index- the index of the element.- Returns:
- the element at the specified index.
- Throws:
NamedListEntryClassCastException- if the value stored in the list is not an instance ofelementClass.IndexOutOfBoundsException- if the given index is not a valid index into the given list.
-
-