-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.java
More file actions
56 lines (47 loc) · 1.51 KB
/
Field.java
File metadata and controls
56 lines (47 loc) · 1.51 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
package src;
public class Field {
private Modificator modificator;
private Type type;
private String name;
private Object value;
private Field(Builder builder) {
this.modificator = builder.modificator;
this.type = builder.type;
this.name = builder.name;
this.value = builder.value;
}
@Override
public String toString() {
return modificator + " " + type + " " + name + " = " +
(type == Type.STRING ? "\"" + value + "\"" : value) + ";";
}
public static class Builder {
private Modificator modificator;
private Type type;
private String name;
private Object value;
public Builder setModificator(Modificator modificator) {
this.modificator = modificator;
return this;
}
public Builder setType(Type type) {
this.type = type;
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder setValue(Object value) {
this.value = value;
return this;
}
// Исключения
public Field build() throws EmptyNameException {
if (name == null || name.isEmpty()) {
throw new EmptyNameException("Имя поля не может быть пустым или null");
}
return new Field(this);
}
}
}