Class Series<T extends NamedValue<java.lang.String>>

  • Type Parameters:
    T - The contained type
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>
    Direct Known Subclasses:
    Form

    public class Series<T extends NamedValue<java.lang.String>>
    extends WrapperList<T>
    Modifiable list of entries with many helper methods. Note that this class uses the Parameter class as the template type. This allows you to use an instance of this class as any other java.util.List, in particular all the helper methods in java.util.Collections.
    Author:
    Jerome Louvel
    See Also:
    Parameter, Collections, List
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Object EMPTY_VALUE
      A marker for empty values to differentiate from non existing values (null).
    • Constructor Summary

      Constructors 
      Constructor Description
      Series​(java.lang.Class<T> entryClass)
      Constructor.
      Series​(java.lang.Class<T> entryClass, int initialCapacity)
      Constructor.
      Series​(java.lang.Class<T> entryClass, java.util.List<T> delegate)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.String name, java.lang.String value)
      Creates then adds a parameter at the end of the list.
      void copyTo​(java.util.Map<java.lang.String,​java.lang.Object> params)
      Copies the parameters whose name is a key in the given map.
      If a matching parameter is found, its value is put in the map.
      If multiple values are found, a list is created and set in the map.
      T createEntry​(java.lang.String name, java.lang.String value)
      Creates a new entry.
      T getFirst​(java.lang.String name)
      Returns the first parameter found with the given name.
      T getFirst​(java.lang.String name, boolean ignoreCase)
      Returns the first parameter found with the given name.
      java.lang.String getFirstValue​(java.lang.String name)
      Returns the value of the first parameter found with the given name.
      java.lang.String getFirstValue​(java.lang.String name, boolean ignoreCase)
      Returns the value of the first parameter found with the given name.
      java.lang.String getFirstValue​(java.lang.String name, boolean ignoreCase, java.lang.String defaultValue)
      Returns the value of the first parameter found with the given name.
      java.lang.String getFirstValue​(java.lang.String name, java.lang.String defaultValue)
      Returns the value of the first parameter found with the given name.
      java.util.Set<java.lang.String> getNames()
      Returns the set of parameter names (case sensitive).
      java.lang.String getValues​(java.lang.String name)
      Returns the values of the parameters with a given name.
      java.lang.String getValues​(java.lang.String name, java.lang.String separator, boolean ignoreCase)
      Returns the parameter values with a given name.
      java.lang.String[] getValuesArray​(java.lang.String name)
      Returns an array of all the values associated to the given parameter name.
      java.lang.String[] getValuesArray​(java.lang.String name, boolean ignoreCase)
      Returns an array of all the values associated to the given parameter name.
      java.lang.String[] getValuesArray​(java.lang.String name, boolean ignoreCase, java.lang.String defaultValue)
      Returns an array of all the values associated to the given parameter name.
      java.lang.String[] getValuesArray​(java.lang.String name, java.lang.String defaultValue)
      Returns an array of all the values associated to the given parameter name.
      java.util.Map<java.lang.String,​java.lang.String> getValuesMap()
      Returns a map of name, value pairs.
      boolean removeAll​(java.lang.String name)
      Removes all the parameters with a given name.
      boolean removeAll​(java.lang.String name, boolean ignoreCase)
      Removes all the parameters with a given name.
      boolean removeFirst​(java.lang.String name)
      Removes from this list the first entry whose name equals the specified name ignoring the case.
      boolean removeFirst​(java.lang.String name, boolean ignoreCase)
      Removes from this list the first entry whose name equals the specified name ignoring the case or not.
      T set​(java.lang.String name, java.lang.String value)
      Replaces the value of the first parameter with the given name and removes all other parameters with the same name.
      T set​(java.lang.String name, java.lang.String value, boolean ignoreCase)
      Replaces the value of the first parameter with the given name and removes all other parameters with the same name.
      Series<T> subList​(int fromIndex, int toIndex)
      Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
      Series<T> subList​(java.lang.String name)
      Returns a list of all the values associated to the parameter name.
      Series<T> subList​(java.lang.String name, boolean ignoreCase)
      Returns a list of all the values associated to the parameter name.
      static Series<? extends NamedValue> unmodifiableSeries​(Series<? extends NamedValue> series)
      Returns an unmodifiable view of the specified series.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        replaceAll, sort, spliterator
    • Field Detail

      • EMPTY_VALUE

        public static final java.lang.Object EMPTY_VALUE
        A marker for empty values to differentiate from non existing values (null).
    • Constructor Detail

      • Series

        public Series​(java.lang.Class<T> entryClass)
        Constructor.
      • Series

        public Series​(java.lang.Class<T> entryClass,
                      int initialCapacity)
        Constructor.
        Parameters:
        initialCapacity - The initial list capacity.
      • Series

        public Series​(java.lang.Class<T> entryClass,
                      java.util.List<T> delegate)
        Constructor.
        Parameters:
        delegate - The delegate list.
    • Method Detail

      • unmodifiableSeries

        public static Series<? extends NamedValue> unmodifiableSeries​(Series<? extends NamedValue> series)
        Returns an unmodifiable view of the specified series. Attempts to call a modification method will throw an UnsupportedOperationException.
        Parameters:
        series - The series for which an unmodifiable view should be returned.
        Returns:
        The unmodifiable view of the specified series.
      • add

        public boolean add​(java.lang.String name,
                           java.lang.String value)
        Creates then adds a parameter at the end of the list.
        Parameters:
        name - The parameter name.
        value - The parameter value.
        Returns:
        True (as per the general contract of the Collection.add method).
      • copyTo

        public void copyTo​(java.util.Map<java.lang.String,​java.lang.Object> params)
        Copies the parameters whose name is a key in the given map.
        If a matching parameter is found, its value is put in the map.
        If multiple values are found, a list is created and set in the map.
        Parameters:
        params - The map controlling the copy.
      • createEntry

        public T createEntry​(java.lang.String name,
                             java.lang.String value)
        Creates a new entry.
        Parameters:
        name - The name of the entry.
        value - The value of the entry.
        Returns:
        A new entry.
      • getFirst

        public T getFirst​(java.lang.String name)
        Returns the first parameter found with the given name.
        Parameters:
        name - The parameter name (case sensitive).
        Returns:
        The first parameter found with the given name.
      • getFirst

        public T getFirst​(java.lang.String name,
                          boolean ignoreCase)
        Returns the first parameter found with the given name.
        Parameters:
        name - The parameter name.
        ignoreCase - Indicates if the name comparison is case insensitive.
        Returns:
        The first parameter found with the given name.
      • getFirstValue

        public java.lang.String getFirstValue​(java.lang.String name)
        Returns the value of the first parameter found with the given name.
        Parameters:
        name - The parameter name (case sensitive).
        Returns:
        The value of the first parameter found with the given name.
      • getFirstValue

        public java.lang.String getFirstValue​(java.lang.String name,
                                              boolean ignoreCase)
        Returns the value of the first parameter found with the given name.
        Parameters:
        name - The parameter name.
        ignoreCase - Indicates if the name comparison is case sensitive.
        Returns:
        The value of the first parameter found with the given name.
      • getFirstValue

        public java.lang.String getFirstValue​(java.lang.String name,
                                              boolean ignoreCase,
                                              java.lang.String defaultValue)
        Returns the value of the first parameter found with the given name.
        Parameters:
        name - The parameter name.
        ignoreCase - Indicates if the name comparison is case sensitive.
        defaultValue - The default value to return if no matching parameter found or if the parameter has a null value.
        Returns:
        The value of the first parameter found with the given name or the default value.
      • getFirstValue

        public java.lang.String getFirstValue​(java.lang.String name,
                                              java.lang.String defaultValue)
        Returns the value of the first parameter found with the given name.
        Parameters:
        name - The parameter name (case sensitive).
        defaultValue - The default value to return if no matching parameter found or if the parameter has a null value.
        Returns:
        The value of the first parameter found with the given name or the default value.
      • getNames

        public java.util.Set<java.lang.String> getNames()
        Returns the set of parameter names (case sensitive).
        Returns:
        The set of parameter names.
      • getValues

        public java.lang.String getValues​(java.lang.String name)
        Returns the values of the parameters with a given name. If multiple parameters with the same name are found, all values are concatenated and separated by a comma (like for HTTP message headers).
        Parameters:
        name - The parameter name (case insensitive).
        Returns:
        The values of the parameters with a given name.
      • getValues

        public java.lang.String getValues​(java.lang.String name,
                                          java.lang.String separator,
                                          boolean ignoreCase)
        Returns the parameter values with a given name. If multiple parameters with the same name are found, all values are concatenated and separated by the given separator.
        Parameters:
        name - The parameter name.
        separator - The separator character.
        ignoreCase - Indicates if the name comparison is case sensitive.
        Returns:
        The sequence of values.
      • getValuesArray

        public java.lang.String[] getValuesArray​(java.lang.String name)
        Returns an array of all the values associated to the given parameter name.
        Parameters:
        name - The parameter name to match (case sensitive).
        Returns:
        The array of values.
      • getValuesArray

        public java.lang.String[] getValuesArray​(java.lang.String name,
                                                 boolean ignoreCase)
        Returns an array of all the values associated to the given parameter name.
        Parameters:
        name - The parameter name to match.
        ignoreCase - Indicates if the name comparison is case sensitive.
        Returns:
        The array of values.
      • getValuesArray

        public java.lang.String[] getValuesArray​(java.lang.String name,
                                                 boolean ignoreCase,
                                                 java.lang.String defaultValue)
        Returns an array of all the values associated to the given parameter name.
        Parameters:
        name - The parameter name to match.
        ignoreCase - Indicates if the name comparison is case sensitive.
        defaultValue - The default value to return if no matching parameter found or if the parameter has a null value.
        Returns:
        The array of values.
      • getValuesArray

        public java.lang.String[] getValuesArray​(java.lang.String name,
                                                 java.lang.String defaultValue)
        Returns an array of all the values associated to the given parameter name.
        Parameters:
        name - The parameter name to match.
        defaultValue - The default value to return if no matching parameter found or if the parameter has a null value.
        Returns:
        The array of values.
      • getValuesMap

        public java.util.Map<java.lang.String,​java.lang.String> getValuesMap()
        Returns a map of name, value pairs. The order of the map keys is respected based on the series order. When a name has multiple values, only the first one is put in the map.
        Returns:
        The map of name, value pairs.
      • removeAll

        public boolean removeAll​(java.lang.String name)
        Removes all the parameters with a given name.
        Parameters:
        name - The parameter name (case sensitive).
        Returns:
        True if the list changed.
      • removeAll

        public boolean removeAll​(java.lang.String name,
                                 boolean ignoreCase)
        Removes all the parameters with a given name.
        Parameters:
        name - The parameter name.
        ignoreCase - Indicates if the name comparison is case insensitive.
        Returns:
        True if the list changed.
      • removeFirst

        public boolean removeFirst​(java.lang.String name)
        Removes from this list the first entry whose name equals the specified name ignoring the case.
        Parameters:
        name - The name of the entries to be removed (case sensitive).
        Returns:
        false if no entry has been removed, true otherwise.
      • removeFirst

        public boolean removeFirst​(java.lang.String name,
                                   boolean ignoreCase)
        Removes from this list the first entry whose name equals the specified name ignoring the case or not.
        Parameters:
        name - The name of the entries to be removed.
        ignoreCase - Indicates if the name comparison is case insensitive.
        Returns:
        false if no entry has been removed, true otherwise.
      • set

        public T set​(java.lang.String name,
                     java.lang.String value)
        Replaces the value of the first parameter with the given name and removes all other parameters with the same name. The name matching is case sensitive.
        Parameters:
        name - The parameter name.
        value - The value to set.
        Returns:
        The parameter set or added.
      • set

        public T set​(java.lang.String name,
                     java.lang.String value,
                     boolean ignoreCase)
        Replaces the value of the first parameter with the given name and removes all other parameters with the same name.
        Parameters:
        name - The parameter name.
        value - The value to set.
        ignoreCase - Indicates if the name comparison is case insensitive.
        Returns:
        The parameter set or added.
      • subList

        public Series<T> subList​(int fromIndex,
                                 int toIndex)
        Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
        Specified by:
        subList in interface java.util.List<T extends NamedValue<java.lang.String>>
        Overrides:
        subList in class WrapperList<T extends NamedValue<java.lang.String>>
        Parameters:
        fromIndex - The start position.
        toIndex - The end position (exclusive).
        Returns:
        The sub-list.
      • subList

        public Series<T> subList​(java.lang.String name)
        Returns a list of all the values associated to the parameter name.
        Parameters:
        name - The parameter name (case sensitive).
        Returns:
        The list of values.
      • subList

        public Series<T> subList​(java.lang.String name,
                                 boolean ignoreCase)
        Returns a list of all the values associated to the parameter name.
        Parameters:
        name - The parameter name.
        ignoreCase - Indicates if the name comparison is case insensitive.
        Returns:
        The list of values.