[6785] | 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 | |
---|
| 20 | package org.apache.james.mime4j.dom.address; |
---|
| 21 | |
---|
| 22 | import java.util.ArrayList; |
---|
| 23 | import java.util.Arrays; |
---|
| 24 | import java.util.Collection; |
---|
| 25 | import java.util.List; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * A named group of zero or more mailboxes. |
---|
| 29 | */ |
---|
| 30 | public class Group extends Address { |
---|
| 31 | |
---|
| 32 | private static final long serialVersionUID = 1L; |
---|
| 33 | |
---|
| 34 | private final String name; |
---|
| 35 | private final MailboxList mailboxList; |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * @param name |
---|
| 39 | * The group name. |
---|
| 40 | * @param mailboxes |
---|
| 41 | * The mailboxes in this group. |
---|
| 42 | */ |
---|
| 43 | public Group(String name, MailboxList mailboxes) { |
---|
| 44 | if (name == null) |
---|
| 45 | throw new IllegalArgumentException(); |
---|
| 46 | if (mailboxes == null) |
---|
| 47 | throw new IllegalArgumentException(); |
---|
| 48 | |
---|
| 49 | this.name = name; |
---|
| 50 | this.mailboxList = mailboxes; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * @param name |
---|
| 55 | * The group name. |
---|
| 56 | * @param mailboxes |
---|
| 57 | * The mailboxes in this group. |
---|
| 58 | */ |
---|
| 59 | public Group(String name, Mailbox... mailboxes) { |
---|
| 60 | this(name, new MailboxList(Arrays.asList(mailboxes), true)); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * @param name |
---|
| 65 | * The group name. |
---|
| 66 | * @param mailboxes |
---|
| 67 | * The mailboxes in this group. |
---|
| 68 | */ |
---|
| 69 | public Group(String name, Collection<Mailbox> mailboxes) { |
---|
| 70 | this(name, new MailboxList(new ArrayList<Mailbox>(mailboxes), true)); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * Returns the group name. |
---|
| 75 | */ |
---|
| 76 | public String getName() { |
---|
| 77 | return name; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Returns the mailboxes in this group. |
---|
| 82 | */ |
---|
| 83 | public MailboxList getMailboxes() { |
---|
| 84 | return mailboxList; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | @Override |
---|
| 88 | protected void doAddMailboxesTo(List<Mailbox> results) { |
---|
| 89 | for (Mailbox mailbox : mailboxList) { |
---|
| 90 | results.add(mailbox); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | @Override |
---|
| 95 | public String toString() { |
---|
| 96 | StringBuilder sb = new StringBuilder(); |
---|
| 97 | sb.append(name); |
---|
| 98 | sb.append(':'); |
---|
| 99 | boolean first = true; |
---|
| 100 | for (Mailbox mailbox : mailboxList) { |
---|
| 101 | if (first) { |
---|
| 102 | first = false; |
---|
| 103 | } else { |
---|
| 104 | sb.append(','); |
---|
| 105 | } |
---|
| 106 | sb.append(' '); |
---|
| 107 | sb.append(mailbox); |
---|
| 108 | } |
---|
| 109 | sb.append(";"); |
---|
| 110 | return sb.toString(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | } |
---|