Package org.apache.james.mime4j.message
Class AbstractHeader
- java.lang.Object
-
- org.apache.james.mime4j.message.AbstractHeader
-
-
Constructor Summary
Constructors Constructor Description AbstractHeader()
Creates a new emptyHeader
.AbstractHeader(Header other)
Creates a newHeader
from the specifiedHeader
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addField(Field field)
Adds a field to the end of the list of fields.Field
getField(String name)
Gets aField
given a field name.<F extends Field>
FgetField(String name, Class<F> clazz)
Gets aField
given a field name and of the given type.List<Field>
getFields()
Gets the fields of this header.List<Field>
getFields(String name)
Gets allField
s having the specified field name.<F extends Field>
List<F>getFields(String name, Class<F> clazz)
Gets allField
s having the specified field name and of the given type.Map<String,List<Field>>
getFieldsAsMap()
Gets the fields of this header.Iterator<Field>
iterator()
Returns an iterator over the list of fields of this header.int
removeFields(String name)
Removes allField
s having the specified field name.void
setField(Field field)
Sets or replaces a field.String
toString()
Return Header Object as String representation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AbstractHeader
public AbstractHeader()
Creates a new emptyHeader
.
-
AbstractHeader
public AbstractHeader(Header other)
Creates a newHeader
from the specifiedHeader
. TheHeader
instance is initialized with a copy of the list ofField
s of the specifiedHeader
. TheField
objects are not copied because they are immutable and can safely be shared between headers.- Parameters:
other
- header to copy.
-
-
Method Detail
-
addField
public void addField(Field field)
Adds a field to the end of the list of fields.
-
getFields
public List<Field> getFields()
Gets the fields of this header. The returned list will not be modifiable.
-
getFieldsAsMap
public Map<String,List<Field>> getFieldsAsMap()
Gets the fields of this header. The returned map will not be modifiable. For each header name, values are ordered by which they appear in the underlying entity.- Specified by:
getFieldsAsMap
in interfaceHeader
- Returns:
- the map of
Field
objects indexed by names.
-
getField
public Field getField(String name)
Gets aField
given a field name. If there are multiple such fields defined in this header the first one will be returned.
-
getField
public <F extends Field> F getField(String name, Class<F> clazz)
Gets aField
given a field name and of the given type. If there are multiple such fields defined in this header the first one will be returned.
-
getFields
public List<Field> getFields(String name)
Gets allField
s having the specified field name.
-
getFields
public <F extends Field> List<F> getFields(String name, Class<F> clazz)
Gets allField
s having the specified field name and of the given type.
-
iterator
public Iterator<Field> iterator()
Returns an iterator over the list of fields of this header.
-
removeFields
public int removeFields(String name)
Removes allField
s having the specified field name.- Specified by:
removeFields
in interfaceHeader
- Parameters:
name
- the field name (e.g. From, Subject).- Returns:
- number of fields removed.
-
setField
public void setField(Field field)
Sets or replaces a field. This method is useful for header fields such as Subject or Message-ID that should not occur more than once in a message. If thisHeader
does not already contain a header field of the same name as the given field then it is added to the end of the list of fields (same behavior asaddField(Field)
). Otherwise the first occurrence of a field with the same name is replaced by the given field and all further occurrences are removed.
-
-