Skip to content

Commit 54677ee

Browse files
authored
Merge pull request #152 from maxmind/sromani/improve-docs
Sromani/improve docs
2 parents 3886c66 + dbe1e8f commit 54677ee

16 files changed

+151
-48
lines changed

checkstyle.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,39 +314,43 @@
314314
</module>
315315
<module name="NonEmptyAtclauseDescription"/>
316316
<module name="InvalidJavadocPosition"/>
317-
<!-- <module name="JavadocTagContinuationIndentation"/> -->
317+
<module name="JavadocTagContinuationIndentation"/>
318318
<!-- <module name="SummaryJavadoc">
319319
<property name="forbiddenSummaryFragments"
320320
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
321321
</module> -->
322322
<!-- <module name="JavadocParagraph"/>
323-
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
324323
<module name="AtclauseOrder">
325324
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
326325
<property name="target"
327326
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
328327
</module> -->
328+
<module name="RequireEmptyLineBeforeBlockTagGroup"/>
329329
<module name="JavadocMethod">
330330
<property name="accessModifiers" value="public"/>
331331
<property name="allowMissingParamTags" value="true"/>
332332
<property name="allowMissingReturnTag" value="true"/>
333333
<property name="allowedAnnotations" value="Override, Test"/>
334334
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
335335
</module>
336-
<!-- <module name="MissingJavadocMethod">
336+
<module name="MissingJavadocMethod">
337337
<property name="scope" value="public"/>
338-
<property name="minLineCount" value="2"/>
339338
<property name="allowedAnnotations" value="Override, Test"/>
340339
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF,
341340
COMPACT_CTOR_DEF"/>
342341
</module>
342+
<module name="JavadocType"/>
343+
<module name="JavadocVariable">
344+
<property name="tokens" value="VARIABLE_DEF"/>
345+
<property name="scope" value="public"/>
346+
</module>
343347
<module name="MissingJavadocType">
344348
<property name="scope" value="protected"/>
345349
<property name="tokens"
346350
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
347351
RECORD_DEF, ANNOTATION_DEF"/>
348352
<property name="excludeScope" value="nothing"/>
349-
</module> -->
353+
</module>
350354
<module name="MethodName">
351355
<property name="format" value="^[a-z][a-z0-9]\w*$"/>
352356
<message key="name.invalidPattern"

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
<groupId>org.apache.maven.plugins</groupId>
132132
<artifactId>maven-javadoc-plugin</artifactId>
133133
<version>3.6.3</version>
134+
<configuration>
135+
<doclint>-missing</doclint>
136+
</configuration>
134137
<executions>
135138
<execution>
136139
<goals>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ public class CHMCache implements NodeCache {
1616
private final ConcurrentHashMap<CacheKey, DecodedValue> cache;
1717
private boolean cacheFull = false;
1818

19+
/**
20+
* Creates a new cache with the default capacity.
21+
*/
1922
public CHMCache() {
2023
this(DEFAULT_CAPACITY);
2124
}
2225

26+
/**
27+
* Creates a new cache with the specified capacity.
28+
*
29+
* @param capacity
30+
* the maximum number of elements the cache can hold before
31+
* starting to evict them
32+
*/
2333
public CHMCache(int capacity) {
2434
this.capacity = capacity;
2535
this.cache = new ConcurrentHashMap<>(capacity);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.maxmind.db;
22

3+
/**
4+
* {@code CacheKey} is used as a key in the data-section cache. It contains the offset of the
5+
* value in the database file, the class of the value, and the type
6+
* of the value.
7+
*
8+
* @param <T> the type of value
9+
*/
310
public final class CacheKey<T> {
411
private final int offset;
512
private final Class<T> cls;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/**
66
* DatabaseRecord represents the data and metadata associated with a database
77
* lookup.
8+
*
9+
* @param <T> the type to deserialize the returned value to
810
*/
911
public final class DatabaseRecord<T> {
1012
private final T data;
@@ -23,17 +25,18 @@ public DatabaseRecord(T data, InetAddress ipAddress, int prefixLength) {
2325
}
2426

2527
/**
26-
* @return the data for the record in the database. The record will be
27-
* <code>null</code> if there was no data for the address in the database.
28+
* @return the data for the record in the database. The record will be
29+
* <code>null</code> if there was no data for the address in the
30+
* database.
2831
*/
2932
public T getData() {
3033
return data;
3134
}
3235

3336
/**
3437
* @return the network associated with the record in the database. This is
35-
* the largest network where all of the IPs in the network have the same
36-
* data.
38+
* the largest network where all of the IPs in the network have the same
39+
* data.
3740
*/
3841
public Network getNetwork() {
3942
return network;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.maxmind.db;
22

3+
/**
4+
* {@code DecodedValue} is a wrapper for the decoded value and the number of bytes used
5+
* to decode it.
6+
*/
37
public final class DecodedValue {
48
final Object value;
59

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import java.net.InetAddress;
44

5+
/**
6+
* This is a custom exception that is thrown when the user attempts to use an
7+
* IPv6 address in an IPv4-only database.
8+
*/
59
public class InvalidNetworkException extends Exception {
10+
/**
11+
* @param ip the IP address that was used
12+
*/
613
public InvalidNetworkException(InetAddress ip) {
714
super("you attempted to use an IPv6 network in an IPv4-only database: " + ip.toString());
815
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
55

6+
/**
7+
* {@code MaxMindDbConstructor} is an annotation that can be used to mark a constructor
8+
* that should be used to create an instance of a class when decoding a MaxMind
9+
* DB file.
10+
*/
611
@Retention(RetentionPolicy.RUNTIME)
712
public @interface MaxMindDbConstructor {
813
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
55

6+
/**
7+
* Interface for a MaxMind DB parameter. This is used to mark a parameter that
8+
* should be used to create an instance of a class when decoding a MaxMind DB
9+
* file.
10+
*/
611
@Retention(RetentionPolicy.RUNTIME)
712
public @interface MaxMindDbParameter {
13+
/**
14+
* @return the name of the parameter in the MaxMind DB file
15+
*/
816
String name();
917
}

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

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
/**
9+
* {@code Metadata} holds data associated with the database itself.
10+
*/
811
public final class Metadata {
912
private final int binaryFormatMajorVersion;
1013
private final int binaryFormatMinorVersion;
@@ -27,27 +30,40 @@ public final class Metadata {
2730

2831
private final int searchTreeSize;
2932

33+
/**
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.
55+
*/
3056
@MaxMindDbConstructor
3157
public Metadata(
32-
@MaxMindDbParameter(name = "binary_format_major_version")
33-
int binaryFormatMajorVersion,
34-
@MaxMindDbParameter(name = "binary_format_minor_version")
35-
int binaryFormatMinorVersion,
36-
@MaxMindDbParameter(name = "build_epoch")
37-
BigInteger buildEpoch,
38-
@MaxMindDbParameter(name = "database_type")
39-
String databaseType,
40-
@MaxMindDbParameter(name = "languages")
41-
List<String> languages,
42-
@MaxMindDbParameter(name = "description")
43-
Map<String, String> description,
44-
@MaxMindDbParameter(name = "ip_version")
45-
int ipVersion,
46-
@MaxMindDbParameter(name = "node_count")
47-
long nodeCount,
48-
@MaxMindDbParameter(name = "record_size")
49-
int recordSize
50-
) {
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) {
5167
this.binaryFormatMajorVersion = binaryFormatMajorVersion;
5268
this.binaryFormatMinorVersion = binaryFormatMinorVersion;
5369
this.buildEpoch = buildEpoch;
@@ -85,8 +101,8 @@ public Date getBuildDate() {
85101

86102
/**
87103
* @return a string that indicates the structure of each data record
88-
* associated with an IP address. The actual definition of these
89-
* structures is left up to the database creator.
104+
* associated with an IP address. The actual definition of these
105+
* structures is left up to the database creator.
90106
*/
91107
public String getDatabaseType() {
92108
return this.databaseType;
@@ -101,7 +117,7 @@ public Map<String, String> getDescription() {
101117

102118
/**
103119
* @return whether the database contains IPv4 or IPv6 address data. The only
104-
* possible values are 4 and 6.
120+
* possible values are 4 and 6.
105121
*/
106122
public int getIpVersion() {
107123
return this.ipVersion;
@@ -130,7 +146,7 @@ int getNodeCount() {
130146

131147
/**
132148
* @return the number of bits in a record in the search tree. Note that each
133-
* node consists of two records.
149+
* node consists of two records.
134150
*/
135151
int getRecordSize() {
136152
return this.recordSize;
@@ -151,11 +167,11 @@ int getSearchTreeSize() {
151167
@Override
152168
public String toString() {
153169
return "Metadata [binaryFormatMajorVersion="
154-
+ this.binaryFormatMajorVersion + ", binaryFormatMinorVersion="
155-
+ this.binaryFormatMinorVersion + ", buildEpoch="
156-
+ this.buildEpoch + ", databaseType=" + this.databaseType
157-
+ ", description=" + this.description + ", ipVersion="
158-
+ this.ipVersion + ", nodeCount=" + this.nodeCount
159-
+ ", recordSize=" + this.recordSize + "]";
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 + "]";
160176
}
161177
}

0 commit comments

Comments
 (0)