-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.java
More file actions
167 lines (127 loc) · 4.55 KB
/
Copy pathInventory.java
File metadata and controls
167 lines (127 loc) · 4.55 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
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
/**
* checked 09MAR2019
*/
//Inventory class from UML Diagram
package Model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Inventory {
private static int partIDCounter = 0;
private static int productIDCounter = 0;
private static final ObservableList<Product> Products = FXCollections.observableArrayList();
private static final ObservableList<Part> allParts = FXCollections.observableArrayList();
//class constructor
public Inventory() {
}
//get all the parts from the inv
public static ObservableList<Part> getAllParts() {
return allParts;
}
//add a part to the inv
public static void addPart(Part part) {
allParts.add(part);
}
//delete the part from the inv
public static void deletePart(Part part) {
allParts.remove(part);
}
//update the part in the inv
public static void updatePart(int index, Part part) {
allParts.set(index, part);
}
//Increment the PartID count and then return/get the part ID count
public static int getPartCounter() {
partIDCounter++;
return partIDCounter;
}
//verify that the part is actually able to be deleted
public static boolean isPartDeletable(Part part) {
boolean inList = false;
for (int i = 0; i < Products.size(); i++) {
if (Products.get(i).getProductParts().contains(part)) {
inList = true;
}
}
return inList;
}
//lookup the part using a search term, check if it is integer input first
public static int findPart(String partToBeSearchedFor) {
boolean inPartList = false;
int idx = 0;
if (isInt(partToBeSearchedFor)) {
for (int i = 0; i < allParts.size(); i++) {
if (Integer.parseInt(partToBeSearchedFor) == allParts.get(i).getPartID()) {
idx = i;
inPartList = true;
}
}
} else {
for (int i = 0; i < allParts.size(); i++) {
if (partToBeSearchedFor.equals(allParts.get(i).getNamePart())) {
idx = i;
inPartList = true;
}
}
}
if (inPartList = true) {
return idx;
} else {
return -1;
}
}
//create function that returns the product list in an observable list data type
public static ObservableList<Product> getAllProducts() {
return Products;
}
//add a product to the product list inventory
public static void addProduct(Product productToBeAdded) {
Products.add(productToBeAdded);
}
//remove a product from the product list inventory
public static void removeProduct(Product productToBeRemoved) {
Products.remove(productToBeRemoved);
}
//get the id of the next product, increments product ID and returns it
public static int getProductCount() {
productIDCounter++;
return productIDCounter;
}
//helper function to check if the input is an integer
public static boolean isInt(String integerToBeChekced) {
try {
Integer.parseInt(integerToBeChekced);
return true;
} catch (NumberFormatException e) {
return false;
}
}
//find the product in the list
public static int lookupProduct(String productToBeLookedUp) {
boolean inProductList = false;
int idx = 0;
if (isInt(productToBeLookedUp)) {
for (int i = 0; i < Products.size(); i++) {
if (Integer.parseInt(productToBeLookedUp) == Products.get(i).getProductID()) {
idx = i;
inProductList = true;
}
}
} else {
for (int i = 0; i < Products.size(); i++) {
if (productToBeLookedUp.equals(Products.get(i).getNameProduct())) {
idx = i;
inProductList = true;
}
}
}
if (inProductList = true) {
return idx;
} else {
return -1;
}
}
//update the product using the index and the product
public static void updateProduct(int index, Product product) {
Products.set(index, product);
}
}