Package org.apache.http.message
Class BasicHeaderIterator
java.lang.Object
org.apache.http.message.BasicHeaderIterator
- All Implemented Interfaces:
Iterator<Object>
,HeaderIterator
Basic implementation of a
HeaderIterator
.- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Header[]
An array of headers to iterate over.protected int
The position of the next header inallHeaders
.protected String
The header name to filter by. -
Constructor Summary
ConstructorsConstructorDescriptionBasicHeaderIterator
(Header[] headers, String name) Creates a new header iterator. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
filterHeader
(int index) Checks whether a header is part of the iteration.protected int
findNext
(int pos) Determines the index of the next header.boolean
hasNext()
Indicates whether there is another header in this iteration.final Object
next()
Returns the next header.Obtains the next header from this iteration.void
remove()
Removing headers is not supported.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
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.null
to 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, ornull
for any
-
-
Method Details
-
findNext
protected int findNext(int pos) Determines the index of the next header.- Parameters:
pos
- 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:
true
if the header should be part of the iteration,false
to skip
-
hasNext
public boolean hasNext()Description copied from interface:HeaderIterator
Indicates whether there is another header in this iteration.- Specified by:
hasNext
in interfaceHeaderIterator
- Specified by:
hasNext
in interfaceIterator<Object>
- Returns:
true
if there is another header,false
otherwise
-
nextHeader
Obtains the next header from this iteration.- Specified by:
nextHeader
in 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:
next
in interfaceIterator<Object>
- Returns:
- the next header in this iteration
- Throws:
NoSuchElementException
- if there are no more headers
-
remove
Removing headers is not supported.- Specified by:
remove
in interfaceIterator<Object>
- Throws:
UnsupportedOperationException
- always
-