Package org.apache.http.message
Class BasicListHeaderIterator
- java.lang.Object
-
- org.apache.http.message.BasicListHeaderIterator
-
- All Implemented Interfaces:
java.util.Iterator<java.lang.Object>,HeaderIterator
public class BasicListHeaderIterator extends java.lang.Object implements HeaderIterator
- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Header>allHeadersA list of headers to iterate over.protected intcurrentIndexThe position of the next header inallHeaders.protected java.lang.StringheaderNameThe header name to filter by.protected intlastIndexThe position of the last returned header.
-
Constructor Summary
Constructors Constructor Description BasicListHeaderIterator(java.util.List<Header> headers, java.lang.String name)Creates a new header iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanfilterHeader(int index)Checks whether a header is part of the iteration.protected intfindNext(int pos)Determines the index of the next header.booleanhasNext()Indicates whether there is another header in this iteration.java.lang.Objectnext()Returns the next header.HeadernextHeader()Obtains the next header from this iteration.voidremove()Removes the header that was returned last.
-
-
-
Field Detail
-
allHeaders
protected final java.util.List<Header> allHeaders
A list of headers to iterate over. Not all elements of this array are necessarily part of the iteration.
-
currentIndex
protected int currentIndex
The position of the next header inallHeaders. Negative if the iteration is over.
-
lastIndex
protected int lastIndex
The position of the last returned header. Negative if none has been returned so far.
-
headerName
protected java.lang.String headerName
The header name to filter by.nullto iterate over all headers in the array.
-
-
Constructor Detail
-
BasicListHeaderIterator
public BasicListHeaderIterator(java.util.List<Header> headers, java.lang.String name)
Creates a new header iterator.- Parameters:
headers- a list of headers over which to iteratename- the name of the headers over which to iterate, ornullfor any
-
-
Method Detail
-
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:
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 interfacejava.util.Iterator<java.lang.Object>- Returns:
trueif there is another header,falseotherwise
-
nextHeader
public Header nextHeader() throws java.util.NoSuchElementException
Obtains the next header from this iteration.- Specified by:
nextHeaderin interfaceHeaderIterator- Returns:
- the next header in this iteration
- Throws:
java.util.NoSuchElementException- if there are no more headers
-
next
public final java.lang.Object next() throws java.util.NoSuchElementExceptionReturns the next header. Same asnextHeader, but not type-safe.- Specified by:
nextin interfacejava.util.Iterator<java.lang.Object>- Returns:
- the next header in this iteration
- Throws:
java.util.NoSuchElementException- if there are no more headers
-
remove
public void remove() throws java.lang.UnsupportedOperationExceptionRemoves the header that was returned last.- Specified by:
removein interfacejava.util.Iterator<java.lang.Object>- Throws:
java.lang.UnsupportedOperationException
-
-