org.apache.http.message

## Class BasicListHeaderIterator

- java.lang.Object
- - org.apache.http.message.BasicListHeaderIterator

- All Implemented Interfaces:
    Iterator<Object>, HeaderIterator

      @NotThreadSafe
      public class BasicListHeaderIterator
      extends Object
      implements HeaderIterator

  Implementation of a `HeaderIterator` based on a `List`. For use by `HeaderGroup`.
  Since:
    4.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected List<Header>` | `allHeaders` A list of headers to iterate over.
    `protected int` | `currentIndex` The position of the next header in `allHeaders`.
    `protected String` | `headerName` The header name to filter by.
    `protected int` | `lastIndex` The position of the last returned header.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicListHeaderIterator(List<Header> headers, String name)` Creates a new header iterator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected 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.
    `Object` | `next()` Returns the next header.
    `Header` | `nextHeader()` Obtains the next header from this iteration.
    `void` | `remove()` Removes the header that was returned last.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### allHeaders

          protected final 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 in `allHeaders`. 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 String headerName

      The header name to filter by. `null` to iterate over all headers in the array.

  - ### Constructor Detail

    - #### BasicListHeaderIterator

          public BasicListHeaderIterator(List<Header> headers,
                                 String name)

      Creates a new header iterator.
      Parameters:
        `headers` - a list of headers over which to iterate
        `name` - the name of the headers over which to iterate, or `null` for 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:
        `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 interface `Iterator<Object>`
      Specified by:
        `hasNext` in interface `HeaderIterator`
      Returns:
        `true` if there is another header, `false` otherwise

    - #### nextHeader

          public Header nextHeader()
                            throws NoSuchElementException

      Obtains the next header from this iteration.
      Specified by:
        `nextHeader` in interface `HeaderIterator`
      Returns:
        the next header in this iteration
      Throws:
        `NoSuchElementException` - if there are no more headers

    - #### next

          public final Object next()
                            throws NoSuchElementException

      Returns the next header. Same as `nextHeader`, but not type-safe.
      Specified by:
        `next` in interface `Iterator<Object>`
      Returns:
        the next header in this iteration
      Throws:
        `NoSuchElementException` - if there are no more headers

    - #### remove

          public void remove()
                      throws UnsupportedOperationException

      Removes the header that was returned last.
      Specified by:
        `remove` in interface `Iterator<Object>`
      Throws:
        `UnsupportedOperationException`

Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.