Skip to content

Commit 317d84e

Browse files
oschwaldclaude
andcommitted
Remove redundant constructors now that IP/network are auto-injected
- Remove copy constructors from model classes that only populated IP address and network (AnonymousIpResponse, AnonymousPlusResponse, ConnectionTypeResponse, AsnResponse, DomainResponse, IspResponse, IpRiskResponse) - Update DatabaseReader getter methods to return responses directly - Update annotations to use @MaxMindDbIpAddress and @MaxMindDbNetwork for context injection - Remove @MaxMindDbConstructor from Traits that was only needed for ConnectionType conversion - Add @MaxMindDbCreator to ConnectionType.fromString() for enum deserialization These constructors are no longer needed since IP address and network are now automatically injected via @MaxMindDbIpAddress and @MaxMindDbNetwork annotations, and enum conversion is handled by @MaxMindDbCreator. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f9065aa commit 317d84e

File tree

12 files changed

+48
-408
lines changed

12 files changed

+48
-408
lines changed

src/main/java/com/maxmind/geoip2/DatabaseReader.java

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ private Optional<CountryResponse> getCountry(
317317
return Optional.of(
318318
new CountryResponse(
319319
response,
320-
result.ipAddress(),
321-
result.network(),
322320
locales
323321
)
324322
);
@@ -354,12 +352,7 @@ private Optional<CityResponse> getCity(
354352
return Optional.empty();
355353
}
356354
return Optional.of(
357-
new CityResponse(
358-
response,
359-
result.ipAddress(),
360-
result.network(),
361-
locales
362-
)
355+
new CityResponse(response, locales)
363356
);
364357
}
365358

@@ -400,13 +393,7 @@ private Optional<AnonymousIpResponse> getAnonymousIp(
400393
if (response == null) {
401394
return Optional.empty();
402395
}
403-
return Optional.of(
404-
new AnonymousIpResponse(
405-
response,
406-
result.ipAddress(),
407-
result.network()
408-
)
409-
);
396+
return Optional.of(response);
410397
}
411398

