|
1 | 1 | package io.ipgeolocation.api; |
2 | 2 |
|
3 | 3 | public class GeolocationParams { |
4 | | - private String ip; |
5 | | - private String[] ips; |
| 4 | + private final String ipAddress; |
| 5 | + private final String lang; |
| 6 | + private final String fields; |
| 7 | + private final Boolean includeHostname; |
| 8 | + private final boolean includeLiveHostname; |
| 9 | + private final boolean includeHostnameFallbackLive; |
| 10 | + private final boolean includeSecurity; |
| 11 | + private final boolean includeUserAgentDetail; |
| 12 | + private final String excludes; |
| 13 | + |
| 14 | + public GeolocationParams( |
| 15 | + String ipAddress, |
| 16 | + String lang, |
| 17 | + String fields, |
| 18 | + String excludes, |
| 19 | + boolean includeHostname, |
| 20 | + boolean includeLiveHostname, |
| 21 | + boolean includeHostnameFallbackLive, |
| 22 | + boolean includeSecurity, |
| 23 | + boolean includeUserAgentDetail) { |
| 24 | + this.ipAddress = ipAddress; |
| 25 | + this.lang = lang; |
| 26 | + this.fields = fields; |
| 27 | + this.includeHostname = includeHostname; |
| 28 | + this.includeLiveHostname = includeLiveHostname; |
| 29 | + this.includeHostnameFallbackLive = includeHostnameFallbackLive; |
| 30 | + this.includeSecurity = includeSecurity; |
| 31 | + this.includeUserAgentDetail = includeUserAgentDetail; |
| 32 | + this.excludes = excludes; |
| 33 | + } |
| 34 | + |
| 35 | + public String getIPAddress() { |
| 36 | + return ipAddress; |
| 37 | + } |
| 38 | + |
| 39 | + public String getFields() { |
| 40 | + return fields; |
| 41 | + } |
| 42 | + |
| 43 | + public String getLang() { |
| 44 | + return lang; |
| 45 | + } |
| 46 | + |
| 47 | + public boolean isIncludeHostname() { |
| 48 | + return includeHostname; |
| 49 | + } |
| 50 | + |
| 51 | + public boolean isIncludeLiveHostname() { |
| 52 | + return includeLiveHostname; |
| 53 | + } |
| 54 | + |
| 55 | + public boolean isIncludeHostnameFallbackLive() { |
| 56 | + return includeHostnameFallbackLive; |
| 57 | + } |
| 58 | + |
| 59 | + public boolean isIncludeSecurity() { |
| 60 | + return includeSecurity; |
| 61 | + } |
| 62 | + |
| 63 | + public boolean isIncludeUserAgentDetail() { |
| 64 | + return includeUserAgentDetail; |
| 65 | + } |
| 66 | + |
| 67 | + public String getExcludes() { |
| 68 | + return excludes; |
| 69 | + } |
| 70 | + |
| 71 | + public static GeolocationParamsBuilder builder() { |
| 72 | + return new GeolocationParamsBuilder(); |
| 73 | + } |
| 74 | + |
| 75 | + public static class GeolocationParamsBuilder { |
| 76 | + private String ipAddress; |
6 | 77 | private String lang; |
7 | 78 | private String fields; |
8 | | - private Boolean includeHostname = false; |
9 | | - private Boolean includeLiveHostname = false; |
10 | | - private Boolean includeHostnameFallbackLive = false; |
11 | | - private Boolean includeSecurity = false; |
12 | | - private Boolean includeUserAgentDetail = false; |
| 79 | + private boolean includeHostname; |
| 80 | + private boolean includeLiveHostname; |
| 81 | + private boolean includeHostnameFallbackLive; |
| 82 | + private boolean includeSecurity; |
| 83 | + private boolean includeUserAgentDetail; |
13 | 84 | private String excludes; |
14 | 85 |
|
15 | | - public GeolocationParams() { |
16 | | - this.ip = ""; |
17 | | - this.ips = new String[0]; |
18 | | - this.lang = "en"; |
19 | | - this.fields = ""; |
20 | | - this.includeHostname = false; |
21 | | - this.includeSecurity = false; |
22 | | - this.includeUserAgentDetail = false; |
23 | | - this.excludes = ""; |
| 86 | + private GeolocationParamsBuilder() { |
| 87 | + ipAddress = ""; |
| 88 | + lang = "en"; |
| 89 | + fields = "*"; |
| 90 | + excludes = ""; |
24 | 91 | } |
25 | 92 |
|
26 | | - public void setIPAddress(String ip) { |
27 | | - this.ip = Strings.nullToEmpty(ip); |
| 93 | + public GeolocationParamsBuilder withIPAddress(String ipAddress) { |
| 94 | + this.ipAddress = ipAddress; |
| 95 | + return this; |
28 | 96 | } |
29 | 97 |
|
30 | | - public String getIPAddress() { |
31 | | - return ip; |
| 98 | + public GeolocationParamsBuilder withLang(String lang) { |
| 99 | + this.lang = lang; |
| 100 | + return this; |
32 | 101 | } |
33 | 102 |
|
34 | | - public void setFields(String fields) { |
35 | | - this.fields = Strings.nullToEmpty(fields); |
| 103 | + public GeolocationParamsBuilder withFields(String fields) { |
| 104 | + this.fields = fields; |
| 105 | + return this; |
36 | 106 | } |
37 | 107 |
|
38 | | - public String getFields() { |
39 | | - return fields; |
| 108 | + public GeolocationParamsBuilder withExcludes(String excludes) { |
| 109 | + this.excludes = excludes; |
| 110 | + return this; |
40 | 111 | } |
41 | 112 |
|
42 | | - public void setLang(String lang) { |
43 | | - this.lang = lang; |
| 113 | + public GeolocationParamsBuilder includeHostname() { |
| 114 | + this.includeHostname = Boolean.TRUE; |
| 115 | + return this; |
44 | 116 | } |
45 | 117 |
|
46 | | - public String getLang() { |
47 | | - return lang; |
| 118 | + public GeolocationParamsBuilder includeLiveHostname() { |
| 119 | + this.includeLiveHostname = Boolean.TRUE; |
| 120 | + return this; |
48 | 121 | } |
49 | 122 |
|
50 | | - public void setIncludeHostname(Boolean includeHostname) { |
51 | | - this.includeHostname = includeHostname; |
| 123 | + public GeolocationParamsBuilder includeHostnameFallbackLive() { |
| 124 | + this.includeHostnameFallbackLive = Boolean.TRUE; |
| 125 | + return this; |
52 | 126 | } |
53 | 127 |
|
54 | | - public boolean isIncludeHostname() { |
55 | | - return includeHostname; |
| 128 | + public GeolocationParamsBuilder includeSecurity() { |
| 129 | + this.includeSecurity = Boolean.TRUE; |
| 130 | + return this; |
56 | 131 | } |
57 | 132 |
|
58 | | - public void setIncludeLiveHostname(Boolean includeLiveHostname) { |
59 | | - this.includeLiveHostname = includeLiveHostname; |
| 133 | + public GeolocationParamsBuilder includeUserAgentDetail() { |
| 134 | + this.includeUserAgentDetail = Boolean.TRUE; |
| 135 | + return this; |
60 | 136 | } |
61 | 137 |
|
62 | | - public Boolean isIncludeLiveHostname() { |
63 | | - return includeLiveHostname; |
64 | | - } |
65 | | - |
66 | | - public void setIncludeHostnameFallbackLive(Boolean includeHostnameFallbackLive) { |
67 | | - this.includeHostnameFallbackLive = includeHostnameFallbackLive; |
68 | | - } |
69 | | - |
70 | | - public Boolean isIncludeHostnameFallbackLive() { |
71 | | - return includeHostnameFallbackLive; |
72 | | - } |
73 | | - |
74 | | - public void setIncludeSecurity(Boolean includeSecurity) { |
75 | | - this.includeSecurity = includeSecurity; |
76 | | - } |
77 | | - |
78 | | - public Boolean isIncludeSecurity() { |
79 | | - return includeSecurity; |
80 | | - } |
81 | | - |
82 | | - public void setIncludeUserAgentDetail(Boolean includeUserAgentDetail) { |
83 | | - this.includeUserAgentDetail = includeUserAgentDetail; |
84 | | - } |
85 | | - |
86 | | - public Boolean isIncludeUserAgentDetail() { |
87 | | - return includeUserAgentDetail; |
88 | | - } |
89 | | - |
90 | | - public void setExcludes(String excludes) { |
91 | | - this.excludes = excludes; |
92 | | - } |
93 | | - |
94 | | - public String getExcludes() { |
95 | | - return excludes; |
96 | | - } |
97 | | - |
98 | | - public void setIPAddresses(String[] ips) throws IllegalArgumentException { |
99 | | - if (ips.length > 50) { |
100 | | - throw new IllegalArgumentException("Max. number of IP addresses cannot be more than 50."); |
101 | | - } else { |
102 | | - this.ips = ips; |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - public String[] getIPAddresses() { |
107 | | - return ips; |
| 138 | + public GeolocationParams build() { |
| 139 | + return new GeolocationParams( |
| 140 | + ipAddress, |
| 141 | + lang, |
| 142 | + fields, |
| 143 | + excludes, |
| 144 | + includeHostname, |
| 145 | + includeLiveHostname, |
| 146 | + includeHostnameFallbackLive, |
| 147 | + includeSecurity, |
| 148 | + includeUserAgentDetail); |
108 | 149 | } |
| 150 | + } |
109 | 151 | } |
0 commit comments