Skip to content

Commit 52e6fc2

Browse files
committed
code inspection fixes
1 parent 9678b17 commit 52e6fc2

23 files changed

+203
-279
lines changed

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9-
## [2.0.0] - 2019-12-18
9+
## [2.0.0] - 2019-12-19
1010

1111
- performance improvements
1212
- raised minimum supported Java version to Java 7

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
<compilerArgs>
111111
<arg>-Werror</arg>
112112
</compilerArgs>
113-
<compilerArgument></compilerArgument>
114113
</configuration>
115114
</plugin>
116115

src/main/java/com/arangodb/velocypack/ObjectIterator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public VPackSlice getValue() {
7676
public String getKey() {
7777
try {
7878
return currentField.makeKey().getAsString();
79-
} catch (final VPackKeyTypeException e) {
80-
throw new NoSuchElementException();
81-
} catch (final VPackNeedAttributeTranslatorException e) {
79+
} catch (final VPackKeyTypeException | VPackNeedAttributeTranslatorException e) {
8280
throw new NoSuchElementException();
8381
}
8482
}

src/main/java/com/arangodb/velocypack/Type.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static java.lang.reflect.Type getTypeParameter(final Class<?> clazz) {
4545
if (superclass instanceof Class) {
4646
throw new RuntimeException("Missing type parameter.");
4747
}
48-
return ParameterizedType.class.cast(superclass).getActualTypeArguments()[0];
48+
return ((ParameterizedType) superclass).getActualTypeArguments()[0];
4949
}
5050

5151
public java.lang.reflect.Type getType() {

src/main/java/com/arangodb/velocypack/VPack.java

Lines changed: 40 additions & 49 deletions
Large diffs are not rendered by default.

src/main/java/com/arangodb/velocypack/VPackBuilder.java

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@
2020

2121
package com.arangodb.velocypack;
2222

23-
import java.io.UnsupportedEncodingException;
2423
import java.math.BigDecimal;
2524
import java.math.BigInteger;
2625
import java.nio.charset.StandardCharsets;
2726
import java.sql.Timestamp;
2827
import java.util.ArrayList;
2928
import java.util.Arrays;
3029
import java.util.Collection;
31-
import java.util.Collections;
3230
import java.util.Comparator;
3331
import java.util.Date;
34-
import java.util.HashMap;
3532
import java.util.List;
36-
import java.util.Map;
3733

3834
import com.arangodb.velocypack.exception.VPackBuilderException;
3935
import com.arangodb.velocypack.exception.VPackBuilderKeyAlreadyWrittenException;
@@ -47,7 +43,6 @@
4743
import com.arangodb.velocypack.internal.DefaultVPackBuilderOptions;
4844
import com.arangodb.velocypack.internal.Value;
4945
import com.arangodb.velocypack.internal.util.NumberUtil;
50-
import com.fasterxml.jackson.core.io.CharTypes;
5146

5247
/**
5348
* @author Mark Vollmary
@@ -59,7 +54,7 @@ public class VPackBuilder {
5954
private static final int LONG_BYTES = Long.SIZE / Byte.SIZE;
6055
private static final int DOUBLE_BYTES = Double.SIZE / Byte.SIZE;
6156

62-
public static interface BuilderOptions {
57+
public interface BuilderOptions {
6358
boolean isBuildUnindexedArrays();
6459

6560
void setBuildUnindexedArrays(boolean buildUnindexedArrays);
@@ -69,7 +64,7 @@ public static interface BuilderOptions {
6964
void setBuildUnindexedObjects(boolean buildUnindexedObjects);
7065
}
7166

72-
public static interface Appender<T> {
67+
public interface Appender<T> {
7368
void append(VPackBuilder builder, T value) throws VPackBuilderException;
7469
}
7570

@@ -218,7 +213,7 @@ public void append(final VPackBuilder builder, final VPackSlice value) throws VP
218213
private int size;
219214
private final List<Integer> stack; // Start positions of open
220215
// objects/arrays
221-
private List<List<Integer>> index; // Indices for starts
216+
private final List<List<Integer>> index; // Indices for starts
222217
// of
223218
// subindex
224219
private boolean keyWritten; // indicates that in the current object the key
@@ -234,8 +229,8 @@ public VPackBuilder(final BuilderOptions options) {
234229
this.options = options;
235230
size = 0;
236231
buffer = new byte[10];
237-
stack = new ArrayList<Integer>();
238-
index = new ArrayList<List<Integer>>(4);
232+
stack = new ArrayList<>();
233+
index = new ArrayList<>(4);
239234
}
240235

241236
public BuilderOptions getOptions() {
@@ -473,8 +468,8 @@ private <T> VPackBuilder addInternal(final String attribute, final Appender<T> a
473468
if (translate != null) {
474469
final byte[] trValue = translate.getRawVPack();
475470
ensureCapacity(size + trValue.length);
476-
for (int i = 0; i < trValue.length; i++) {
477-
addUnchecked(trValue[i]);
471+
for (byte b : trValue) {
472+
addUnchecked(b);
478473
}
479474
keyWritten = true;
480475
if (value == null) {
@@ -590,7 +585,7 @@ private void appendSmallInt(final long value) {
590585

591586
private void appendUInt(final BigInteger value) {
592587
add((byte) 0x2f);
593-
append(value, LONG_BYTES);
588+
append(value);
594589
}
595590

596591
private void append(final long value, final int length) {
@@ -600,10 +595,10 @@ private void append(final long value, final int length) {
600595
}
601596
}
602597

603-
private void append(final BigInteger value, final int length) {
604-
ensureCapacity(size + length);
605-
for (int i = length - 1; i >= 0; i--) {
606-
addUnchecked(value.shiftRight(length - i - 1 << 3).byteValue());
598+
private void append(final BigInteger value) {
599+
ensureCapacity(size + VPackBuilder.LONG_BYTES);
600+
for (int i = VPackBuilder.LONG_BYTES - 1; i >= 0; i--) {
601+
addUnchecked(value.shiftRight(VPackBuilder.LONG_BYTES - i - 1 << 3).byteValue());
607602
}
608603
}
609604

@@ -692,9 +687,7 @@ private void cleanupAdd() {
692687
public VPackBuilder close() throws VPackBuilderException {
693688
try {
694689
return close(true);
695-
} catch (final VPackKeyTypeException e) {
696-
throw new VPackBuilderException(e);
697-
} catch (final VPackNeedAttributeTranslatorException e) {
690+
} catch (final VPackKeyTypeException | VPackNeedAttributeTranslatorException e) {
698691
throw new VPackBuilderException(e);
699692
}
700693
}
@@ -739,10 +732,8 @@ protected VPackBuilder close(final boolean sort)
739732
offsetSize = 1;
740733
} else if ((size - tos) + 2 * in.size() <= 0xffff) {
741734
offsetSize = 2;
742-
} else if (((size - tos) / 2) + 4 * in.size() / 2 <= Integer.MAX_VALUE/* 0xffffffffu */) {
743-
offsetSize = 4;
744735
} else {
745-
offsetSize = 8;
736+
offsetSize = 4;
746737
}
747738
// Maybe we need to move down data
748739
if (offsetSize == 1) {
@@ -768,8 +759,7 @@ protected VPackBuilder close(final boolean sort)
768759
sortObjectIndex(tos, in);
769760
}
770761
// final int tableBase = size;
771-
for (int i = 0; i < in.size(); i++) {
772-
long x = in.get(i);
762+
for (long x : in) {
773763
ensureCapacity(size + offsetSize);
774764
for (int j = 0; j < offsetSize; j++) {
775765
addUnchecked(/* tableBase + offsetSize * i + j, */ (byte) (x & 0xff));
@@ -780,11 +770,8 @@ protected VPackBuilder close(final boolean sort)
780770
if (offsetSize > 1) {
781771
if (offsetSize == 2) {
782772
buffer[tos] = (byte) (buffer[tos] + 1);
783-
} else if (offsetSize == 4) {
773+
} else {
784774
buffer[tos] = (byte) (buffer[tos] + 2);
785-
} else { // offsetSize == 8
786-
buffer[tos] = (byte) (buffer[tos] + 3);
787-
appendLength(in.size());
788775
}
789776
}
790777
// Fix the byte length in the beginning
@@ -794,12 +781,10 @@ protected VPackBuilder close(final boolean sort)
794781
x >>= 8;
795782
}
796783
// set the number of items in the beginning
797-
if (offsetSize < 8) {
798-
x = in.size();
799-
for (int i = offsetSize + 1; i <= 2 * offsetSize; i++) {
800-
buffer[tos + i] = (byte) (x & 0xff);
801-
x >>= 8;
802-
}
784+
x = in.size();
785+
for (int i = offsetSize + 1; i <= 2 * offsetSize; i++) {
786+
buffer[tos + i] = (byte) (x & 0xff);
787+
x >>= 8;
803788
}
804789
stack.remove(stack.size() - 1);
805790
return this;
@@ -915,10 +900,8 @@ private VPackBuilder closeArray(final int tos, final List<Integer> in) {
915900
offsetSize = 1;
916901
} else if ((size - tos) + (needIndexTable ? 2 * n : 0) <= 0xffff) {
917902
offsetSize = 2;
918-
} else if (((size - tos) / 2) + ((needIndexTable ? 4 * n : 0) / 2) <= Integer.MAX_VALUE/* 0xffffffffu */) {
919-
offsetSize = 4;
920903
} else {
921-
offsetSize = 8;
904+
offsetSize = 4;
922905
}
923906
// Maybe we need to move down data
924907
if (offsetSize == 1) {
@@ -945,8 +928,7 @@ private VPackBuilder closeArray(final int tos, final List<Integer> in) {
945928
// Now build the table:
946929
if (needIndexTable) {
947930
// final int tableBase = size;
948-
for (int i = 0; i < n; i++) {
949-
long x = in.get(i);
931+
for (long x : in) {
950932
ensureCapacity(size + offsetSize);
951933
for (int j = 0; j < offsetSize; j++) {
952934
addUnchecked(/* tableBase + offsetSize * i + j, */ (byte) (x & 0xff));
@@ -960,13 +942,8 @@ private VPackBuilder closeArray(final int tos, final List<Integer> in) {
960942
if (offsetSize > 1) {
961943
if (offsetSize == 2) {
962944
buffer[tos] = (byte) (buffer[tos] + 1);
963-
} else if (offsetSize == 4) {
945+
} else {
964946
buffer[tos] = (byte) (buffer[tos] + 2);
965-
} else { // offsetSize == 8
966-
buffer[tos] = (byte) (buffer[tos] + 3);
967-
if (needNrSubs) {
968-
appendLength(n);
969-
}
970947
}
971948
}
972949
// Fix the byte length in the beginning
@@ -976,7 +953,7 @@ private VPackBuilder closeArray(final int tos, final List<Integer> in) {
976953
x >>= 8;
977954
}
978955
// set the number of items in the beginning
979-
if (offsetSize < 8 && needNrSubs) {
956+
if (needNrSubs) {
980957
x = n;
981958
for (int i = offsetSize + 1; i <= 2 * offsetSize; i++) {
982959
buffer[tos + i] = (byte) (x & 0xff);

src/main/java/com/arangodb/velocypack/VPackParser.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.arangodb.velocypack.internal.util.DateUtil;
3333
import com.fasterxml.jackson.core.JsonFactory;
3434
import com.fasterxml.jackson.core.JsonGenerator;
35-
import com.fasterxml.jackson.core.JsonParseException;
3635
import com.fasterxml.jackson.core.JsonParser;
3736
import com.fasterxml.jackson.core.JsonToken;
3837
import com.fasterxml.jackson.core.SerializableString;
@@ -66,10 +65,10 @@ public static class Builder implements VPackParserSetupContext<Builder> {
6665

6766
public Builder() {
6867
super();
69-
deserializers = new HashMap<ValueType, VPackJsonDeserializer>();
70-
deserializersByName = new HashMap<String, Map<ValueType, VPackJsonDeserializer>>();
71-
serializers = new HashMap<Class<?>, VPackJsonSerializer<?>>();
72-
serializersByName = new HashMap<String, Map<Class<?>, VPackJsonSerializer<?>>>();
68+
deserializers = new HashMap<>();
69+
deserializersByName = new HashMap<>();
70+
serializers = new HashMap<>();
71+
serializersByName = new HashMap<>();
7372
}
7473

7574
@Override
@@ -79,7 +78,7 @@ public VPackParser.Builder registerDeserializer(
7978
final VPackJsonDeserializer deserializer) {
8079
Map<ValueType, VPackJsonDeserializer> byName = deserializersByName.get(attribute);
8180
if (byName == null) {
82-
byName = new HashMap<ValueType, VPackJsonDeserializer>();
81+
byName = new HashMap<>();
8382
deserializersByName.put(attribute, byName);
8483
}
8584
byName.put(type, deserializer);
@@ -101,7 +100,7 @@ public <T> VPackParser.Builder registerSerializer(
101100
final VPackJsonSerializer<T> serializer) {
102101
Map<Class<?>, VPackJsonSerializer<?>> byName = serializersByName.get(attribute);
103102
if (byName == null) {
104-
byName = new HashMap<Class<?>, VPackJsonSerializer<?>>();
103+
byName = new HashMap<>();
105104
serializersByName.put(attribute, byName);
106105
}
107106
byName.put(type, serializer);
@@ -131,10 +130,9 @@ public Builder registerModules(final VPackParserModule... modules) {
131130
}
132131

133132
public synchronized VPackParser build() {
134-
return new VPackParser(new HashMap<Class<?>, VPackJsonSerializer<?>>(serializers),
135-
new HashMap<String, Map<Class<?>, VPackJsonSerializer<?>>>(serializersByName),
136-
new HashMap<ValueType, VPackJsonDeserializer>(deserializers),
137-
new HashMap<String, Map<ValueType, VPackJsonDeserializer>>(deserializersByName));
133+
return new VPackParser(new HashMap<>(serializers),
134+
new HashMap<>(serializersByName),
135+
new HashMap<>(deserializers), new HashMap<>(deserializersByName));
138136
}
139137
}
140138

@@ -175,7 +173,7 @@ public VPackParser registerDeserializer(
175173
final VPackJsonDeserializer deserializer) {
176174
Map<ValueType, VPackJsonDeserializer> byName = deserializersByName.get(attribute);
177175
if (byName == null) {
178-
byName = new HashMap<ValueType, VPackJsonDeserializer>();
176+
byName = new HashMap<>();
179177
deserializersByName.put(attribute, byName);
180178
}
181179
byName.put(type, deserializer);
@@ -208,7 +206,7 @@ public <T> VPackParser registerSerializer(
208206
final VPackJsonSerializer<T> serializer) {
209207
Map<Class<?>, VPackJsonSerializer<?>> byName = serializersByName.get(attribute);
210208
if (byName == null) {
211-
byName = new HashMap<Class<?>, VPackJsonSerializer<?>>();
209+
byName = new HashMap<>();
212210
serializersByName.put(attribute, byName);
213211
}
214212
byName.put(type, serializer);
@@ -346,8 +344,6 @@ public VPackSlice fromJson(final String json, final boolean includeNullValues) t
346344
final VPackBuilder builder = new VPackBuilder();
347345
try {
348346
parse(json, builder, includeNullValues);
349-
} catch (final JsonParseException e) {
350-
throw new VPackBuilderException(e);
351347
} catch (final IOException e) {
352348
throw new VPackBuilderException(e);
353349
}
@@ -365,8 +361,6 @@ public VPackSlice fromJson(final Iterable<String> jsons, final boolean includeNu
365361
for (final String json : jsons) {
366362
parse(json, builder, includeNullValues);
367363
}
368-
} catch (final JsonParseException e) {
369-
throw new VPackBuilderException(e);
370364
} catch (final IOException e) {
371365
throw new VPackBuilderException(e);
372366
}
@@ -375,7 +369,7 @@ public VPackSlice fromJson(final Iterable<String> jsons, final boolean includeNu
375369
}
376370

377371
private void parse(final String json, final VPackBuilder builder, final boolean includeNullValues)
378-
throws JsonParseException, IOException {
372+
throws IOException {
379373
final JsonParser parser = new JsonFactory().createParser(json);
380374
String fieldName = null;
381375
JsonToken token;
@@ -435,13 +429,13 @@ private void parseValue(final VPackBuilder builder, final String fieldName, fina
435429
if (serializer != null) {
436430
((VPackJsonSerializer<Object>) serializer).serialize(builder, fieldName, value);
437431
} else if (String.class.isAssignableFrom(value.getClass())) {
438-
builder.add(fieldName, String.class.cast(value));
432+
builder.add(fieldName, (String) value);
439433
} else if (Boolean.class.isAssignableFrom(value.getClass())) {
440-
builder.add(fieldName, Boolean.class.cast(value));
434+
builder.add(fieldName, (Boolean) value);
441435
} else if (Double.class.isAssignableFrom(value.getClass())) {
442-
builder.add(fieldName, Double.class.cast(value));
436+
builder.add(fieldName, (Double) value);
443437
} else if (Long.class.isAssignableFrom(value.getClass())) {
444-
builder.add(fieldName, Long.class.cast(value));
438+
builder.add(fieldName, (Long) value);
445439
}
446440
}
447441

0 commit comments

Comments
 (0)