FileDocCategorySizeDatePackage
BasicHeaderIterator.javaAPI DocAndroid 1.5 API5354Wed May 06 22:41:10 BST 2009org.apache.http.message

BasicHeaderIterator

public class BasicHeaderIterator extends Object implements HeaderIterator
Basic implementation of a {@link HeaderIterator}.
version
$Revision: 581981 $

Fields Summary
protected final Header[]
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.
protected int
currentIndex
The position of the next header in {@link #allHeaders allHeaders}. Negative if the iteration is over.
protected String
headerName
The header name to filter by. null to iterate over all headers in the array.
Constructors Summary
public BasicHeaderIterator(Header[] headers, String name)
Creates a new header iterator.

param
headers an array of headers over which to iterate
param
name the name of the headers over which to iterate, or null for any

        if (headers == null) {
            throw new IllegalArgumentException
                ("Header array must not be null.");
        }

        this.allHeaders = headers;
        this.headerName = name;
        this.currentIndex = findNext(-1);
    
Methods Summary
protected booleanfilterHeader(int index)
Checks whether a header is part of the iteration.

param
index the index of the header to check
return
true if the header should be part of the iteration, false to skip

        return (this.headerName == null) ||
            this.headerName.equalsIgnoreCase(this.allHeaders[index].getName());
    
protected intfindNext(int from)
Determines the index of the next header.

param
from one less than the index to consider first, -1 to search for the first header
return
the index of the next header that matches the filter name, or negative if there are no more headers

        if (from < -1)
            return -1;

        final int to = this.allHeaders.length-1;
        boolean found = false;
        while (!found && (from < to)) {
            from++;
            found = filterHeader(from);
        }
        return found ? from : -1;
    
public booleanhasNext()

        return (this.currentIndex >= 0);
    
public final java.lang.Objectnext()
Returns the next header. Same as {@link #nextHeader nextHeader}, but not type-safe.

return
the next header in this iteration
throws
NoSuchElementException if there are no more headers

        return nextHeader();
    
public org.apache.http.HeadernextHeader()
Obtains the next header from this iteration.

return
the next header in this iteration
throws
NoSuchElementException if there are no more headers


        final int current = this.currentIndex;
        if (current < 0) {
            throw new NoSuchElementException("Iteration already finished.");
        }

        this.currentIndex = findNext(current);

        return this.allHeaders[current];
    
public voidremove()
Removing headers is not supported.

throws
UnsupportedOperationException always


        throw new UnsupportedOperationException
            ("Removing headers is not supported.");