1 /*
2 * (C) 2002 David Carr david@carr.name
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 package net.sourceforge.mflow.impl;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import net.sourceforge.mflow.api.Contact;
26 import net.sourceforge.mflow.api.ContactGroup;
27
28 /***
29 * A collection of Contacts, with an optional name
30 *
31 * @author <a href="mailto:david@carr.name">David Carr</a>
32 * @version $Revision: 1.4 $
33 * @todo remove extension of arraylist
34 */
35 public class ContactGroupImpl implements ContactGroup {
36 private String name;
37 private List contacts;
38 private List groups;
39
40 /***
41 * Default constructor, no name set
42 */
43 ContactGroupImpl() {
44 this("");
45 }
46
47 /***
48 * Constructor to set the inital name
49 *
50 * @param name the initial name
51 */
52 ContactGroupImpl(String name) {
53 this.name = name;
54 this.contacts = new ArrayList();
55 this.groups = new ArrayList();
56 }
57
58 /***
59 * Accessor for the name
60 *
61 * @return the name
62 */
63 public String getName() {
64 return this.name;
65 }
66
67 /***
68 * Mutator for the name
69 *
70 * @param name the new name
71 */
72 public void setName(String name) {
73 this.name = name;
74 }
75
76 public boolean add(Contact c) {
77 if (c == null) {
78 return false;
79 }
80 if (!this.contacts.contains(c)) {
81 this.contacts.add(c);
82 return true;
83 } else {
84 return false;
85 }
86 }
87
88 public boolean add(ContactGroup cg) {
89 if (cg == null) {
90 return false;
91 }
92 if (!this.groups.contains(cg)) {
93 this.groups.add(cg);
94 return true;
95 } else {
96 return false;
97 }
98 }
99
100 public boolean addAll(List list) {
101 if (list == null) {
102 return false;
103 }
104 boolean changed = false;
105 for (Iterator it = list.iterator(); it.hasNext();) {
106 Object o = it.next();
107 if (o instanceof ContactGroup) {
108 if (add((ContactGroup) o)) {
109 changed = true;
110 }
111 } else if (o instanceof Contact) {
112 if (add((Contact) o)) {
113 changed = true;
114 }
115 }
116 }
117 return changed;
118 }
119
120 /***
121 * Converts this ContactGroup into a String form
122 *
123 * @return a String representation of this ContactGroup
124 */
125 public String toString() {
126 return this.name
127 + ": "
128 + this.groups.toString()
129 + " "
130 + this.contacts.toString();
131 }
132
133 public Contact[] getContacts() {
134 return (Contact[]) this.contacts.toArray(new Contact[this.contacts.size()]);
135 }
136
137 public ContactGroup[] getGroups() {
138 return (ContactGroup[]) this.groups.toArray(
139 new ContactGroup[this.groups.size()]);
140 }
141
142 public int size() {
143 return this.contacts.size() + this.groups.size();
144 }
145 }
This page was automatically generated by Maven