-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudyGroup.java
More file actions
170 lines (148 loc) · 6.5 KB
/
StudyGroup.java
File metadata and controls
170 lines (148 loc) · 6.5 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
168
169
170
package org.example.classes;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import exception.IllegalValueException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.Objects;
import static org.example.details.StorageOfManagers.*;
/**
* Класс - объект коллекции
*/
public class StudyGroup implements Comparable<StudyGroup> {
private String name; //Поле не может быть null, Строка не может быть пустой
private long studentsCount; //Значение поля должно быть больше 0
private long shouldBeExpelled; //Значение поля должно быть больше 0
private Coordinates coordinates; //Поле не может быть null
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy-HH:mm:ss")
private java.time.LocalDateTime creationDate; //Поле не может быть null, Значение этого поля должно генерироваться автоматически
public void setId(int id) {
this.id = (long) id;
}
private Long id; //Поле не может быть null, Значение поля должно быть больше 0, Значение этого поля должно быть уникальным, Значение этого поля должно генерироваться автоматически
private FormOfEducation formOfEducation; //Поле не может быть null
private Semester semesterEnum; //Поле не может быть null
private Person groupAdmin; //Поле может быть null
@JsonCreator
public StudyGroup(String name, long studentsCount, long shouldBeExpelled, Coordinates coordinates, FormOfEducation formOfEducation, Semester semesterEnum, Person groupAdmin) {
setName(name);
setStudentsCount(studentsCount);
setShouldBeExpelled(shouldBeExpelled);
setCoordinates(coordinates);
this.creationDate =LocalDateTime.now();
this.id = collectionManager.getId();
setFormOfEducation(formOfEducation);
setGroupAdmin(groupAdmin);
setSemesterEnum(semesterEnum);
}
public StudyGroup(){
this.id = collectionManager.getId();
this.creationDate = LocalDateTime.now();
}
public void setCreationDate(LocalDateTime creationDate) {
this.creationDate = creationDate;
}
public void setName(String name) {
if(!collectionManager.validate(name, false)){
throw new IllegalValueException("Поле name не может быть пустым");
}
else {
this.name = name;
}
}
public void setShouldBeExpelled(long shouldBeExpelled) {
if (collectionManager.validate(shouldBeExpelled, 0)){
this.shouldBeExpelled = shouldBeExpelled;
}
else{
throw new IllegalValueException("Число студентов на отчислении должно быть больше нуля");
}
}
public void setStudentsCount(long studentsCount) {
if (collectionManager.validate(studentsCount, 0)){
this.studentsCount = studentsCount;
}
else{
throw new IllegalValueException("Число студентов должно быть больше нуля");
}
}
public void setCoordinates(Coordinates coordinates){
if(collectionManager.validate(coordinates, false)){
this.coordinates = coordinates;
}
else{
throw new IllegalValueException("Объект: координаты не может быть null");
}
}
public void setGroupAdmin(Person groupAdmin) {
if(collectionManager.validate(groupAdmin, false)){
this.groupAdmin = groupAdmin;
}
else{
throw new IllegalValueException("Объект: groupAdmin не может быть null");
}
}
public void setSemesterEnum(Semester semesterEnum) {
if(collectionManager.validate(semesterEnum, false)){
this.semesterEnum = semesterEnum;
}
else{
throw new IllegalValueException("Объект: semesterEnum не может быть null");
}
}
public void setFormOfEducation(FormOfEducation formOfEducation) {
if(collectionManager.validate(formOfEducation, false)){
this.formOfEducation = formOfEducation;
}
else{
throw new IllegalValueException("Объект: formOfEducation не может быть null");
}
}
public long getId(){
return this.id;
}
public String getName() {
return name;
}
public long getStudentsCount() {
return studentsCount;
}
public long getShouldBeExpelled() {
return shouldBeExpelled;
}
public Coordinates getCoordinates() {
return coordinates;
}
public LocalDateTime getCreationDate() {
return creationDate;
}
public FormOfEducation getFormOfEducation() {
return formOfEducation;
}
public Semester getSemesterEnum() {
return semesterEnum;
}
public Person getGroupAdmin() {
return groupAdmin;
}
@Override
public String toString(){
return "Name: " + this.name + ", StudentsCount: " + this.studentsCount + ", ShouldBeExpelled: " + this.shouldBeExpelled + ", Coordinates: " + this.coordinates.toString() + ", creationDate: " + this.creationDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy-HH-mm-ss")) + ", id: " + this.id + ", formOfEducation: " + this.formOfEducation + ", semesterEnum: " + this.semesterEnum + ", groupAdmin: " + this.groupAdmin.toString();
}
@Override
public int compareTo(StudyGroup group){
return this.id.compareTo(group.id);
}
@Override
public int hashCode(){
return Objects.hash(this.name, this.creationDate, this.id);
}
}