-
Notifications
You must be signed in to change notification settings - Fork 0
/
Category.java
124 lines (111 loc) · 3.2 KB
/
Category.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
package com.barattoManager.category;
import com.barattoManager.category.field.Field;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
/**
* Class that rappresenta a category
*/
public class Category {
/**
* Category name
*/
@JsonProperty("category_name")
private final String name;
/**
* Category description
*/
@JsonProperty("category_description")
private final String description;
/**
* {@link HashMap} of sub-category
*/
@JsonProperty("category_sub_categories")
private final HashMap<String, Category> subCategory;
/**
* {@link HashMap} of fields
*/
@JsonProperty("category_fields")
private final HashMap<String, Field> categoryFields;
/**
* {@link Category} constructor
* @param name Name of category
* @param description Description of category
* @param subCategory {@link HashMap} that contains each sub-category
* @param categoryFields {@link HashMap} that contains each fields
*/
public Category(
@JsonProperty("category_name") String name,
@JsonProperty("category_description") String description,
@JsonProperty("category_sub_categories") HashMap<String, Category> subCategory,
@JsonProperty("category_fields") HashMap<String, Field> categoryFields
) {
this.name = name;
this.description = description;
this.subCategory = subCategory;
this.categoryFields = categoryFields;
}
/**
* {@link Category} constructor
* @param name Name of category
* @param description Description of category
*/
public Category(String name, String description) {
this.name = name;
this.description = description;
this.subCategory = new HashMap<>();
this.categoryFields = new HashMap<>();
}
/**
* Method used to add a new sub-category to this category
* @param name Name of sub-category
* @param description Description of sab-category
*/
public void addSubCategory(String name, String description) {
var newCategory = new Category(name, description);
newCategory.addNewFields(categoryFields);
subCategory.put(newCategory.getName().toLowerCase(), newCategory);
}
/**
* Method used to add a new {@link Field}s to this category
* @param newFields {@link HashMap} that contains the fields to add
*/
public void addNewFields(HashMap<String, Field> newFields) {
categoryFields.putAll(newFields);
}
/**
* Method used to add a new {@link Field} to this category
* @param name Name of field
* @param required If true the field is required otherwise no
*/
public void addNewFields(String name, boolean required) {
categoryFields.put(name.toLowerCase(), new Field(name, required));
}
/**
* Method used to get the name of category
* @return Name of category
*/
public String getName() {
return name;
}
/**
* Method used to get the description of category
* @return Description of category
*/
public String getDescription() {
return description;
}
/**
* Method used to get the HashMap of sub-category
* @return {@link HashMap} of sub-category
*/
public HashMap<String, Category> getSubCategory() {
return subCategory;
}
/**
* Method used to get the HashMap of fields
* @return {@link HashMap} of fields
*/
public HashMap<String, Field> getCategoryFields() {
return categoryFields;
}
}