Newer
Older
import exceptions.CategoryInvalidException;
import exceptions.LoginInvalidException;
import exceptions.MailInvalidException;
import exceptions.PasswordInvalidException;
import exceptions.TitleInvalidException;
import exceptions.UsernameEmailEmptyException;
static int idCounter;
public static ArrayList<User> users = new ArrayList<User>();
private ArrayList<Item> myItem = new ArrayList<Item>();
private int id;
private String username, email, password;
this.id = idCounter++;
users.add(this);
public User(String usernameInput, String mailInput, String passwordInput) {
username = usernameInput;
email = mailInput;
password = passwordInput;
this.id = idCounter++;
users.add(this);
}
User u = new User();
return u;
public static boolean login(String username, String email, String password)
throws UsernameEmailEmptyException, PasswordInvalidException, MailInvalidException, LoginInvalidException {
if (username.equals("") && email.equals("")) {
throw new UsernameEmailEmptyException();
} else {
if (password.equals("")) {
throw new PasswordInvalidException();
} else if (!username.equals("")) {
User toCheck = null;
for (User u : users) {
if (u.username.equals(username)) {
toCheck = u;
}
}
if (toCheck == null) {
throw new LoginInvalidException();
if (password.equals(toCheck.password)) {
return true;
} else {
throw new LoginInvalidException();
}
} else if (!email.equals("usr@mail.com")) {
throw new MailInvalidException();
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
User toCheck = null;
for (User u : users) {
if (u.email.equals(email)) {
toCheck = u;
}
}
if (toCheck == null) {
throw new LoginInvalidException();
} else {
if (password.equals(toCheck.password)) {
return true;
} else {
throw new LoginInvalidException();
}
}
public ArrayList<Auction> retrieveSubscribedAuction() {
// TODO Auto-generated method stub
return null;
}
public boolean becomeSeller(String ssn) {
// TODO Auto-generated method stub
return false;
}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
public ArrayList<Item> searchItem(String title, String category)
throws CategoryInvalidException, TitleInvalidException {
if (!title.matches("^[a-zA-Z]+$") || title.length() > 30) {
throw new TitleInvalidException();
} else {
Category c = Category.getCategory(category);
if (c == null) {
throw new CategoryInvalidException();
} else {
ArrayList<Item> toReturn = new ArrayList<Item>();
for (Item i : Item.items) {
if (i.getTitle().equals(title) || i.getCategory().equals(c)) {
toReturn.add(i);
}
}
return toReturn;
}
}
}
public boolean searchAuction(String startTime, String endTime, double price, double bidIncrement, String title,
Category category) {
// TODO Auto-generated method stub
return false;
}
public boolean addItem(int itemId) {
if (myItem.contains(Item.getItem(itemId))) {
return myItem.add(Item.getItem(itemId));
}
return false;
}
public void setId(int i) {
this.id = i;
}
public int getId() {
// TODO Auto-generated method stub
return id;
}
public void setUsername(String usernameInput) {
this.username = usernameInput;
}
public void setEmail(String emailInput) {
this.email = emailInput;
}
public void setPassword(String passwordInput) {
this.password = passwordInput;
}