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
21 package org.apache.james.postage.user;
22
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26
27 /***
28 * collection of all users used for one Postage scenario
29 */
30 public class UserList {
31
32 int m_count = 0;
33 String m_namePrefix = null;
34
35 List m_users = new ArrayList();
36 String m_password = null;
37 String m_domain = null;
38
39 public UserList(int count, String namePrefix, String domain) {
40 m_count = count;
41 m_namePrefix = namePrefix;
42 m_domain = domain;
43 }
44
45 public UserList(int count, String namePrefix, String domain, String password) {
46 this(count, namePrefix, domain);
47 m_password = password;
48 }
49
50 public int getCount() {
51 return m_count;
52 }
53
54 public String getNamePrefix() {
55 return m_namePrefix;
56 }
57
58 public Iterator getUsernames() {
59 return m_users.iterator();
60 }
61
62 public void setExistingUsers(List existingUsers) {
63 m_users.clear();
64 m_users.addAll(existingUsers);
65 }
66
67 public String getPassword() {
68 return m_password;
69 }
70
71 public String getDomain() {
72 return m_domain;
73 }
74
75 public String getRandomUsername() {
76 if (m_users.isEmpty()) return null;
77 return (String)m_users.get((int)(Math.random() * (double)(m_users.size() - 1)));
78 }
79
80 public String getEmailAddress(String username) {
81 return username + "@" + m_domain;
82 }
83 }