com.hunnysoft.jmime
Class AddressList

java.lang.Object
  extended bycom.hunnysoft.jmime.Node
      extended bycom.hunnysoft.jmime.FieldBody
          extended bycom.hunnysoft.jmime.AddressList
All Implemented Interfaces:
java.lang.Cloneable

public class AddressList
extends FieldBody

Class that represents a list of RFC 2822 mail addresses.

AddressList represents a list of mail addresses as described in RFC 2822. In Hunny JMIME, AddressList is a container for objects of type Address, and it contains various methods to manage its contained objects. AddressList is also a FieldBody. This reflects the fact that certain RFC 2822 header fields, such as the "To" header field, have a list of addresses as their field bodies.


Field Summary
 
Fields inherited from class com.hunnysoft.jmime.FieldBody
mText
 
Fields inherited from class com.hunnysoft.jmime.Node
mIsModified, mParent, mString
 
Constructor Summary
AddressList()
          Default constructor.
AddressList(AddressList other)
          Copy constructor.
AddressList(ByteString bstr)
          Constructor that takes an initial byte string argument.
 
Method Summary
 void addAddress(Address address)
          Adds an address to the end of the list.
 Address addressAt(int index)
          Gets the address at the specified position.
 void assemble()
          Assembles the string representation.
 java.lang.Object clone()
          Creates a copy of this object.
 void deleteAllAddresses()
          Deletes all addresses in the list.
 void insertAddressAt(int index, Address address)
          Inserts an address at the specified position.
 int numAddresses()
          Gets the number of addresses in the list.
 void parse()
          Parses the string representation.
 Address removeAddressAt(int index)
          Removes the address at the specified position.
 
Methods inherited from class com.hunnysoft.jmime.FieldBody
fold, isFoldingEnabled, maybeFold, setFoldingEnabled, setText, text, unfold
 
Methods inherited from class com.hunnysoft.jmime.Node
_setString, isModified, parent, setModified, setParent, setString, string, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AddressList

public AddressList()
Default constructor.

This constructor sets the AddressList object's string representation to the empty string and sets its parent node to null. The list of Address objects is initially empty.


AddressList

public AddressList(AddressList other)
Copy constructor.

This constructor performs a deep copy of its argument. The parent node of the new AddressList object is set to null.

Parameters:
other - AddressList instance to copy

AddressList

public AddressList(ByteString bstr)
Constructor that takes an initial byte string argument.

This constructor sets the AddressList object's string representation to bstr and sets its parent node to null.

Normally, you call the parse() method immediately after this constructor to create the broken-down representation.

Parameters:
bstr - initial value for the string representation
Method Detail

clone

public java.lang.Object clone()
Creates a copy of this object.

This method, inherited from Object, creates a new AddressList object that has the same value as this AddressList object. The parent node of the new AddressList object is set to null.

Overrides:
clone in class FieldBody
Returns:
a copy of this object

parse

public void parse()
Parses the string representation.

This method, inherited from Node, executes the parse operation for AddressList objects. The parse operation creates or updates the broken-down representation from the string representation. For AddressList objects, the parse operation parses the string representation to create a list of Address objects. This method also calls the parse() method of each Address object in its list.

You should call this method after you set or modify the string representation, and before you access any of the contained Address objects.

This method clears the is-modified flag.

Overrides:
parse in class FieldBody

assemble

public void assemble()
Assembles the string representation.

This method, inherited from Node, executes the assemble operation for AddressList objects. The assemble operation creates or updates the string representation from the broken-down representation. For AddressList objects, the assemble operation builds the string representation from the list of contained Address objects. Before it builds the string representation for the AddressList object, this method first calls the assemble() method of each Address object in its list.

You should call this method after you set or modify any of the contained Address objects, and before you retrieve the string representation.

This method clears the is-modified flag.

Overrides:
assemble in class FieldBody

numAddresses

public int numAddresses()
Gets the number of addresses in the list.

Returns:
number of addresses in the list

addAddress

public void addAddress(Address address)
Adds an address to the end of the list.

Parameters:
address - Address object to add

deleteAllAddresses

public void deleteAllAddresses()
Deletes all addresses in the list.


addressAt

public Address addressAt(int index)
Gets the address at the specified position.

Parameters:
index - position of the Address object to get (0 <= index < numAddresses())
Returns:
Address object at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range

insertAddressAt

public void insertAddressAt(int index,
                            Address address)
Inserts an address at the specified position.

Inserting at position 0 inserts the address at the beginning. Inserting at position numAddresses() appends the address to the end.

Parameters:
index - position in the list to insert the Address object (0 <= index <= numAddresses())
address - Address object to insert
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range

removeAddressAt

public Address removeAddressAt(int index)
Removes the address at the specified position.

Parameters:
index - position of the Address object to remove (0 <= index < numAddresses())
Returns:
the removed Address object
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range