Class NamedLists


  • public final class NamedLists
    extends Object
    Utility class for working with NamedList. All methods of this class are null-safe: if the named list is null, the methods will simply return null.

    The convenience methods that take a number of path elements as an argument all work by first navigating to the given nested NamedList and then returning the requested element of that list. Note that if any of the lists in the given path contains a null value for the path element, or no value of that name, the methods return null.

    All methods of this class throw a NamedListEntryClassCastException if an element does not have the expected type.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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.
      static <T> T get​(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 the Collection of 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 the List of 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 the Set of 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 String getString​(org.apache.solr.common.util.NamedList<?> namedList, String name)
      Gets the string value of the specified name from the given list.
      static String getString​(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 nested NamedList stored at the given index.
      static org.apache.solr.common.util.NamedList<?> navigate​(org.apache.solr.common.util.NamedList<?> namedList, String name)
      Gets the nested NamedList stored under the given name.
      static org.apache.solr.common.util.NamedList<?> navigate​(org.apache.solr.common.util.NamedList<?> namedList, String... names)
      Gets the nested NamedList stored 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 nested NamedList stored under the given name.
        Parameters:
        namedList - the list.
        name - the name of the element in the list.
        Returns:
        the nested NamedList, or null if no element with the given name exists in the list or the value is null.
      • navigate

        public static org.apache.solr.common.util.NamedList<?> navigate​(org.apache.solr.common.util.NamedList<?> namedList,
                                                                        String... names)
        Gets the nested NamedList stored 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 nested NamedList stored at the given index. Note that unlike NamedList.getVal(int), this method will return null if the given index is invalid instead of throwing an IndexOutOfBoundsException.
        Parameters:
        namedList - the list.
        index - the index of the element.
        Returns:
        the nested NamedList, or null if the element at the given index is null or 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 null if namedList was null.
        Since:
        1.1
      • getSet

        public static <T> Set<T> getSet​(org.apache.solr.common.util.NamedList<?> namedList,
                                        String name)
        Gets the Set of 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 a ClassCastException may 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 null if the list does not contain an element with the given name or the value is null.
      • 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 the List of 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 a ClassCastException may 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 null if the list does not contain an element with the given name or the value is null.
      • 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 the Collection of 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 a ClassCastException may 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 null if the list does not contain an element with the given name or the value is null.
      • 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 null if the list does not contain an element with the given name or the value is null.
      • 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 null if no element with the given name exists in the list or the value if null.
        Throws:
        NamedListEntryClassCastException - if the value stored in the list is not an instance of class elementClass.
      • 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 of elementClass.
        IndexOutOfBoundsException - if the given index is not a valid index into the given list.