-
Notifications
You must be signed in to change notification settings - Fork 21
/
Supplier.java
326 lines (295 loc) · 10.5 KB
/
Supplier.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
* Copyright 2018 Kaushik N. Sanji
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.kaushiknsanji.storeapp.data.local.models;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
/**
* Parcelable Model class for storing and updating the details of the Supplier.
*
* @author Kaushik N Sanji
*/
public class Supplier implements Parcelable {
/**
* Implementation of {@link android.os.Parcelable.Creator} interface
* to generate instances of this Parcelable class {@link Supplier} from a {@link Parcel}
*/
public static final Creator<Supplier> CREATOR = new Creator<Supplier>() {
/**
* Creates an instance of this Parcelable class {@link Supplier} from
* a given Parcel whose data had been previously written by #writeToParcel() method
*
* @param in The Parcel to read the object's data from.
* @return Returns a new instance of this Parcelable class {@link Supplier}
*/
@Override
public Supplier createFromParcel(Parcel in) {
return new Supplier(in);
}
/**
* Creates a new array of this Parcelable class {@link Supplier}
*
* @param size Size of the array
* @return Returns an array of this Parcelable class {@link Supplier}, with every
* entry initialized to null
*/
@Override
public Supplier[] newArray(int size) {
return new Supplier[size];
}
};
//The Primary Key/ID of the Supplier
private final int mId;
//The Name of the Supplier
private String mName;
//The Unique Code of the Supplier
private String mCode;
//List of Supplier's Contacts
private ArrayList<SupplierContact> mContacts;
//List of Products with their Selling Price info
private ArrayList<ProductSupplierInfo> mProductSupplierInfoList;
/**
* Private Constructor of {@link Supplier}
*
* @param id The Integer Primary Key/ID of the Supplier
* @param name The Name of the Supplier
* @param code The Unique Code of the Supplier
* @param contacts {@link ArrayList} of Supplier's Contacts {@link SupplierContact}
* @param productSupplierInfoList {@link ArrayList} of Products with their Selling Price info {@link ProductSupplierInfo}
*/
private Supplier(int id,
String name,
String code,
ArrayList<SupplierContact> contacts,
ArrayList<ProductSupplierInfo> productSupplierInfoList) {
mId = id;
mName = name;
mCode = code;
mContacts = contacts;
mProductSupplierInfoList = productSupplierInfoList;
}
/**
* Parcelable constructor that de-serializes the data from a Parcel {@code in} passed
*
* @param in The Instance of the Parcel class containing the serialized data
*/
protected Supplier(Parcel in) {
mId = in.readInt();
mName = in.readString();
mCode = in.readString();
mContacts = in.createTypedArrayList(SupplierContact.CREATOR);
mProductSupplierInfoList = in.createTypedArrayList(ProductSupplierInfo.CREATOR);
}
/**
* Flattens/Serializes the object of {@link Supplier} into a Parcel
*
* @param dest The Parcel in which the object should be written
* @param flags Additional flags about how the object should be written.
* May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mId);
dest.writeString(mName);
dest.writeString(mCode);
dest.writeTypedList(mContacts);
dest.writeTypedList(mProductSupplierInfoList);
}
/**
* Describes the kinds of special objects contained in this Parcelable
* instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled
* by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0; //Indicating with no mask
}
/**
* Getter Method for Primary Key/ID of the Supplier
*
* @return The Integer Primary Key/ID of the Supplier
*/
public int getId() {
return mId;
}
/**
* Getter Method for the Name of the Supplier
*
* @return The Name of the Supplier
*/
public String getName() {
return mName;
}
/**
* Setter Method to set the Name of the Supplier
*
* @param name The Name of the Supplier
*/
public void setName(String name) {
mName = name;
}
/**
* Getter Method for the Code of the Supplier
*
* @return The Code of the Supplier
*/
public String getCode() {
return mCode;
}
/**
* Setter Method to set the Code of the Supplier
*
* @param code The Unique Code of the Supplier
*/
public void setCode(String code) {
mCode = code;
}
/**
* Getter Method for the List of Supplier's Contacts
*
* @return An {@link ArrayList} of Supplier's Contacts {@link SupplierContact}
*/
public ArrayList<SupplierContact> getContacts() {
return mContacts;
}
/**
* Setter Method to set the List of Supplier's Contacts
*
* @param contacts {@link ArrayList} of Supplier's Contacts {@link SupplierContact}
*/
public void setContacts(ArrayList<SupplierContact> contacts) {
mContacts = contacts;
}
/**
* Getter Method for the List of Products with their Selling Price info
*
* @return {@link ArrayList} of Products with their Selling Price info {@link ProductSupplierInfo}
*/
public ArrayList<ProductSupplierInfo> getProductSupplierInfoList() {
return mProductSupplierInfoList;
}
/**
* Setter Method to set the List of Products with their Selling Price info
*
* @param productSupplierInfoList {@link ArrayList} of Products with their Selling Price info {@link ProductSupplierInfo}
*/
public void setProductSupplierInfoList(ArrayList<ProductSupplierInfo> productSupplierInfoList) {
mProductSupplierInfoList = productSupplierInfoList;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param o The reference object with which to compare.
* @return <b>TRUE</b> if this object is the same as the {@code o}
* argument; <b>FALSE</b> otherwise.
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Supplier supplier = (Supplier) o;
if (mId != supplier.mId) return false;
if (!mName.equals(supplier.mName)) return false;
if (!mCode.equals(supplier.mCode)) return false;
if (!mContacts.equals(supplier.mContacts)) return false;
return mProductSupplierInfoList.equals(supplier.mProductSupplierInfoList);
}
/**
* Returns a hash code value for the object.
*
* @return A hash code value for this object.
*/
@Override
public int hashCode() {
int result = mId;
result = 31 * result + mName.hashCode();
result = 31 * result + mCode.hashCode();
result = 31 * result + mContacts.hashCode();
result = 31 * result + mProductSupplierInfoList.hashCode();
return result;
}
/**
* Static Builder class that constructs {@link Supplier}
*/
public static class Builder {
private int mId;
private String mName;
private String mCode;
private ArrayList<SupplierContact> mContacts;
private ArrayList<ProductSupplierInfo> mProductSupplierInfoList;
/**
* Setter for the Integer Primary Key/ID of the Supplier
*
* @param id Integer Primary Key/ID of the Supplier
* @return Instance of {@link Builder} for chaining method calls.
*/
public Builder setId(int id) {
mId = id;
return this;
}
/**
* Setter for the Name of the Supplier
*
* @param name The Name of the Supplier
* @return Instance of {@link Builder} for chaining method calls.
*/
public Builder setName(String name) {
mName = name;
return this;
}
/**
* Setter for the Code of the Supplier
*
* @param code The Unique Code of the Supplier
* @return Instance of {@link Builder} for chaining method calls.
*/
public Builder setCode(String code) {
mCode = code;
return this;
}
/**
* Setter for the List of Supplier's Contacts
*
* @param contacts {@link ArrayList} of Supplier's Contacts {@link SupplierContact}
* @return Instance of {@link Builder} for chaining method calls.
*/
public Builder setContacts(ArrayList<SupplierContact> contacts) {
mContacts = contacts;
return this;
}
/**
* Setter for the List of Products with their Selling Price info
*
* @param productSupplierInfoList {@link ArrayList} of Products with their Selling Price info {@link ProductSupplierInfo}
* @return Instance of {@link Builder} for chaining method calls.
*/
public Builder setProductSupplierInfoList(ArrayList<ProductSupplierInfo> productSupplierInfoList) {
mProductSupplierInfoList = productSupplierInfoList;
return this;
}
/**
* Terminal Method that constructs the {@link Supplier}
*
* @return Instance of {@link Supplier} built
*/
public Supplier createSupplier() {
//Returning the instance built
return new Supplier(mId, mName, mCode, mContacts, mProductSupplierInfoList);
}
}
}