1/****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one   *
3 * or more contributor license agreements.  See the NOTICE file *
4 * distributed with this work for additional information        *
5 * regarding copyright ownership.  The ASF licenses this file   *
6 * to you under the Apache License, Version 2.0 (the            *
7 * "License"); you may not use this file except in compliance   *
8 * with the License.  You may obtain a copy of the License at   *
9 *                                                              *
10 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11 *                                                              *
12 * Unless required by applicable law or agreed to in writing,   *
13 * software distributed under the License is distributed on an  *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15 * KIND, either express or implied.  See the License for the    *
16 * specific language governing permissions and limitations      *
17 * under the License.                                           *
18 ****************************************************************/
19
20package org.apache.james.mime4j.field.address;
21
22import java.util.ArrayList;
23
24/**
25 * An immutable, random-access list of Mailbox objects.
26 *
27 *
28 */
29public class MailboxList {
30
31	private ArrayList<Address> mailboxes;
32
33	/**
34	 * @param mailboxes An ArrayList that contains only Mailbox objects.
35	 * @param dontCopy true iff it is not possible for the mailboxes ArrayList to be modified by someone else.
36	 */
37	public MailboxList(ArrayList<Address> mailboxes, boolean dontCopy) {
38		if (mailboxes != null)
39			this.mailboxes = (dontCopy ? mailboxes : new ArrayList<Address>(mailboxes));
40		else
41			this.mailboxes = new ArrayList<Address>(0);
42	}
43
44	/**
45	 * The number of elements in this list.
46	 */
47	public int size() {
48		return mailboxes.size();
49	}
50
51	/**
52	 * Gets an address.
53	 */
54	public Mailbox get(int index) {
55		if (0 > index || size() <= index)
56			throw new IndexOutOfBoundsException();
57		return (Mailbox)mailboxes.get(index);
58	}
59
60	/**
61	 * Dumps a representation of this mailbox list to
62	 * stdout, for debugging purposes.
63	 */
64	public void print() {
65		for (int i = 0; i < size(); i++) {
66			Mailbox mailbox = get(i);
67			System.out.println(mailbox.toString());
68		}
69	}
70
71}
72