-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountry.java
More file actions
114 lines (95 loc) · 2.81 KB
/
Country.java
File metadata and controls
114 lines (95 loc) · 2.81 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
package creational.builder;
public class Country {
private String name;
private String capital;
private String language;
private String religion;
private String currency;
private double area;
private long population;
private Country(CountryBuilder builder) {
name = builder.name;
capital = builder.capital;
language = builder.language;
religion = builder.religion;
currency = builder.currency;
area = builder.area;
population = builder.population;
}
public static class CountryBuilder {
private String name;
private String capital;
private String language;
private String religion;
private String currency;
double area;
long population;
public CountryBuilder name(String name) {
this.name = name;
return this;
}
public CountryBuilder capital(String name) {
this.capital = name;
return this;
}
public CountryBuilder language(String name) {
this.language = name;
return this;
}
public CountryBuilder religion(String name) {
this.religion = name;
return this;
}
public CountryBuilder currency(String name) {
this.currency = name;
return this;
}
public CountryBuilder area(double km2) {
this.area = km2;
return this;
}
public CountryBuilder population(long quantity) {
this.population = quantity;
return this;
}
public Country build() {
if (name == null) {
throw new IllegalStateException("The value of 'name' can't be null");
}
if (capital == null) {
throw new IllegalStateException("The value of 'capital' can't be null");
}
if (language == null) {
throw new IllegalStateException("The value of 'language' can't be null");
}
if (religion == null) {
throw new IllegalStateException("The value of 'religion' can't be null");
}
if (currency == null) {
throw new IllegalStateException("The value of 'currency' can't be null");
}
return new Country(this);
}
}
public String getName() {
return name;
}
public String getCapital() {
return capital;
}
public String getLanguage() {
return language;
}
public String getReligion() {
return religion;
}
public String getCurrency() {
return currency;
}
public double getArea() {
return area;
}
public long getPopulation() {
return population;
}
}