Class HeaderList
- All Implemented Interfaces:
- Serializable,- Cloneable,- Iterable<Header>,- Collection<Header>,- List<Header>,- RandomAccess
- Direct Known Subclasses:
- HeaderList.Void
Example
   HeaderList 
Convenience creators are provided for creating lists with minimal code:
   HeaderList 
 Static methods are provided on HttpHeaders to further simplify creation of header lists.
 
   
See Also:
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classRepresents no header list in annotations.
- 
Field SummaryFields inherited from class java.util.AbstractListmodCount
- 
Constructor SummaryConstructorsModifierConstructorDescriptionConstructor.protectedHeaderList(HeaderList copyFrom) Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionAppends the specified header to the end of this list.Appends the specified header to the end of this list using a value supplier.Adds the specified headers to the end of the headers in this list.Adds the specified header to the end of the headers in this list.Adds the specified headers to the end of the headers in this list.caseSensitive(boolean value) Specifies that the headers in this list should be treated as case-sensitive.booleanTests if headers with the given name are contained within this list.copy()Makes a copy of this list.static HeaderListcreate()Instantiates a new list.Performs an action on all headers with the specified name in this list.Performs an action on all matching headers in this list.forEachValue(String name, Consumer<String> action) Performs an action on the values of all matching headers in this list.forEachValue(Predicate<Header> filter, Consumer<String> action) Performs an action on the values for all matching headers in this list.<T> Optional<T>Gets a header representing all of the header values with the given name.Gets a header representing all of the header values with the given name.<T> Optional<T>Gets a header representing all of the header values with the given name.Header[]getAll()Gets all of the headers.Header[]Gets all of the headers with the given name.Gets the first header with the given name.Gets the last header with the given name.String[]Returns all the string values for all headers with the specified name.Returns an iterator over this list of headers.headerIterator(String name) Returns an iterator over the headers with a given name in this list.static HeaderListCreates a newHeaderListinitialized with the specified headers.static HeaderListCreates a newHeaderListinitialized with the specified headers.static HeaderListCreates a newHeaderListinitialized with the specified name/value pairs.Appends the specified header to the beginning of this list.Appends the specified header to the beginning of this list using a value supplier.Adds the specified headers to the beginning of the headers in this list.Adds the specified header to the beginning of the headers in this list.Adds the specified headers to the beginning of the headers in this list.Removes the header with the specified name from this list.Removes the header with the specified name from this list.Removes the specified headers from this list.Removes the specified header from this list.Removes the specified headers from this list.Removes all headers from this list.Allows header values to contain SVL variables.resolving(VarResolver varResolver) Allows header values to contain SVL variables.Replaces the first occurrence of the headers with the same name.Replaces the first occurrence of the headers with the same name.Replaces the first occurrence of the headers with the same name.Adds or replaces the header(s) with the same name.Adds or replaces the header(s) with the same name.setDefault(String name, Object value) Replaces the first occurrence of the headers with the same name.setDefault(String name, Supplier<?> value) Replaces the first occurrence of the headers with the same name.setDefault(List<Header> headers) Adds a collection of default headers.setDefault(Header... headers) Makes a copy of this list of headers and adds a collection of default headers.Specifies whether this bean should be unmodifiable.Returns a stream of the headers in this list with the specified name.toString()Methods inherited from class org.apache.juneau.collections.ControlledArrayListadd, add, addAll, addAll, assertModifiable, clear, isModifiable, iterator, listIterator, listIterator, overrideAdd, overrideAdd, overrideAddAll, overrideAddAll, overrideClear, overrideIterator, overrideListIterator, overrideRemove, overrideRemove, overrideRemoveAll, overrideRemoveIf, overrideReplaceAll, overrideRetainAll, overrideSet, overrideSort, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, sort, subListMethods inherited from class java.util.ArrayListclone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, lastIndexOf, removeRange, size, spliterator, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollectioncontainsAllMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, stream, toArrayMethods inherited from interface java.util.ListcontainsAll
- 
Constructor Details- 
HeaderListpublic HeaderList()Constructor.
- 
HeaderListCopy constructor.- Parameters:
- copyFrom- The bean to copy.
 
 
- 
- 
Method Details- 
createInstantiates a new list.- Returns:
- A new list.
 
- 
ofCreates a newHeaderListinitialized with the specified headers.- Parameters:
- headers- The headers to add to the list.
 Can be- null .- null entries are ignored.
- Returns:
- A new unmodifiable instance, never null .
 
- 
ofCreates a newHeaderListinitialized with the specified headers.- Parameters:
- headers- The headers to add to the list.- null entries are ignored.
- Returns:
- A new unmodifiable instance, never null .
 
