Skip to content

Commit 0d7b549

Browse files
oschwaldclaude
andcommitted
Convert CtrlData to record
Converts the CtrlData class to use Java 17 records, reducing boilerplate and improving memory layout. Updates all getter method calls to use record accessors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2547e16 commit 0d7b549

File tree

3 files changed

+232
-32
lines changed

3 files changed

+232
-32
lines changed

pom.xml.versionsBackup

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.maxmind.db</groupId>
5+
<artifactId>maxmind-db</artifactId>
6+
<version>3.1.2-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<name>MaxMind DB Reader</name>
9+
<description>Reader for MaxMind DB</description>
10+
<url>http://dev.maxmind.com/</url>
11+
<licenses>
12+
<license>
13+
<name>Apache License 2.0</name>
14+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
15+
<distribution>repo</distribution>
16+
</license>
17+
</licenses>
18+
<organization>
19+
<name>MaxMind, Inc.</name>
20+
<url>http://www.maxmind.com/</url>
21+
</organization>
22+
<scm>
23+
<url>https://github.com/maxmind/MaxMind-DB-Reader-java</url>
24+
<connection>scm:git:git://github.com:maxmind/MaxMind-DB-Reader-java.git</connection>
25+
<developerConnection>scm:git:[email protected]:maxmind/MaxMind-DB-Reader-java.git</developerConnection>
26+
<tag>HEAD</tag>
27+
</scm>
28+
<issueManagement>
29+
<url>https://github.com/maxmind/MaxMind-DB-Reader-java/issues</url>
30+
<system>GitHub</system>
31+
</issueManagement>
32+
<developers>
33+
<developer>
34+
<id>oschwald</id>
35+
<name>Gregory J. Oschwald</name>
36+
<email>[email protected]</email>
37+
</developer>
38+
</developers>
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.junit.jupiter</groupId>
42+
<artifactId>junit-jupiter</artifactId>
43+
<version>5.12.2</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.hamcrest</groupId>
48+
<artifactId>java-hamcrest</artifactId>
49+
<version>2.0.0.0</version>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-enforcer-plugin</artifactId>
58+
<version>3.5.0</version>
59+
<executions>
60+
<execution>
61+
<id>enforce-maven</id>
62+
<goals>
63+
<goal>enforce</goal>
64+
</goals>
65+
<configuration>
66+
<rules>
67+
<requireMavenVersion>
68+
<version>3.6.3</version>
69+
</requireMavenVersion>
70+
</rules>
71+
</configuration>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-checkstyle-plugin</artifactId>
78+
<version>3.6.0</version>
79+
<configuration>
80+
<consoleOutput>true</consoleOutput>
81+
<configLocation>checkstyle.xml</configLocation>
82+
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
83+
<violationSeverity>warning</violationSeverity>
84+
</configuration>
85+
<dependencies>
86+
<dependency>
87+
<groupId>com.puppycrawl.tools</groupId>
88+
<artifactId>checkstyle</artifactId>
89+
<version>10.24.0</version>
90+
</dependency>
91+
</dependencies>
92+
<executions>
93+
<execution>
94+
<id>test</id>
95+
<phase>test</phase>
96+
<goals>
97+
<goal>check</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-gpg-plugin</artifactId>
105+
<version>3.2.7</version>
106+
<executions>
107+
<execution>
108+
<id>sign-artifacts</id>
109+
<phase>verify</phase>
110+
<goals>
111+
<goal>sign</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-source-plugin</artifactId>
119+
<version>3.3.1</version>
120+
<executions>
121+
<execution>
122+
<id>attach-sources</id>
123+
<phase>package</phase>
124+
<goals>
125+
<goal>jar-no-fork</goal>
126+
</goals>
127+
</execution>
128+
</executions>
129+
</plugin>
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-javadoc-plugin</artifactId>
133+
<version>3.11.2</version>
134+
<configuration>
135+
<doclint>-missing</doclint>
136+
</configuration>
137+
<executions>
138+
<execution>
139+
<goals>
140+
<goal>jar</goal>
141+
</goals>
142+
</execution>
143+
</executions>
144+
</plugin>
145+
<plugin>
146+
<groupId>org.apache.maven.plugins</groupId>
147+
<artifactId>maven-compiler-plugin</artifactId>
148+
<version>3.14.0</version>
149+
<configuration>
150+
<release>11</release>
151+
<source>11</source>
152+
<target>11</target>
153+
</configuration>
154+
</plugin>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-surefire-plugin</artifactId>
158+
<version>3.5.3</version>
159+
</plugin>
160+
<plugin>
161+
<groupId>org.codehaus.mojo</groupId>
162+
<artifactId>versions-maven-plugin</artifactId>
163+
<version>2.18.0</version>
164+
</plugin>
165+
<plugin>
166+
<groupId>org.sonatype.central</groupId>
167+
<artifactId>central-publishing-maven-plugin</artifactId>
168+
<version>0.7.0</version>
169+
<extensions>true</extensions>
170+
<configuration>
171+
<publishingServerId>central</publishingServerId>
172+
<autoPublish>true</autoPublish>
173+
</configuration>
174+
</plugin>
175+
</plugins>
176+
</build>
177+
<properties>
178+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
179+
</properties>
180+
<profiles>
181+
<profile>
182+
<id>not-windows</id>
183+
<!--
184+
Starting with 3.1.0, this fails on Windows. Given that we only
185+
technically need this when release and we don't release on Windows,
186+
we can just disable it on Widnows. See this issue:
187+
https://github.com/mojohaus/exec-maven-plugin/issues/373
188+
-->
189+
<activation>
190+
<os><family>!Windows</family></os>
191+
</activation>
192+
<build>
193+
<plugins>
194+
<plugin>
195+
<!--
196+
We need this for updating the submodule during release. Maven SCM
197+
doesn't support this itself apparently. See
198+
https://github.com/apache/maven-scm/pull/179
199+
-->
200+
<groupId>org.codehaus.mojo</groupId>
201+
<artifactId>exec-maven-plugin</artifactId>
202+
<version>3.5.1</version>
203+
<executions>
204+
<execution>
205+
<phase>initialize</phase>
206+
<id>invoke build</id>
207+
<goals>
208+
<goal>exec</goal>
209+
</goals>
210+
</execution>
211+
</executions>
212+
<configuration>
213+
<executable>git</executable>
214+
<commandlineArgs>submodule update --init --recursive</commandlineArgs>
215+
</configuration>
216+
</plugin>
217+
</plugins>
218+
</build>
219+
</profile>
220+
</profiles>
221+
<distributionManagement>
222+
<repository>
223+
<id>sonatype-nexus-staging</id>
224+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
225+
</repository>
226+
</distributionManagement>
227+
</project>
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
package com.maxmind.db;
22