412399
/**
@@ -447,13 +434,7 @@ private Optional<AnonymousPlusResponse> getAnonymousPlus(
447434
if (response == null) {
448435
return Optional.empty();
449436
}
450-
return Optional.of(
451-
new AnonymousPlusResponse(
452-
response,
453-
result.ipAddress(),
454-
result.network()
455-
)
456-
);
437+
return Optional.of(response);
457438
}
458439

459440

@@ -493,13 +474,7 @@ private Optional<IpRiskResponse> getIpRisk(InetAddress ipAddress) throws IOExcep
493474
if (response == null) {
494475
return Optional.empty();
495476
}
496-
return Optional.of(
497-
new IpRiskResponse(
498-
response,
499-
result.ipAddress(),
500-
result.network()
501-
)
502-
);
477+
return Optional.of(response);
503478
}
504479

505480
/**
@@ -538,13 +513,7 @@ private Optional<AsnResponse> getAsn(InetAddress ipAddress)
538513
if (response == null) {
539514
return Optional.empty();
540515
}
541-
return Optional.of(
542-
new AsnResponse(
543-
response,
544-
result.ipAddress(),
545-
result.network()
546-
)
547-
);
516+
return Optional.of(response);
548517
}
549518

550519
/**
@@ -584,13 +553,7 @@ private Optional<ConnectionTypeResponse> getConnectionType(
584553
if (response == null) {
585554
return Optional.empty();
586555
}
587-
return Optional.of(
588-
new ConnectionTypeResponse(
589-
response,
590-
result.ipAddress(),
591-
result.network()
592-
)
593-
);
556+
return Optional.of(response);
594557
}
595558

596559
/**
@@ -630,13 +593,7 @@ private Optional<DomainResponse> getDomain(
630593
if (response == null) {
631594
return Optional.empty();
632595
}
633-
return Optional.of(
634-
new DomainResponse(
635-
response,
636-
result.ipAddress(),
637-
result.network()
638-
)
639-
);
596+
return Optional.of(response);
640597
}
641598

642599
/**
@@ -677,12 +634,7 @@ private Optional<EnterpriseResponse> getEnterprise(
677634
return Optional.empty();
678635
}
679636
return Optional.of(
680-
new EnterpriseResponse(
681-
response,
682-
result.ipAddress(),
683-
result.network(),
684-
locales
685-
)
637+
new EnterpriseResponse(response, locales)
686638
);
687639
}
688640

@@ -723,13 +675,7 @@ private Optional<IspResponse> getIsp(
723675
if (response == null) {
724676
return Optional.empty();
725677
}
726-
return Optional.of(
727-
new IspResponse(
728-
response,
729-
result.ipAddress(),
730-
result.network()
731-
)
732-
);
678+
return Optional.of(response);
733679
}
734680

735681
/**

src/main/java/com/maxmind/geoip2/model/AnonymousIpResponse.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8+
import com.maxmind.db.MaxMindDbIpAddress;
9+
import com.maxmind.db.MaxMindDbNetwork;
810
import com.maxmind.db.MaxMindDbParameter;
911
import com.maxmind.db.Network;
1012
import com.maxmind.geoip2.JsonSerializable;
@@ -29,7 +31,7 @@
2931
*/
3032
public record AnonymousIpResponse(
3133
@JsonProperty("ip_address")
32-
@MaxMindDbParameter(name = "ip_address")
34+
@MaxMindDbIpAddress
3335
String ipAddress,
3436

3537
@JsonProperty("is_anonymous")
@@ -58,35 +60,10 @@ public record AnonymousIpResponse(
5860

5961
@JsonProperty("network")
6062
@JsonDeserialize(using = NetworkDeserializer.class)
61-
@MaxMindDbParameter(name = "network")
63+
@MaxMindDbNetwork
6264
Network network
6365
) implements JsonSerializable {
6466

65-
/**
66-
* Constructs an instance of {@code AnonymousIpResponse} from the values in the passed
67-
* response and the specified IP address and network.
68-
*
69-
* @param response the response to copy
70-
* @param ipAddress the IP address being checked
71-
* @param network the network associated with the record
72-
*/
73-
public AnonymousIpResponse(
74-
AnonymousIpResponse response,
75-
String ipAddress,
76-
Network network
77-
) {
78-
this(
79-
ipAddress,
80-
response.isAnonymous(),
81-
response.isAnonymousVpn(),
82-
response.isHostingProvider(),
83-
response.isPublicProxy(),
84-
response.isResidentialProxy(),
85-
response.isTorExitNode(),
86-
network
87-
);
88-
}
89-
9067
/**
9168
* @return The IP address that the data in the model is for.
9269
* @deprecated Use {@link #ipAddress()} instead. This method will be removed in 6.0.0.

src/main/java/com/maxmind/geoip2/model/AnonymousPlusResponse.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
88
import com.maxmind.db.MaxMindDbConstructor;
9+
import com.maxmind.db.MaxMindDbIpAddress;
10+
import com.maxmind.db.MaxMindDbNetwork;
911
import com.maxmind.db.MaxMindDbParameter;
1012
import com.maxmind.db.Network;
1113
import com.maxmind.geoip2.JsonSerializable;
@@ -37,7 +39,7 @@
3739
*/
3840
public record AnonymousPlusResponse(
3941
@JsonProperty("ip_address")
40-
@MaxMindDbParameter(name = "ip_address")
42+
@MaxMindDbIpAddress
4143
String ipAddress,
4244

4345
@JsonProperty("is_anonymous")
@@ -66,7 +68,7 @@ public record AnonymousPlusResponse(
6668

6769
@JsonProperty("network")
6870
@JsonDeserialize(using = NetworkDeserializer.class)
69-
@MaxMindDbParameter(name = "network")
71+
@MaxMindDbNetwork
7072
Network network,
7173

7274
@JsonProperty("anonymizer_confidence")
@@ -100,7 +102,7 @@ public record AnonymousPlusResponse(
100102
*/
101103
@MaxMindDbConstructor
102104
public AnonymousPlusResponse(
103-
@MaxMindDbParameter(name = "ip_address") String ipAddress,
105+
@MaxMindDbIpAddress String ipAddress,
104106
@MaxMindDbParameter(name = "is_anonymous", useDefault = true)
105107
boolean isAnonymous,
106108
@MaxMindDbParameter(name = "is_anonymous_vpn", useDefault = true)
@@ -113,7 +115,7 @@ public AnonymousPlusResponse(
113115
boolean isResidentialProxy,
114116
@MaxMindDbParameter(name = "is_tor_exit_node", useDefault = true)
115117
boolean isTorExitNode,
116-
@MaxMindDbParameter(name = "network") Network network,
118+
@MaxMindDbNetwork Network network,
117119
@MaxMindDbParameter(name = "anonymizer_confidence") Integer anonymizerConfidence,
118120
@MaxMindDbParameter(name = "network_last_seen") String networkLastSeen,
119121
@MaxMindDbParameter(name = "provider_name") String providerName
@@ -133,34 +135,6 @@ public AnonymousPlusResponse(
133135
);
134136
}
135137

136-
/**
137-
* Constructs an instance of {@code AnonymousPlusResponse} from the values in the
138-
* response and the specified IP address and network.
139-
*
140-
* @param response the response to copy
141-
* @param ipAddress the IP address being checked
142-
* @param network the network associated with the record
143-
*/
144-
public AnonymousPlusResponse(
145-
AnonymousPlusResponse response,
146-
String ipAddress,
147-
Network network
148-
) {
149-
this(
150-
ipAddress,
151-
response.isAnonymous(),
152-
response.isAnonymousVpn(),
153-
response.isHostingProvider(),
154-
response.isPublicProxy(),
155-
response.isResidentialProxy(),
156-
response.isTorExitNode(),
157-
network,
158-
response.anonymizerConfidence(),
159-
response.networkLastSeen(),
160-
response.providerName()
161-
);
162-
}
163-
164138
/**
165139
* @return The IP address that the data in the model is for.
166140
* @deprecated Use {@link #ipAddress()} instead. This method will be removed in 6.0.0.

src/main/java/com/maxmind/geoip2/model/AsnResponse.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8+
import com.maxmind.db.MaxMindDbIpAddress;
9+
import com.maxmind.db.MaxMindDbNetwork;
810
import com.maxmind.db.MaxMindDbParameter;
911
import com.maxmind.db.Network;
1012
import com.maxmind.geoip2.JsonSerializable;
@@ -30,35 +32,15 @@ public record AsnResponse(
3032
String autonomousSystemOrganization,
3133

3234
@JsonProperty("ip_address")
33-
@MaxMindDbParameter(name = "ip_address")
35+
@MaxMindDbIpAddress
3436
String ipAddress,
3537

3638
@JsonProperty("network")
3739
@JsonDeserialize(using = NetworkDeserializer.class)
38-
@MaxMindDbParameter(name = "network")
40+
@MaxMindDbNetwork
3941
Network network
4042
) implements JsonSerializable {
4143

42-
/**
43-
* Constructs an instance of {@code AsnResponse} with only the specified values set.
44-
*
45-
* @param response The {@code AsnResponse} object to copy.
46-
* @param ipAddress The IP address that the data in the model is for.
47-
* @param network The network associated with the record.
48-
*/
49-
public AsnResponse(
50-
AsnResponse response,
51-
String ipAddress,
52-
Network network
53-
) {
54-
this(
55-
response.autonomousSystemNumber(),
56-
response.autonomousSystemOrganization(),
57-
ipAddress,
58-
network
59-
);
60-
}
61-
6244
/**
6345
* @return The autonomous system number associated with the IP address.
6446
* @deprecated Use {@link #autonomousSystemNumber()} instead. This method will be removed

src/main/java/com/maxmind/geoip2/model/CityResponse.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,10 @@ public record CityResponse(
108108
* Constructs an instance of {@code CityResponse} with the specified parameters.
109109
*
110110
* @param response the response
111-
* @param ipAddress the IP address that the data in the model is for.
112-
* @param network the network associated with the record.
113111
* @param locales the locales
114112
*/
115113
public CityResponse(
116114
CityResponse response,
117-
String ipAddress,
118-
Network network,
119115
List<String> locales
120116
) {
121117
this(
@@ -128,7 +124,7 @@ public CityResponse(
128124
new Country(response.registeredCountry(), locales),
129125
new RepresentedCountry(response.representedCountry(), locales),
130126
mapSubdivisions(response.subdivisions(), locales),
131-
new Traits(response.traits(), ipAddress, network)
127+
response.traits()
132128
);
133129
}
134130

0 commit comments

Comments
 (0)