-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProduct.java
179 lines (158 loc) · 4.7 KB
/
Product.java
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
174
175
176
177
178
179
package GraphicalInterface;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
/**
* This class is designed to store relevant information of the products that are being sold to a client at a given sale.
* It is later on used in order to create an ObservableList of this kind of objects and populate a TableView with information
* retrieved from a database.
*/
public class Product{
// String properties are used instead of strings because the values are going to be observed in the interface. The variable identifier is
// used in the graphical interface in order to retrieve the value of the attributes and display it in a column to populate the tables.
// Strings cannot work with table view because they are not properties.
private StringProperty id, description, price, amount, existence, rfc;
private int amountNum;
/**
* This constructor allows the user to create a new Product object, it does not initialize the StringProperty
* variables.
*/
public Product(){
id = null;
description = null;
price = null;
amountNum = 0;
amount = null;
rfc = null;
}
/**
* This method allows the user to set the value of the id StringProperty
* @param id The value of the id
*/
public void setId(String id){
idProperty().set(id);
}
/**
* This method returns the value of the id.
* @return A String continaing the id of the product.
*/
public String getId(){
return idProperty().get();
}
/**
* This method initializes the id StringProperty if it is not initialized already.
* @return the initilaized id StringProperty
*/
public StringProperty idProperty(){
if (id == null){
id = new SimpleStringProperty(this, "id");
}
return id;
}
/**
* Set the description of a product
* @param description string
*/
public void setDescription(String description){
descriptionProperty().set(description);
}
/**
* Initializes the description property if it is null, and returns it
* @return StringProperty
*/
public StringProperty descriptionProperty(){
if (this.description == null){
this.description = new SimpleStringProperty(this, "description");
}
return this.description;
}
/**
* Set the price of the product
* @param price string
*/
public void setPrice(String price){
priceProperty().set(price);
}
/**
* Return the price of the product
* @return String
*/
public String getPrice(){
return priceProperty().get();
}
/**
* Initializes the price property if it is null, and returns it
* @return StringProperty
*/
public StringProperty priceProperty(){
if (price == null){
price = new SimpleStringProperty(this, "price");
}
return price;
}
/**
* Set the value of amount
* @param amount string
*/
public void setAmount(String amount){
amountProperty().set(amount);
amountNum = Integer.valueOf(amount);
}
/**
* Get the amount value
* @return String
*/
public String getAmount(){
return amountProperty().get();
}
/**
* Initializes the amount property if it is null, and returns it
* @return String Property
*/
public StringProperty amountProperty(){
if (amount == null){
amount = new SimpleStringProperty(this, "amount");
}
return amount;
}
/**
* Increase the value of amount by one
*/
public void addAmount(){
this.amountNum = this.amountNum + 1;
amount.set(String.valueOf(amountNum));
}
/**
* Initializes the existence property if it is null, and returns it
* @param existence String
*/
public void setExistence(String existence){
existenceProperty().set(existence);
}
/**
* Initializes the exact property if it is null, and returns it
* @return StringProperty
*/
public StringProperty existenceProperty(){
if (existence == null){
existence = new SimpleStringProperty(this, "existence");
}
return existence;
}
/**
* Set the value of rfc
* @param rfc string
*/
public void setRfc(String rfc){
rfcProperty().set(rfc);
}
/**
* Initializes the rfc property if it is null, and returns it
* @return StringProperty
*/
public StringProperty rfcProperty(){
if (rfc == null){
rfc = new SimpleStringProperty(this, "rfc");
}
return rfc;
}
}