- 
ofPairsCreates a newHeaderListinitialized with the specified name/value pairs.ExampleHeaderList headers = HeaderList.ofPairs ("Accept" ,"text/xml" ,"Content-Type" ,"text/xml" );- Parameters:
- pairs- Initial list of pairs.
 Must be an even number of parameters representing key/value pairs.
- Returns:
- A new instance.
- Throws:
- RuntimeException- If odd number of parameters were specified.
 
- 
copyMakes a copy of this list.- Returns:
- A new copy of this list.
 
- 
setDefaultAdds a collection of default headers.Default headers are set if they're not already in the list. - Parameters:
- headers- The list of default headers.
- Returns:
- This object.
 
- 
setDefaultReplaces the first occurrence of the headers with the same name.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
setDefaultReplaces the first occurrence of the headers with the same name.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
setDefaultMakes a copy of this list of headers and adds a collection of default headers.Default headers are set if they're not already in the list. - Parameters:
- headers- The list of default headers.
- Returns:
- A new list, or the same list if the headers were empty.
 
- 
resolvingAllows header values to contain SVL variables.Resolves variables in header values when using the following methods: - append(String,Object)
- append(String,Supplier<?>)
- prepend(String,Object)
- prepend(String,Supplier<?>)
- set(String,Object)
- set(String,Supplier<?>)
 Uses VarResolver.DEFAULTto resolve variables.- Returns:
- This object.
 
- 
resolvingAllows header values to contain SVL variables.Resolves variables in header values when using the following methods: - Parameters:
- varResolver- The variable resolver to use for resolving variables.
- Returns:
- This object.
 
- 
caseSensitiveSpecifies that the headers in this list should be treated as case-sensitive.The default behavior is case-insensitive. - Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
appendAdds the specified header to the end of the headers in this list.- Parameters:
- value- The header to add.- null values are ignored.
- Returns:
- This object.
 
- 
appendAppends the specified header to the end of this list.The header is added as a BasicHeader.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
appendAppends the specified header to the end of this list using a value supplier.The header is added as a BasicHeader.Value is re-evaluated on each call to BasicHeader.getValue().- Parameters:
- name- The header name.
- value- The header value supplier.
- Returns:
- This object.
 
- 
appendAdds the specified headers to the end of the headers in this list.- Parameters:
- values- The headers to add.- null values are ignored.
- Returns:
- This object.
 
- 
appendAdds the specified headers to the end of the headers in this list.- Parameters:
- values- The headers to add.- null values are ignored.
- Returns:
- This object.
 
- 
prependAdds the specified header to the beginning of the headers in this list.- Parameters:
- value- The header to add.- null values are ignored.
- Returns:
- This object.
 
- 
prependAppends the specified header to the beginning of this list.The header is added as a BasicHeader.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
prependAppends the specified header to the beginning of this list using a value supplier.The header is added as a BasicHeader.Value is re-evaluated on each call to BasicHeader.getValue().- Parameters:
- name- The header name.
- value- The header value supplier.
- Returns:
- This object.
 
- 
prependAdds the specified headers to the beginning of the headers in this list.- Parameters:
- values- The headers to add.- null values are ignored.
- Returns:
- This object.
 
- 
prependAdds the specified headers to the beginning of the headers in this list.- Parameters:
- values- The headers to add.- null values are ignored.
- Returns:
- This object.
 
- 
removeRemoves the specified header from this list.- Parameters:
- value- The header to remove.- null values are ignored.
- Returns:
- This object.
 
- 
removeRemoves the specified headers from this list.- Parameters:
- values- The headers to remove.- null values are ignored.
- Returns:
- This object.
 
- 
removeRemoves the specified headers from this list.- Parameters:
- values- The headers to remove.- null values are ignored.
- Returns:
- This object.
 
- 
removeRemoves the header with the specified name from this list.- Parameters:
- name- The header name.
- Returns:
- This object.
 
- 
removeRemoves the header with the specified name from this list.- Parameters:
- names- The header name.
- Returns:
- This object.
 
- 
removeAllRemoves all headers from this list.- Returns:
- This object.
 
- 
setAdds or replaces the header(s) with the same name.If no header with the same name is found the given header is added to the end of the list. - Parameters:
- value- The headers to replace.- null values are ignored.
- Returns:
- This object.
 
- 
setAdds or replaces the header(s) with the same name.If no header with the same name is found the given header is added to the end of the list. - Parameters:
- values- The headers to replace.- null values are ignored.
- Returns:
- This object.
 
