11package com .maxmind .db ;
22
3- import java .math .BigInteger ;
3+ import java .util .ArrayList ;
4+ import java .util .Date ;
5+ import java .util .HashMap ;
6+ import java .util .List ;
7+ import java .util .Map ;
48
9+ import com .fasterxml .jackson .core .type .TypeReference ;
510import com .fasterxml .jackson .databind .JsonNode ;
11+ import com .fasterxml .jackson .databind .ObjectMapper ;
612
7- // XXX - if we make this public, add getters
8- final class Metadata {
9- final int binaryFormatMajorVersion ;
10- final int binaryFormatMinorVersion ;
11- private final BigInteger buildEpoch ;
12- final String databaseType ;
13- final JsonNode description ;
14- final int ipVersion ;
15- final int nodeCount ;
16- final int recordSize ;
17- final int nodeByteSize ;
18- final int searchTreeSize ;
19- final JsonNode languages ;
20-
21- public Metadata (JsonNode metadata ) {
13+ public final class Metadata {
14+ private final int binaryFormatMajorVersion ;
15+ private final int binaryFormatMinorVersion ;
16+
17+ private final long buildEpoch ;
18+
19+ private final String databaseType ;
20+
21+ private final JsonNode description ;
22+
23+ private final int ipVersion ;
24+
25+ private final JsonNode languages ;
26+
27+ private final int nodeByteSize ;
28+
29+ private final int nodeCount ;
30+
31+ private final int recordSize ;
32+
33+ private final int searchTreeSize ;
34+
35+ Metadata (JsonNode metadata ) {
2236 this .binaryFormatMajorVersion = metadata .get (
2337 "binary_format_major_version" ).asInt ();
2438 this .binaryFormatMinorVersion = metadata .get (
2539 "binary_format_minor_version" ).asInt ();
26- this .buildEpoch = metadata .get ("build_epoch" ).bigIntegerValue ();
40+ this .buildEpoch = metadata .get ("build_epoch" ).asLong ();
2741 this .databaseType = metadata .get ("database_type" ).asText ();
2842 this .languages = metadata .get ("languages" );
2943 this .description = metadata .get ("description" );
@@ -34,6 +48,91 @@ public Metadata(JsonNode metadata) {
3448 this .searchTreeSize = this .nodeCount * this .nodeByteSize ;
3549 }
3650
51+ /**
52+ * @return the major version number for the database's binary format.
53+ */
54+ public int getBinaryFormatMajorVersion () {
55+ return this .binaryFormatMajorVersion ;
56+ }
57+
58+ /**
59+ * @return the minor version number for the database's binary format.
60+ */
61+ public int getBinaryFormatMinorVersion () {
62+ return this .binaryFormatMinorVersion ;
63+ }
64+
65+ /**
66+ * @return the date of the database build.
67+ */
68+ public Date getBuildDate () {
69+ return new Date (this .buildEpoch * 1000 );
70+ }
71+
72+ /**
73+ * @return a string that indicates the structure of each data record
74+ * associated with an IP address. The actual definition of these
75+ * structures is left up to the database creator.
76+ */
77+ public String getDatabaseType () {
78+ return this .databaseType ;
79+ }
80+
81+ /**
82+ * @return map from language code to description in that language.
83+ */
84+ public Map <String , String > getDescription () {
85+ return new ObjectMapper ().convertValue (this .description ,
86+ new TypeReference <HashMap <String , String >>() {
87+ });
88+ }
89+
90+ /**
91+ * @return whether the database contains IPv4 or IPv6 address data. The only
92+ * possible values are 4 and 6.
93+ */
94+ public int getIpVersion () {
95+ return this .ipVersion ;
96+ }
97+
98+ /**
99+ * @return list of languages supported by the database.
100+ */
101+ public List <String > getLanguages () {
102+ return new ObjectMapper ().convertValue (this .languages ,
103+ new TypeReference <ArrayList <String >>() {
104+ });
105+ }
106+
107+ /**
108+ * @return the nodeByteSize
109+ */
110+ int getNodeByteSize () {
111+ return this .nodeByteSize ;
112+ }
113+
114+ /**
115+ * @return the number of nodes in the search tree.
116+ */
117+ int getNodeCount () {
118+ return this .nodeCount ;
119+ }
120+
121+ /**
122+ * @return the number of bits in a record in the search tree. Note that each
123+ * node consists of two records.
124+ */
125+ int getRecordSize () {
126+ return this .recordSize ;
127+ }
128+
129+ /**
130+ * @return the searchTreeSize
131+ */
132+ int getSearchTreeSize () {
133+ return this .searchTreeSize ;
134+ }
135+
37136 /*
38137 * (non-Javadoc)
39138 *
0 commit comments