Skip to content

Commit d863fd6

Browse files
committed
fixed sonar reported issues
1 parent bb27ecf commit d863fd6

8 files changed

Lines changed: 33 additions & 34 deletions

File tree

src/main/java/io/ipdata/client/model/Asn.java renamed to src/main/java/io/ipdata/client/model/AsnModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.experimental.Accessors;
66

77
@ToString @Getter @Accessors(fluent = true)
8-
public class Asn {
8+
public class AsnModel {
99
private String asn;
1010
private String name;
1111
private String domain;

src/main/java/io/ipdata/client/model/IpdataModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public class IpdataModel {
3030
private String flag;
3131
private String emojiFlag;
3232
private String emojiUnicode;
33-
private Asn asn;
33+
private AsnModel asn;
3434
private Carrier carrier;
3535
private List<Language> languages;
3636
private Currency currency;
3737
private TimeZone timeZone;
38-
private Threat threat;
38+
private ThreatModel threat;
3939
//meta
4040
private int count;
4141

src/main/java/io/ipdata/client/model/Threat.java renamed to src/main/java/io/ipdata/client/model/ThreatModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.ToString;
66

77
@Getter @ToString
8-
public class Threat {
8+
public class ThreatModel {
99
@JsonProperty("is_tor")
1010
private boolean tor;
1111
@JsonProperty("is_proxy")

src/main/java/io/ipdata/client/service/CachingInternalClient.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import com.google.common.annotations.VisibleForTesting;
44
import com.google.common.cache.LoadingCache;
55
import io.ipdata.client.error.IpdataException;
6-
import io.ipdata.client.model.Asn;
6+
import io.ipdata.client.model.AsnModel;
77
import io.ipdata.client.model.Currency;
88
import io.ipdata.client.model.IpdataModel;
9-
import io.ipdata.client.model.Threat;
9+
import io.ipdata.client.model.ThreatModel;
1010
import io.ipdata.client.model.TimeZone;
1111
import java.util.List;
1212
import java.util.concurrent.ExecutionException;
1313
import java.util.concurrent.TimeUnit;
1414
import lombok.Builder;
1515
import lombok.experimental.Delegate;
1616

17-
1817
@Builder
1918
@VisibleForTesting
2019

@@ -34,10 +33,10 @@ public class CachingInternalClient implements IpdataInternalClient, IpdataIntern
3433

3534
private LoadingCache<String, IpdataModel> ipdataCache;
3635
private LoadingCache<HashPair<String, String>, IpdataModel> fieldsCache;
37-
private LoadingCache<String, Asn> asnCache;
36+
private LoadingCache<String, AsnModel> asnCache;
3837
private LoadingCache<String, TimeZone> tzCache;
3938
private LoadingCache<String, Currency> currencyCache;
40-
private LoadingCache<String, Threat> threatCache;
39+
private LoadingCache<String, ThreatModel> threatCache;
4140

4241
@Override
4342
public IpdataModel getFields(String ip, String fields) throws IpdataException {
@@ -49,7 +48,7 @@ public IpdataModel getFields(String ip, String fields) throws IpdataException {
4948
}
5049

5150
@Override
52-
public Asn asn(String ip) throws IpdataException {
51+
public AsnModel asn(String ip) throws IpdataException {
5352
try {
5453
return asnCache.get(ip);
5554
} catch (ExecutionException e) {
@@ -76,7 +75,7 @@ public Currency currency(String ip) throws IpdataException {
7675
}
7776

7877
@Override
79-
public Threat threat(String ip) throws IpdataException {
78+
public ThreatModel threat(String ip) throws IpdataException {
8079
try {
8180
return threatCache.get(ip);
8281
} catch (ExecutionException e) {
@@ -98,19 +97,19 @@ public List<IpdataModel> bulkIpdata(List<String> ips) throws IpdataException {
9897
return ipdataInternalClient.bulkIpdata(ips);
9998
}
10099

101-
@Delegate(types = IpdataInternalSingleFieldClient.class, excludes = $DelegateExcludes.class)
100+
@Delegate(types = IpdataInternalSingleFieldClient.class, excludes = DelegateExcludes.class)
102101
IpdataInternalSingleFieldClient getIpdataInternalSingleFieldClient() {
103102
return ipdataInternalSingleFieldClient;
104103
}
105104

106-
private interface $DelegateExcludes {
107-
Asn asn(String ip);
105+
private interface DelegateExcludes {
106+
AsnModel asn(String ip);
108107

109108
TimeZone timeZone(String ip);
110109

111110
Currency currency(String ip);
112111

113-
Threat threat(String ip);
112+
ThreatModel threat(String ip);
114113
}
115114

116115
}

src/main/java/io/ipdata/client/service/IpdataField.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.ipdata.client.service;
22

3-
import io.ipdata.client.model.Asn;
3+
import io.ipdata.client.model.AsnModel;
44
import io.ipdata.client.model.Carrier;
55
import io.ipdata.client.model.Currency;
66
import io.ipdata.client.model.Language;
@@ -25,7 +25,7 @@ public class IpdataField<T> {
2525
public static final IpdataField<String> CONTINENT_CODE = new IpdataField<String>("continent_code", String.class);
2626
public static final IpdataField<Double> LATITUDE = new IpdataField<Double>("latitude", Double.class);
2727
public static final IpdataField<Double> LONGITUDE = new IpdataField<Double>("longitude", Double.class);
28-
public static final IpdataField<Asn> ASN = new IpdataField<Asn>("asn", Asn.class);
28+
public static final IpdataField<AsnModel> ASN = new IpdataField<AsnModel>("asn", AsnModel.class);
2929
public static final IpdataField<String> ORGANISATION = new IpdataField<String>("organisation", String.class);
3030
public static final IpdataField<String> POSTAL = new IpdataField<String>("postal", String.class);
3131
public static final IpdataField<String> CALLING_CODE = new IpdataField<String>("calling_code", String.class);
@@ -39,7 +39,7 @@ public class IpdataField<T> {
3939
public static final IpdataField<TimeZone> THREAT = new IpdataField<TimeZone>("threat", TimeZone.class);
4040
public static final IpdataField<Integer> COUNT = new IpdataField<Integer>("count", Integer.class);
4141
private final String name;
42-
private final Class<?> type;
42+
private final Class<T> type;
4343

4444
@Override
4545
public String toString() {

src/main/java/io/ipdata/client/service/IpdataInternalSingleFieldClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import feign.Param;
44
import feign.RequestLine;
55
import io.ipdata.client.error.IpdataException;
6-
import io.ipdata.client.model.Asn;
6+
import io.ipdata.client.model.AsnModel;
77
import io.ipdata.client.model.Currency;
8-
import io.ipdata.client.model.Threat;
8+
import io.ipdata.client.model.ThreatModel;
99
import io.ipdata.client.model.TimeZone;
1010

1111
@SuppressWarnings("RedundantThrows")
@@ -55,7 +55,7 @@ interface IpdataInternalSingleFieldClient {
5555

5656
@Cacheable
5757
@RequestLine("GET /{ip}/asn")
58-
Asn asn(@Param("ip") String ip) throws IpdataException;
58+
AsnModel asn(@Param("ip") String ip) throws IpdataException;
5959

6060
@Cacheable
6161
@RequestLine("GET /{ip}/time_zone")
@@ -67,6 +67,6 @@ interface IpdataInternalSingleFieldClient {
6767

6868
@Cacheable
6969
@RequestLine("GET /{ip}/threat")
70-
Threat threat(@Param("ip") String ip) throws IpdataException;
70+
ThreatModel threat(@Param("ip") String ip) throws IpdataException;
7171

7272
}

src/main/java/io/ipdata/client/service/IpdataServiceBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import feign.httpclient.ApacheHttpClient;
1515
import feign.jackson.JacksonDecoder;
1616
import feign.jackson.JacksonEncoder;
17-
import io.ipdata.client.model.Asn;
17+
import io.ipdata.client.model.AsnModel;
1818
import io.ipdata.client.model.Currency;
1919
import io.ipdata.client.model.IpdataModel;
20-
import io.ipdata.client.model.Threat;
20+
import io.ipdata.client.model.ThreatModel;
2121
import io.ipdata.client.model.TimeZone;
2222
import java.net.URL;
2323
import lombok.RequiredArgsConstructor;
@@ -91,9 +91,9 @@ public IpdataModel load(HashPair<String, String> key) throws Exception {
9191
CacheBuilder.newBuilder()
9292
.expireAfterWrite(cacheConfig.timeout(), cacheConfig.unit())
9393
.maximumSize(cacheConfig.maxSize())
94-
.build(new CacheLoader<String, Asn>() {
94+
.build(new CacheLoader<String, AsnModel>() {
9595
@Override
96-
public Asn load(String key) throws Exception {
96+
public AsnModel load(String key) throws Exception {
9797
return singleFieldClient.asn(key);
9898
}
9999
})
@@ -124,9 +124,9 @@ public Currency load(String key) throws Exception {
124124
CacheBuilder.newBuilder()
125125
.expireAfterWrite(cacheConfig.timeout(), cacheConfig.unit())
126126
.maximumSize(cacheConfig.maxSize())
127-
.build(new CacheLoader<String, Threat>() {
127+
.build(new CacheLoader<String, ThreatModel>() {
128128
@Override
129-
public Threat load(String key) throws Exception {
129+
public ThreatModel load(String key) throws Exception {
130130
return singleFieldClient.threat(key);
131131
}
132132
})

src/test/java/io/ipdata/client/IpdataFunctionalTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import com.google.common.collect.ImmutableMap;
1414
import feign.httpclient.ApacheHttpClient;
1515
import io.ipdata.client.error.RateLimitException;
16-
import io.ipdata.client.model.Asn;
16+
import io.ipdata.client.model.AsnModel;
1717
import io.ipdata.client.model.Currency;
1818
import io.ipdata.client.model.IpdataModel;
19-
import io.ipdata.client.model.Threat;
19+
import io.ipdata.client.model.ThreatModel;
2020
import io.ipdata.client.service.IpdataField;
2121
import io.ipdata.client.service.IpdataService;
2222
import java.net.URL;
@@ -62,10 +62,10 @@ public void testFullresponse() {
6262
@Test
6363
@SneakyThrows
6464
public void testASN() {
65-
Asn asn = ipdataService.asn("8.8.8.8");
65+
AsnModel asn = ipdataService.asn("8.8.8.8");
6666
String serialized = MAPPER.writeValueAsString(asn);
6767
String expected = TestUtils.get(HTTP_CLIENT, "/8.8.8.8/asn", null);
68-
expected = MAPPER.writeValueAsString(MAPPER.readValue(expected, Asn.class));
68+
expected = MAPPER.writeValueAsString(MAPPER.readValue(expected, AsnModel.class));
6969
assertEquals(serialized, expected, false);
7070
if (ipdataService == CACHING_IPDATA_SERVICE) {
7171
//value will be returned from cache now
@@ -78,10 +78,10 @@ public void testASN() {
7878
@Test
7979
@SneakyThrows
8080
public void testThreat() {
81-
Threat threat = ipdataService.threat("8.8.8.8");
81+
ThreatModel threat = ipdataService.threat("8.8.8.8");
8282
String serialized = MAPPER.writeValueAsString(threat);
8383
String expected = TestUtils.get(HTTP_CLIENT, "/8.8.8.8/threat", null);
84-
expected = MAPPER.writeValueAsString(MAPPER.readValue(expected, Threat.class));
84+
expected = MAPPER.writeValueAsString(MAPPER.readValue(expected, ThreatModel.class));
8585
assertEquals(serialized, expected, false);
8686
if (ipdataService == CACHING_IPDATA_SERVICE) {
8787
//value will be returned from cache now

0 commit comments

Comments
 (0)