Package 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 strings and the values Headers, and they're stored in an array in the format key-1 | header-1 | key-2 | header-2. The array is populated from left to right, so any null slots 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- Version:
- $Id: Headers.java,v 1.11.2.5 2008/07/31 12:55:23 belaban Exp $
- Author:
- Bela Ban
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
capacity()
Headers
copy()
Header
getHeader(java.lang.String key)
Returns the header associated with keyjava.util.Map<java.lang.String,Header>
getHeaders()
java.lang.Object[]
getRawData()
int
marshalledSize()
java.lang.String
printHeaders()
java.lang.String
printObjectHeaders()
void
putHeader(java.lang.String key, Header hdr)
Puts a header given a key into the hashmap.Header
putHeaderIfAbsent(java.lang.String key, Header hdr)
Puts a header given a key into the map, only if the key doesn't exist yetHeader
removeHeader(java.lang.String key)
Deprecated.Use getHeader() instead.int
size()
java.lang.String
toString()
-
-
-
Constructor Detail
-
Headers
public Headers(int initial_capacity)
-
Headers
public Headers(Headers hdrs)
-
-
Method Detail
-
getRawData
public java.lang.Object[] getRawData()
-
getHeader
public Header getHeader(java.lang.String key)
Returns the header associated with key- Parameters:
key
-- Returns:
-
getHeaders
public java.util.Map<java.lang.String,Header> getHeaders()
-
printHeaders
public java.lang.String printHeaders()
-
putHeader
public void putHeader(java.lang.String key, Header hdr)
Puts a header given a key into the hashmap. Overwrites potential existing entry.
-
putHeaderIfAbsent
public Header putHeaderIfAbsent(java.lang.String key, Header hdr)
Puts a header given a key into the map, only if the key doesn't exist yet- Parameters:
key
-hdr
-- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
-
removeHeader
public Header removeHeader(java.lang.String key)
Deprecated.Use getHeader() instead. The issue with removing a header is described in http://jira.jboss.com/jira/browse/JGRP-393- Parameters:
key
-- Returns:
- the header assoaicted 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 classjava.lang.Object
-
-