- 
setReplaces the first occurrence of the headers with the same name.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
setReplaces the first occurrence of the headers with the same name.- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
setReplaces the first occurrence of the headers with the same name.If no header with the same name is found the given header is added to the end of the list. - Parameters:
- values- The headers to replace.- null values are ignored.
- Returns:
- This object.
 
- 
getFirstGets the first header with the given name.Header name comparison is case insensitive. - Parameters:
- name- The header name.
- Returns:
- The first matching header, or Optional.empty()if not found.
 
- 
getLastGets the last header with the given name.Header name comparison is case insensitive. - Parameters:
- name- The header name.
- Returns:
- The last matching header, or Optional.empty()if not found.
 
- 
getGets a header representing all of the header values with the given name.If more that one header with the given name exists the values will be combined with ", " as per RFC 2616 Section 4.2.- Parameters:
- name- The header name.
- Returns:
- A header with a condensed value, or Optional.empty()if no headers by the given name are present
 
- 
getGets a header representing all of the header values with the given name.If more that one header with the given name exists the values will be combined with ", " as per RFC 2616 Section 4.2.The implementation class must have a public constructor taking in one of the following argument lists: - X(String - value )
- X(Object - value )
- X(String - name , String- value )
- X(String - name , Object- value )
 ExampleBasicIntegerHeader age = headerList.get("Age" , BasicIntegerHeader.class );- Type Parameters:
- T- The header implementation class.
- Parameters:
- name- The header name.
- type- The header implementation class.
- Returns:
- A header with a condensed value or null if no headers by the given name are present
 
- 
getGets a header representing all of the header values with the given name.Same as get(String, Class)but the header name is pulled from theHeader.name()orHeader.value()annotations.ExampleAge age = headerList.get(Age.class );- Type Parameters:
- T- The return type.
- Parameters:
- type- The header implementation class.
- Returns:
- A header with a condensed value or null if no headers by the given name are present
 
- 
getAllGets all of the headers.The returned array maintains the relative order in which the headers were added. Each call creates a new array not backed by this list. As a general rule, it's more efficient to use the other methods with consumers to get headers. - Returns:
- An array containing all headers, never null .
 
- 
getAllGets all of the headers with the given name.The returned array maintains the relative order in which the headers were added. Header name comparison is case insensitive. Headers with null values are ignored. Each call creates a new array not backed by this list. As a general rule, it's more efficient to use the other methods with consumers to get headers. - Parameters:
- name- The header name.
- Returns:
- An array containing all matching headers, never null .
 
- 
forEachValuePerforms an action on the values for all matching headers in this list.- Parameters:
- filter- A predicate to apply to each element to determine if it should be included. Can be- null .
- action- An action to perform on each element.
- Returns:
- This object.
 
- 
forEachValuePerforms an action on the values of all matching headers in this list.- Parameters:
- name- The header name.
- action- An action to perform on each element.
- Returns:
- This object.
 
- 
getValuesReturns all the string values for all headers with the specified name.- Parameters:
- name- The header name.
- Returns:
- An array containing all values.  Never null .
 
- 
containsTests if headers with the given name are contained within this list.Header name comparison is case insensitive. - Parameters:
- name- The header name.
- Returns:
- true if at least one header with the name is present.
 
- 
headerIteratorReturns an iterator over this list of headers.- Returns:
- A new iterator over this list of headers.
 
- 
headerIteratorReturns an iterator over the headers with a given name in this list.- Parameters:
- name- The name of the headers over which to iterate, or- null for all headers
- Returns:
- A new iterator over the matching headers in this list.
 
- 
forEachPerforms an action on all headers with the specified name in this list.This is the preferred method for iterating over headers as it does not involve creation or copy of lists/arrays. - Parameters:
- name- The header name.
- action- An action to perform on each element.
- Returns:
- This object.
 
- 
forEachPerforms an action on all matching headers in this list.This is the preferred method for iterating over headers as it does not involve creation or copy of lists/arrays. - Parameters:
- filter- A predicate to apply to each element to determine if it should be included. Can be- null .
- action- An action to perform on each element.
- Returns:
- This object.
 
- 
streamReturns a stream of the headers in this list with the specified name.This does not involve a copy of the underlying array of Header objects so should perform well.- Parameters:
- name- The header name.
- Returns:
- This object.
 
- 
toString- Overrides:
- toStringin class- AbstractCollection<Header>
 
- 
setUnmodifiableDescription copied from class:ControlledArrayListSpecifies whether this bean should be unmodifiable.When enabled, attempting to set any properties on this bean will cause an UnsupportedOperationException.- Overrides:
- setUnmodifiablein class- ControlledArrayList<Header>
- Returns:
- This object.
 
 
-