Skip to content

Commit 958e2a4

Browse files
committed
Apply manual style fixes
1 parent 6e59bd2 commit 958e2a4

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

checkstyle-suppressions.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
5+
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
6+
7+
<suppressions>
8+
<suppress checks="AbbreviationAsWordInName" files="CHMCache.java" lines="11"/>
9+
</suppressions>

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<configuration>
5454
<consoleOutput>true</consoleOutput>
5555
<configLocation>checkstyle.xml</configLocation>
56+
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
5657
<violationSeverity>warning</violationSeverity>
5758
</configuration>
5859
<dependencies>

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ final class BufferHolder {
6060
ByteBuffer get() {
6161
// The Java API docs for buffer state:
6262
//
63-
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than
64-
// one thread then access to the buffer should be controlled by appropriate synchronization.
63+
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be
64+
// used by more than one thread then access to the buffer should be controlled by
65+
// appropriate synchronization.
6566
//
66-
// As such, you may think that this should be synchronized. This used to be the case, but we had several
67-
// complaints about the synchronization causing contention, e.g.:
67+
// As such, you may think that this should be synchronized. This used to be the case, but
68+
// we had several complaints about the synchronization causing contention, e.g.:
6869
//
6970
// * https://github.com/maxmind/MaxMind-DB-Reader-java/issues/65
7071
// * https://github.com/maxmind/MaxMind-DB-Reader-java/pull/69
7172
//
72-
// Given that we are not modifying the original ByteBuffer in any way and all currently known and most
73-
// reasonably imaginable implementations of duplicate() only do read operations on the original buffer object,
74-
// the risk of not synchronizing this call seems relatively low and worth taking for the performance benefit
75-
// when lookups are being done from many threads.
73+
// Given that we are not modifying the original ByteBuffer in any way and all currently
74+
// known and most reasonably imaginable implementations of duplicate() only do read
75+
// operations on the original buffer object, the risk of not synchronizing this call seems
76+
// relatively low and worth taking for the performance benefit when lookups are being done
77+
// from many threads.
7678
return this.buffer.duplicate();
7779
}
7880
}

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

+17-19
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class Decoder {
3030

3131
// XXX - This is only for unit testings. We should possibly make a
3232
// constructor to set this
33-
boolean POINTER_TEST_HACK = false;
33+
boolean pointerTestHack = false;
3434

3535
private final NodeCache cache;
3636

@@ -105,7 +105,7 @@ private <T> DecodedValue decode(Class<T> cls, java.lang.reflect.Type genericType
105105
long pointer = packed + this.pointerBase + POINTER_VALUE_OFFSETS[pointerSize];
106106

107107
// for unit testing
108-
if (this.POINTER_TEST_HACK) {
108+
if (this.pointerTestHack) {
109109
return new DecodedValue(pointer);
110110
}
111111

@@ -163,9 +163,8 @@ private <T> Object decodeByType(
163163
case ARRAY:
164164
Class<?> elementClass = Object.class;
165165
if (genericType instanceof ParameterizedType) {
166-
ParameterizedType pType = (ParameterizedType) genericType;
167-
java.lang.reflect.Type[] actualTypes
168-
= pType.getActualTypeArguments();
166+
ParameterizedType ptype = (ParameterizedType) genericType;
167+
java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
169168
if (actualTypes.length == 1) {
170169
elementClass = (Class<?>) actualTypes[0];
171170
}
@@ -302,9 +301,9 @@ private <T, V> List<V> decodeArray(
302301
@SuppressWarnings("unchecked")
303302
List<V> array2 = (List<V>) constructor.newInstance(parameters);
304303
array = array2;
305-
} catch (InstantiationException |
306-
IllegalAccessException |
307-
InvocationTargetException e) {
304+
} catch (InstantiationException
305+
| IllegalAccessException
306+
| InvocationTargetException e) {
308307
throw new DeserializationException("Error creating list: " + e.getMessage(), e);
309308
}
310309
}
@@ -325,9 +324,8 @@ private <T> Object decodeMap(
325324
if (Map.class.isAssignableFrom(cls) || cls.equals(Object.class)) {
326325
Class<?> valueClass = Object.class;
327326
if (genericType instanceof ParameterizedType) {
328-
ParameterizedType pType = (ParameterizedType) genericType;
329-
java.lang.reflect.Type[] actualTypes
330-
= pType.getActualTypeArguments();
327+
ParameterizedType ptype = (ParameterizedType) genericType;
328+
java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
331329
if (actualTypes.length == 2) {
332330
Class<?> keyClass = (Class<?>) actualTypes[0];
333331
if (!keyClass.equals(String.class)) {
@@ -364,9 +362,9 @@ private <T, V> Map<String, V> decodeMapIntoMap(
364362
@SuppressWarnings("unchecked")
365363
Map<String, V> map2 = (Map<String, V>) constructor.newInstance(parameters);
366364
map = map2;
367-
} catch (InstantiationException |
368-
IllegalAccessException |
369-
InvocationTargetException e) {
365+
} catch (InstantiationException
366+
| IllegalAccessException
367+
| InvocationTargetException e) {
370368
throw new DeserializationException("Error creating map: " + e.getMessage(), e);
371369
}
372370
}
@@ -388,7 +386,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
388386
java.lang.reflect.Type[] parameterGenericTypes;
389387
Map<String, Integer> parameterIndexes;
390388
if (cachedConstructor == null) {
391-
constructor = this.findConstructor(cls);
389+
constructor = findConstructor(cls);
392390

393391
parameterTypes = constructor.getParameterTypes();
394392

@@ -397,7 +395,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
397395
parameterIndexes = new HashMap<>();
398396
Annotation[][] annotations = constructor.getParameterAnnotations();
399397
for (int i = 0; i < constructor.getParameterCount(); i++) {
400-
String parameterName = this.getParameterName(cls, i, annotations[i]);
398+
String parameterName = getParameterName(cls, i, annotations[i]);
401399
parameterIndexes.put(parameterName, i);
402400
}
403401

@@ -436,9 +434,9 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
436434

437435
try {
438436
return constructor.newInstance(parameters);
439-
} catch (InstantiationException |
440-
IllegalAccessException |
441-
InvocationTargetException e) {
437+
} catch (InstantiationException
438+
| IllegalAccessException
439+
| InvocationTargetException e) {
442440
throw new DeserializationException("Error creating object: " + e.getMessage(), e);
443441
} catch (IllegalArgumentException e) {
444442
StringBuilder sbErrors = new StringBuilder();

src/test/java/com/maxmind/db/DecoderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ private static <T> void testTypeDecoding(Type type, Map<T, byte[]> tests)
430430
MappedByteBuffer mmap = fc.map(MapMode.READ_ONLY, 0, fc.size());
431431

432432
Decoder decoder = new Decoder(cache, mmap, 0);
433-
decoder.POINTER_TEST_HACK = true;
433+
decoder.pointerTestHack = true;
434434

435435
// XXX - this could be streamlined
436436
if (type.equals(Type.BYTES)) {

0 commit comments

Comments
 (0)