|
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * {@code Metadata} holds data associated with the database itself. |
| 10 | + * |
| 11 | + * @param binaryFormatMajorVersion The major version number for the database's |
| 12 | + * binary format. |
| 13 | + * @param binaryFormatMinorVersion The minor version number for the database's |
| 14 | + * binary format. |
| 15 | + * @param buildEpoch The date of the database build. |
| 16 | + * @param databaseType A string that indicates the structure of each |
| 17 | + * data record associated with an IP address. |
| 18 | + * The actual definition of these structures is |
| 19 | + * left up to the database creator. |
| 20 | + * @param languages List of languages supported by the database. |
| 21 | + * @param description Map from language code to description in that |
| 22 | + * language. |
| 23 | + * @param ipVersion Whether the database contains IPv4 or IPv6 |
| 24 | + * address data. The only possible values are 4 |
| 25 | + * and 6. |
| 26 | + * @param nodeCount The number of nodes in the search tree. |
| 27 | + * @param recordSize The number of bits in a record in the search |
| 28 | + * tree. Note that each node consists of two |
| 29 | + * records. |
10 | 30 | */ |
11 | | -public final class Metadata { |
12 | | - private final int binaryFormatMajorVersion; |
13 | | - private final int binaryFormatMinorVersion; |
14 | | - |
15 | | - private final BigInteger buildEpoch; |
16 | | - |
17 | | - private final String databaseType; |
18 | | - |
19 | | - private final Map<String, String> description; |
20 | | - |
21 | | - private final int ipVersion; |
22 | | - |
23 | | - private final List<String> languages; |
24 | | - |
25 | | - private final int nodeByteSize; |
26 | | - |
27 | | - private final long nodeCount; |
28 | | - |
29 | | - private final int recordSize; |
30 | | - |
31 | | - private final long searchTreeSize; |
32 | | - |
| 31 | +public record Metadata( |
| 32 | + @MaxMindDbParameter(name = "binary_format_major_version") int binaryFormatMajorVersion, |
| 33 | + @MaxMindDbParameter(name = "binary_format_minor_version") int binaryFormatMinorVersion, |
| 34 | + @MaxMindDbParameter(name = "build_epoch") BigInteger buildEpoch, |
| 35 | + @MaxMindDbParameter(name = "database_type") String databaseType, |
| 36 | + @MaxMindDbParameter(name = "languages") List<String> languages, |
| 37 | + @MaxMindDbParameter(name = "description") Map<String, String> description, |
| 38 | + @MaxMindDbParameter(name = "ip_version") int ipVersion, |
| 39 | + @MaxMindDbParameter(name = "node_count") long nodeCount, |
| 40 | + @MaxMindDbParameter(name = "record_size") int recordSize |
| 41 | +) { |
33 | 42 | /** |
34 | | - * Constructs a {@code Metadata} object. |
35 | | - * |
36 | | - * @param binaryFormatMajorVersion The major version number for the database's |
37 | | - * binary format. |
38 | | - * @param binaryFormatMinorVersion The minor version number for the database's |
39 | | - * binary format. |
40 | | - * @param buildEpoch The date of the database build. |
41 | | - * @param databaseType A string that indicates the structure of each |
42 | | - * data record associated with an IP address. |
43 | | - * The actual definition of these structures is |
44 | | - * left up to the database creator. |
45 | | - * @param languages List of languages supported by the database. |
46 | | - * @param description Map from language code to description in that |
47 | | - * language. |
48 | | - * @param ipVersion Whether the database contains IPv4 or IPv6 |
49 | | - * address data. The only possible values are 4 |
50 | | - * and 6. |
51 | | - * @param nodeCount The number of nodes in the search tree. |
52 | | - * @param recordSize The number of bits in a record in the search |
53 | | - * tree. Note that each node consists of two |
54 | | - * records. |
| 43 | + * Compact constructor for the Metadata record. |
55 | 44 | */ |
56 | 45 | @MaxMindDbConstructor |
57 | | - public Metadata( |
58 | | - @MaxMindDbParameter(name = "binary_format_major_version") int binaryFormatMajorVersion, |
59 | | - @MaxMindDbParameter(name = "binary_format_minor_version") int binaryFormatMinorVersion, |
60 | | - @MaxMindDbParameter(name = "build_epoch") BigInteger buildEpoch, |
61 | | - @MaxMindDbParameter(name = "database_type") String databaseType, |
62 | | - @MaxMindDbParameter(name = "languages") List<String> languages, |
63 | | - @MaxMindDbParameter(name = "description") Map<String, String> description, |
64 | | - @MaxMindDbParameter(name = "ip_version") int ipVersion, |
65 | | - @MaxMindDbParameter(name = "node_count") long nodeCount, |
66 | | - @MaxMindDbParameter(name = "record_size") int recordSize) { |
67 | | - this.binaryFormatMajorVersion = binaryFormatMajorVersion; |
68 | | - this.binaryFormatMinorVersion = binaryFormatMinorVersion; |
69 | | - this.buildEpoch = buildEpoch; |
70 | | - this.databaseType = databaseType; |
71 | | - this.languages = languages; |
72 | | - this.description = description; |
73 | | - this.ipVersion = ipVersion; |
74 | | - this.nodeCount = nodeCount; |
75 | | - this.recordSize = recordSize; |
76 | | - |
77 | | - this.nodeByteSize = this.recordSize / 4; |
78 | | - this.searchTreeSize = this.nodeCount * this.nodeByteSize; |
79 | | - } |
80 | | - |
81 | | - /** |
82 | | - * @return the major version number for the database's binary format. |
83 | | - */ |
84 | | - public int getBinaryFormatMajorVersion() { |
85 | | - return this.binaryFormatMajorVersion; |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * @return the minor version number for the database's binary format. |
90 | | - */ |
91 | | - public int getBinaryFormatMinorVersion() { |
92 | | - return this.binaryFormatMinorVersion; |
93 | | - } |
| 46 | + public Metadata {} |
94 | 47 |
|
95 | 48 | /** |
96 | 49 | * @return the date of the database build. |
97 | 50 | */ |
98 | | - public Date getBuildDate() { |
99 | | - return new Date(this.buildEpoch.longValue() * 1000); |
100 | | - } |
101 | | - |
102 | | - /** |
103 | | - * @return a string that indicates the structure of each data record |
104 | | - * associated with an IP address. The actual definition of these |
105 | | - * structures is left up to the database creator. |
106 | | - */ |
107 | | - public String getDatabaseType() { |
108 | | - return this.databaseType; |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * @return map from language code to description in that language. |
113 | | - */ |
114 | | - public Map<String, String> getDescription() { |
115 | | - return this.description; |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * @return whether the database contains IPv4 or IPv6 address data. The only |
120 | | - * possible values are 4 and 6. |
121 | | - */ |
122 | | - public int getIpVersion() { |
123 | | - return this.ipVersion; |
124 | | - } |
125 | | - |
126 | | - /** |
127 | | - * @return list of languages supported by the database. |
128 | | - */ |
129 | | - public List<String> getLanguages() { |
130 | | - return this.languages; |
| 51 | + public Date buildDate() { |
| 52 | + return new Date(buildEpoch.longValue() * 1000); |
131 | 53 | } |
132 | 54 |
|
133 | 55 | /** |
134 | 56 | * @return the nodeByteSize |
135 | 57 | */ |
136 | | - int getNodeByteSize() { |
137 | | - return this.nodeByteSize; |
138 | | - } |
139 | | - |
140 | | - /** |
141 | | - * @return the number of nodes in the search tree. |
142 | | - */ |
143 | | - long getNodeCount() { |
144 | | - return this.nodeCount; |
145 | | - } |
146 | | - |
147 | | - /** |
148 | | - * @return the number of bits in a record in the search tree. Note that each |
149 | | - * node consists of two records. |
150 | | - */ |
151 | | - int getRecordSize() { |
152 | | - return this.recordSize; |
| 58 | + int nodeByteSize() { |
| 59 | + return recordSize / 4; |
153 | 60 | } |
154 | 61 |
|
155 | 62 | /** |
156 | 63 | * @return the searchTreeSize |
157 | 64 | */ |
158 | | - long getSearchTreeSize() { |
159 | | - return this.searchTreeSize; |
160 | | - } |
161 | | - |
162 | | - /* |
163 | | - * (non-Javadoc) |
164 | | - * |
165 | | - * @see java.lang.Object#toString() |
166 | | - */ |
167 | | - @Override |
168 | | - public String toString() { |
169 | | - return "Metadata [binaryFormatMajorVersion=" |
170 | | - + this.binaryFormatMajorVersion + ", binaryFormatMinorVersion=" |
171 | | - + this.binaryFormatMinorVersion + ", buildEpoch=" |
172 | | - + this.buildEpoch + ", databaseType=" + this.databaseType |
173 | | - + ", description=" + this.description + ", ipVersion=" |
174 | | - + this.ipVersion + ", nodeCount=" + this.nodeCount |
175 | | - + ", recordSize=" + this.recordSize + "]"; |
| 65 | + long searchTreeSize() { |
| 66 | + return nodeCount * nodeByteSize(); |
176 | 67 | } |
177 | 68 | } |
0 commit comments