-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathItem.java
More file actions
118 lines (103 loc) · 2.77 KB
/
Item.java
File metadata and controls
118 lines (103 loc) · 2.77 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
public class Item {
private String name;
private final String price;
private final String type;
private final String expiration;
private boolean isError = false;
public Item(ItemBuilder builder) {
this.name = builder.getName();
this.price = builder.getPrice();
this.type = builder.getType();
this.expiration = builder.getExpiration();
this.isError = builder.getIsError();
}
public void setName(String newName){
this.name = newName;
}
public String getName() {
return name;
}
public String getPrice() {
return price;
}
public String getType() {
return type;
}
public String getExpiration() {
return expiration;
}
public boolean isError(){
return isError;
}
//equals method
//toString method
@Override
public String toString() {
if(!isError) {
return "Item{" +
"name='" + name + '\'' +
", price='" + price + '\'' +
", type='" + type + '\'' +
", expiration='" + expiration + '\'' +
"}\n";
}
return "Erroneous entry\n";
}
public static class ItemBuilder{
private String name;
private String price;
private String type;
private String expiration;
private boolean isError = false;
public ItemBuilder(){
}
public ItemBuilder setName(String name) {
checkError(name);
this.name = name;
return this;
}
public ItemBuilder setPrice(String price) {
checkError(price);
this.price = price;
return this;
}
public ItemBuilder setType(String type) {
checkError(type);
this.type = type;
return this;
}
public ItemBuilder setExpiration(String expiration) {
checkError(expiration);
this.expiration = expiration;
return this;
}
public ItemBuilder denoteError(){
this.isError = true;
return this;
}
public void checkError(String input){
if(input == null){
this.isError = true;
this.name = "error";
}
}
public String getName() {
return name;
}
public String getPrice() {
return price;
}
public String getType() {
return type;
}
public String getExpiration() {
return expiration;
}
public boolean getIsError(){
return isError;
}
public Item build(){
return new Item(this);
}
}
}