3-
final class CtrlData {
4-
private final Type type;
5-
private final int ctrlByte;
6-
private final int offset;
7-
private final int size;
8-
9-
CtrlData(Type type, int ctrlByte, int offset, int size) {
10-
this.type = type;
11-
this.ctrlByte = ctrlByte;
12-
this.offset = offset;
13-
this.size = size;
14-
}
15-
16-
public Type getType() {
17-
return this.type;
18-
}
19-
20-
public int getCtrlByte() {
21-
return this.ctrlByte;
22-
}
23-
24-
public int getOffset() {
25-
return this.offset;
26-
}
27-
28-
public int getSize() {
29-
return this.size;
30-
}
3+
record CtrlData(Type type, int ctrlByte, int offset, int size) {
314
}

src/main/java/com/maxmind/db/Decoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,11 @@ private int nextValueOffset(int offset, int numberToSkip)
495495
}
496496

497497
CtrlData ctrlData = this.getCtrlData(offset);
498-
int ctrlByte = ctrlData.getCtrlByte();
499-
int size = ctrlData.getSize();
500-
offset = ctrlData.getOffset();
498+
int ctrlByte = ctrlData.ctrlByte();
499+
int size = ctrlData.size();
500+
offset = ctrlData.offset();
501501

502-
Type type = ctrlData.getType();
502+
Type type = ctrlData.type();
503503
switch (type) {
504504
case POINTER:
505505
int pointerSize = ((ctrlByte >>> 3) & 0x3) + 1;

0 commit comments

Comments
 (0)