-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathTransaction.java
More file actions
80 lines (62 loc) · 1.95 KB
/
Transaction.java
File metadata and controls
80 lines (62 loc) · 1.95 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
//------------------------------------------------------------
//Jacob Dedman
//Created Transaction.java
package edu.uark.registerapp.models.api;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
import java.util.ArrayList;
import org.apache.commons.lang3.StringUtils;
import edu.uark.registerapp.models.api.Product;
import edu.uark.registerapp.models.entities.ProductEntity;
//Jacob Dedman
//Created Transaction class so I can add functionality for updating database
public class Transaction extends ApiResponse {
//Jacob Dedman
//Cart class to hold items
private class Cart {
//Jacob Dedman
//Array of strings holds lookupcode of products
private ArrayList<String> products = new ArrayList<String>();
public void addProduct(Product prod) {
products.add(prod.getLookupCode());
}
public void remProduct(Product prod) {
for (int i = 0; i < products.size(); i++) {
if (products.get(i) == prod.getLookupCode()) {
products.remove(i);
i--;
}
}
}
}
//Jacob Dedman
//Properties
private Cart productCart;
public Transaction addToCart(Product prod) {
this.productCart.addProduct(prod);
return this;
}
public Transaction remFromCart(Product prod) {
this.productCart.remProduct(prod);
return this;
}
private String lookupCode;
public String getLookupCode() {
return this.lookupCode;
}
public Product setLookupCode(final String lookupCode) {
this.lookupCode = lookupCode;
return this;
}
public Transaction() {
super();
this.id = new UUID(0, 0);
this.lookupCode = StringUtils.EMPTY;
}
public Transaction(final TransactionEntity transactionEntity) {
super(false);
this.id = transactionEntity.getId();
this.lookupCode = transactionEntity.getLookupCode();
}
}