org.jgroups.util

## Class Headers

- java.lang.Object
- - org.jgroups.util.Headers

    public class Headers
    extends java.lang.Object

Open addressing based implementation of a hashmap (not supporting the Map interface though) for message headers. The keys are shorts (IDs) and the values Headers, and they're stored in 2 arrays: an ID array and a headers array. The indices of the IDs array corespond with the headers array, e.g.

     IDs:      id-1  | id-2  | id-3  | ... | id-n |
     Headers:  hdr-1 | hdr-2 | hdr-3 | ... | hdr-n |

The arrays are populated from left to right, and any 0 slots in 'ids' can terminate an interation, or signal empty slots.
It is assumed that we only have a few headers, 3-4 on average. Note that getting a header for a given key and putting a new key/header are operations with O(n) cost, so this implementation is not recommended for a large number of elements.
This class is not synchronized

Author:
  Bela Ban

### Constructor Summary

Constructors
Constructor and Description
`Headers(Headers other)`
`Headers(int capacity)`

### Method Summary

Methods
`int` `capacity()`
`Headers` `copy()`
`Header` `getHeader(short id)` Returns the header associated with an ID
`java.util.Map<java.lang.Short,Header>` `getHeaders()`
`Header[]` `getRawHeaders()`
`short[]` `getRawIDs()`
`int` `marshalledSize()`
`java.lang.String` `printHeaders()`
`java.lang.String` `printObjectHeaders()`
`void` `putHeader(short id, Header hdr)` Puts a header given a key into the hashmap.
`Header` `putHeaderIfAbsent(short id, Header hdr)` Puts a header given a key into the map, only if the key doesn't exist yet
`Header` `removeHeader(short id)` Deprecated. Use getHeader() instead. The issue with removing a header is described in http://jira.jboss.com/jira/browse/JGRP-393
`int` `size()`
`java.lang.String` `toString()`

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

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

### Constructor Detail

#### Headers

    public Headers(int capacity)

#### Headers

    public Headers(Headers other)

### Method Detail

#### getRawIDs

    public short[] getRawIDs()

#### getRawHeaders

    public Header[] getRawHeaders()

#### getHeader

    public Header getHeader(short id)

Returns the header associated with an ID

Parameters:
  `id` - The ID
Returns:

#### getHeaders

    public java.util.Map<java.lang.Short,Header> getHeaders()

#### printHeaders

    public java.lang.String printHeaders()

#### putHeader

    public void putHeader(short id,
                 Header hdr)

Puts a header given a key into the hashmap. Overwrites potential existing entry.

#### putHeaderIfAbsent

    public Header putHeaderIfAbsent(short id,
                           Header hdr)

Puts a header given a key into the map, only if the key doesn't exist yet

Parameters:
  `id` -
  `hdr` -
Returns:
  the previous value associated with the specified id, or `null` if there was no mapping for the id. (A `null` return can also indicate that the map previously associated `null` with the id, if the implementation supports null values.)

#### removeHeader

    public Header removeHeader(short id)

Deprecated. Use getHeader() instead. The issue with removing a header is described in http://jira.jboss.com/jira/browse/JGRP-393

Parameters:
  `id` -
Returns:
  the header associated with key

#### copy

    public Headers copy()

#### marshalledSize

    public int marshalledSize()

#### size

    public int size()

#### capacity

    public int capacity()

#### printObjectHeaders

    public java.lang.String printObjectHeaders()

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`