Package org.apache.http.message
Class BasicHeaderIterator
java.lang.Object
org.apache.http.message.BasicHeaderIterator
- All Implemented Interfaces:
Iterator,HeaderIterator
public class BasicHeaderIterator extends Object implements HeaderIterator
Basic implementation of a
HeaderIterator.- Version:
- $Revision: 581981 $
-
Field Summary
Fields Modifier and Type Field Description protected Header[]allHeadersAn array of headers to iterate over.protected intcurrentIndexThe position of the next header inallHeaders.protected StringheaderNameThe header name to filter by. -
Constructor Summary
Constructors Constructor Description BasicHeaderIterator(Header[] headers, String name)Creates a new header iterator. -
Method Summary
Modifier and Type Method Description protected booleanfilterHeader(int index)Checks whether a header is part of the iteration.protected intfindNext(int from)Determines the index of the next header.booleanhasNext()Indicates whether there is another header in this iteration.Objectnext()Returns the next header.HeadernextHeader()Obtains the next header from this iteration.voidremove()Removing headers is not supported.
-
Field Details
-
allHeaders
An array of headers to iterate over. Not all elements of this array are necessarily part of the iteration. This array will never be modified by the iterator. Derived implementations are expected to adhere to this restriction. -
currentIndex
protected int currentIndexThe position of the next header inallHeaders. Negative if the iteration is over. -
headerName
The header name to filter by.nullto iterate over all headers in the array.
-
-
Constructor Details
-
BasicHeaderIterator
Creates a new header iterator.- Parameters:
headers- an array of headers over which to iteratename- the name of the headers over which to iterate, ornullfor any
-
-
Method Details
-
findNext
protected int findNext(int from)Determines the index of the next header.- Parameters:
from- one less than the index to consider first, -1 to search for the first header- Returns:
- the index of the next header that matches the filter name, or negative if there are no more headers
-
filterHeader
protected boolean filterHeader(int index)Checks whether a header is part of the iteration.- Parameters:
index- the index of the header to check- Returns:
trueif the header should be part of the iteration,falseto skip
-
hasNext
public boolean hasNext()Description copied from interface:HeaderIteratorIndicates whether there is another header in this iteration.- Specified by:
hasNextin interfaceHeaderIterator- Specified by:
hasNextin interfaceIterator- Returns:
trueif there is another header,falseotherwise- See Also:
Iterator.next()
-
nextHeader
Obtains the next header from this iteration.- Specified by:
nextHeaderin interfaceHeaderIterator- Returns:
- the next header in this iteration
- Throws:
NoSuchElementException- if there are no more headers
-
next
Returns the next header. Same asnextHeader, but not type-safe.- Specified by:
nextin interfaceIterator- Returns:
- the next header in this iteration
- Throws:
NoSuchElementException- if there are no more headers- See Also:
Iterator.hasNext()
-
remove
Removing headers is not supported.- Specified by:
removein interfaceIterator- Throws:
UnsupportedOperationException- always
-