-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeller.java
More file actions
84 lines (70 loc) · 2.27 KB
/
Copy pathSeller.java
File metadata and controls
84 lines (70 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.io.Serializable;
import java.util.Random;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Seller implements Serializable{
private String email;
private int userId;
private Map<Integer, AuctionItem> sellings; // <auction_id, auction_item>
public Seller(String email) {
this.email = email;
userId = new Random().nextInt(100000);
System.out.println("userID generated: " + userId);
sellings = new HashMap<>();
}
public String enlistSellings() {
System.out.println("enlisting auctions..");
StringBuilder sb = new StringBuilder();
for (Integer auctionId : sellings.keySet()) {
if (!sellings.get(auctionId).isClosed()) {
sb.append(sellings.get(auctionId));
}
}
return sb.toString();
}
public void enlistSellingsWithId() {
System.out.println("enlisting auctions..");
for (Integer auctionId : sellings.keySet()) {
System.out.println(sellings.get(auctionId));
System.out.println("AuctionID: " + auctionId);
System.out.println();
}
}
public String getKeyLocation() {
return String.valueOf(userId);
}
public synchronized void addSelling(int auctionId, AuctionItem ai) {
sellings.put(auctionId, ai);
}
public Map<Integer, AuctionItem> getSellings() {
return sellings;
}
public String getEmail() {
return email;
}
public int getUserId() {
return userId;
}
public void setSellings(Map<Integer, AuctionItem> newList) {
sellings = newList;
}
public synchronized void removeSelling(int auctionId) {
sellings.get(auctionId).setClosed(true);
System.out.println("removed: "+ sellings.remove(auctionId));
enlistSellings();
}
public List<AuctionItem> getAllAuctionItems() {
List<AuctionItem> result = new ArrayList<>();
for (int auctionId : sellings.keySet()) {
result.add(sellings.get(auctionId));
}
return result;
}
@Override
public boolean equals(Object o) {
Seller s = (Seller) o;
return userId == s.getUserId();
}
}