Skip to content

Commit d9aa604

Browse files
committed
IntelliJ automated code cleanup
* Replace explicit type arguments with <> * Add missing <p> tags to Javadoc * Remove redundant warning suppressions * Replace anonymous class with lambda * Use try-with-resources * Collapse identical catch blocks * Use Comparator.comparing * Use Map.getOrDefault * Replace lambda invocation with body * Other miscellaneous
1 parent f0b1437 commit d9aa604

File tree

615 files changed

+3343
-4547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

615 files changed

+3343
-4547
lines changed

bson-record-codec/src/main/org/bson/codecs/record/RecordCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static int getIndexOfTypeParameter(final String typeParameterName, final
140140
return i;
141141
}
142142
}
143-
throw new CodecConfigurationException(String.format("Could not find type parameter on record %s with name %s",
143+
throw new CodecConfigurationException(format("Could not find type parameter on record %s with name %s",
144144
recordClass.getName(), typeParameterName));
145145
}
146146

bson/src/main/org/bson/AbstractBsonWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public abstract class AbstractBsonWriter implements BsonWriter, Closeable {
3737
private final BsonWriterSettings settings;
38-
private final Stack<FieldNameValidator> fieldNameValidatorStack = new Stack<FieldNameValidator>();
38+
private final Stack<FieldNameValidator> fieldNameValidatorStack = new Stack<>();
3939
private State state;
4040
private Context context;
4141
private int serializationDepth;

bson/src/main/org/bson/BSONCallback.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* A callback interface for describing the structure of a BSON document. Implementations of this define how to turn BSON read from MongoDB
2424
* into Java objects.
25-
*
25+
* <p>
2626
* See the <a href="http://bsonspec.org/spec.html">BSON Spec</a>.
2727
*/
2828
public interface BSONCallback {

bson/src/main/org/bson/BasicBSONCallback.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class BasicBSONCallback implements BSONCallback {
4747
* Creates a new instance.
4848
*/
4949
public BasicBSONCallback() {
50-
stack = new LinkedList<BSONObject>();
51-
nameStack = new LinkedList<String>();
50+
stack = new LinkedList<>();
51+
nameStack = new LinkedList<>();
5252
reset();
5353
}
5454

bson/src/main/org/bson/BasicBSONDecoder.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ public BSONObject readObject(final InputStream in) throws IOException {
8585

8686
@Override
8787
public int decode(final byte[] bytes, final BSONCallback callback) {
88-
BsonBinaryReader reader = new BsonBinaryReader(new ByteBufferBsonInput(new ByteBufNIO(ByteBuffer.wrap(bytes))));
89-
try {
88+
try (BsonBinaryReader reader = new BsonBinaryReader(new ByteBufferBsonInput(new ByteBufNIO(ByteBuffer.wrap(bytes))))) {
9089
BsonWriter writer = new BSONCallbackAdapter(new BsonWriterSettings(), callback);
9190
writer.pipe(reader);
9291
return reader.getBsonInput().getPosition(); //TODO check this.
93-
} finally {
94-
reader.close();
9592
}
9693
}
9794

bson/src/main/org/bson/BasicBSONObject.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public BasicBSONObject(final Map map) {
7878
* @return the DBObject
7979
*/
8080
public Map toMap() {
81-
return new LinkedHashMap<String, Object>(this);
81+
return new LinkedHashMap<>(this);
8282
}
8383

8484
/**
@@ -98,7 +98,7 @@ public Object removeField(final String key) {
9898
* @return if the field exists
9999
*/
100100
public boolean containsField(final String field) {
101-
return super.containsKey(field);
101+
return containsKey(field);
102102
}
103103

104104
/**
@@ -382,8 +382,8 @@ private static Object canonicalize(final Object from) {
382382
}
383383

384384
private static Map<String, Object> canonicalizeMap(final Map<String, Object> from) {
385-
Map<String, Object> canonicalized = new LinkedHashMap<String, Object>(from.size());
386-
TreeSet<String> keysInOrder = new TreeSet<String>(from.keySet());
385+
Map<String, Object> canonicalized = new LinkedHashMap<>(from.size());
386+
TreeSet<String> keysInOrder = new TreeSet<>(from.keySet());
387387
for (String key : keysInOrder) {
388388
Object val = from.get(key);
389389
canonicalized.put(key, canonicalize(val));
@@ -393,7 +393,7 @@ private static Map<String, Object> canonicalizeMap(final Map<String, Object> fro
393393

394394
private static BasicBSONObject canonicalizeBSONObject(final BSONObject from) {
395395
BasicBSONObject canonicalized = new BasicBSONObject();
396-
TreeSet<String> keysInOrder = new TreeSet<String>(from.keySet());
396+
TreeSet<String> keysInOrder = new TreeSet<>(from.keySet());
397397
for (String key : keysInOrder) {
398398
Object val = from.get(key);
399399
canonicalized.put(key, canonicalize(val));
@@ -402,7 +402,7 @@ private static BasicBSONObject canonicalizeBSONObject(final BSONObject from) {
402402
}
403403

404404
private static List canonicalizeList(final List<Object> list) {
405-
List<Object> canonicalized = new ArrayList<Object>(list.size());
405+
List<Object> canonicalized = new ArrayList<>(list.size());
406406
for (Object cur : list) {
407407
canonicalized.add(canonicalize(cur));
408408
}

bson/src/main/org/bson/Bits.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static int readInt(final byte[] buffer) {
9999
*/
100100
static int readInt(final byte[] buffer, final int offset) {
101101
int x = 0;
102-
x |= (0xFF & buffer[offset + 0]) << 0;
102+
x |= (0xFF & buffer[offset]) << 0;
103103
x |= (0xFF & buffer[offset + 1]) << 8;
104104
x |= (0xFF & buffer[offset + 2]) << 16;
105105
x |= (0xFF & buffer[offset + 3]) << 24;
@@ -150,7 +150,7 @@ static long readLong(final byte[] buffer) {
150150
*/
151151
static long readLong(final byte[] buffer, final int offset) {
152152
long x = 0;
153-
x |= (0xFFL & buffer[offset + 0]) << 0;
153+
x |= (0xFFL & buffer[offset]) << 0;
154154
x |= (0xFFL & buffer[offset + 1]) << 8;
155155
x |= (0xFFL & buffer[offset + 2]) << 16;
156156
x |= (0xFFL & buffer[offset + 3]) << 24;

bson/src/main/org/bson/BsonArray.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public BsonArray(final List<? extends BsonValue> values) {
4949
* Construct an empty BsonArray
5050
*/
5151
public BsonArray() {
52-
this(new ArrayList<BsonValue>(), false);
52+
this(new ArrayList<>(), false);
5353
}
5454

5555
/**
@@ -61,13 +61,13 @@ public BsonArray() {
6161
* @since 4.3
6262
*/
6363
public BsonArray(final int initialCapacity) {
64-
this(new ArrayList<BsonValue>(initialCapacity), false);
64+
this(new ArrayList<>(initialCapacity), false);
6565
}
6666

6767
@SuppressWarnings("unchecked")
6868
BsonArray(final List<? extends BsonValue> values, final boolean copy) {
6969
if (copy) {
70-
this.values = new ArrayList<BsonValue>(values);
70+
this.values = new ArrayList<>(values);
7171
} else {
7272
this.values = (List<BsonValue>) values;
7373
}

bson/src/main/org/bson/BsonBinary.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public UUID asUuid() {
137137
public UUID asUuid(final UuidRepresentation uuidRepresentation) {
138138
Assertions.notNull("uuidRepresentation", uuidRepresentation);
139139

140-
final byte uuidType = uuidRepresentation == UuidRepresentation.STANDARD
140+
byte uuidType = uuidRepresentation == UuidRepresentation.STANDARD
141141
? BsonBinarySubType.UUID_STANDARD.getValue()
142142
: BsonBinarySubType.UUID_LEGACY.getValue();
143143

@@ -164,7 +164,7 @@ public byte getType() {
164164

165165
/**
166166
* Gets the data of this Binary.
167-
*
167+
* <p>
168168
* This method returns the internal copy of the byte array, so only modify the contents of the returned array if the intention is to
169169
* change the state of this instance.
170170
*
@@ -197,7 +197,7 @@ public boolean equals(final Object o) {
197197

198198
@Override
199199
public int hashCode() {
200-
int result = (int) type;
200+
int result = type;
201201
result = 31 * result + Arrays.hashCode(data);
202202
return result;
203203
}

bson/src/main/org/bson/BsonBinaryReader.java

-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ protected class Mark extends AbstractBsonReader.Mark {
406406
* Construct an instance.
407407
*/
408408
protected Mark() {
409-
super();
410409
startPosition = BsonBinaryReader.this.getContext().startPosition;
411410
size = BsonBinaryReader.this.getContext().size;
412411
bsonInputMark = BsonBinaryReader.this.bsonInput.getMark(Integer.MAX_VALUE);

bson/src/main/org/bson/BsonBinaryWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class BsonBinaryWriter extends AbstractBsonWriter {
3636
private final BsonBinaryWriterSettings binaryWriterSettings;
3737

3838
private final BsonOutput bsonOutput;
39-
private final Stack<Integer> maxDocumentSizeStack = new Stack<Integer>();
39+
private final Stack<Integer> maxDocumentSizeStack = new Stack<>();
4040
private Mark mark;
4141

4242
/**

bson/src/main/org/bson/BsonDocument.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ public BsonDocument(final String key, final BsonValue value) {
9797
* @since 4.3
9898
*/
9999
public BsonDocument(final int initialCapacity) {
100-
map = new LinkedHashMap<String, BsonValue>(initialCapacity);
100+
map = new LinkedHashMap<>(initialCapacity);
101101
}
102102

103103
/**
104104
* Construct an empty document.
105105
*/
106106
public BsonDocument() {
107-
map = new LinkedHashMap<String, BsonValue>();
107+
map = new LinkedHashMap<>();
108108
}
109109

110110
@Override
@@ -834,7 +834,6 @@ public int hashCode() {
834834
* @see #toJson(JsonWriterSettings)
835835
* @see JsonWriterSettings
836836
*/
837-
@SuppressWarnings("deprecation")
838837
public String toJson() {
839838
return toJson(JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build());
840839
}

bson/src/main/org/bson/BsonDocumentReader.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class BsonDocumentReader extends AbstractBsonReader {
4242
* @param document the document to read from
4343
*/
4444
public BsonDocumentReader(final BsonDocument document) {
45-
super();
4645
setContext(new Context(null, BsonContextType.TOP_LEVEL, document));
4746
currentValue = document;
4847
}
@@ -255,7 +254,6 @@ protected class Mark extends AbstractBsonReader.Mark {
255254
* Construct an instance.
256255
*/
257256
protected Mark() {
258-
super();
259257
currentValue = BsonDocumentReader.this.currentValue;
260258
context = BsonDocumentReader.this.getContext();
261259
context.mark();
@@ -272,8 +270,8 @@ public void reset() {
272270

273271
private static class BsonDocumentMarkableIterator<T> implements Iterator<T> {
274272

275-
private Iterator<T> baseIterator;
276-
private List<T> markIterator = new ArrayList<T>();
273+
private final Iterator<T> baseIterator;
274+
private final List<T> markIterator = new ArrayList<>();
277275
private int curIndex; // index of the cursor
278276
private boolean marking;
279277

@@ -350,7 +348,7 @@ protected class Context extends AbstractBsonReader.Context {
350348
*/
351349
protected Context(final Context parentContext, final BsonContextType contextType, final BsonArray array) {
352350
super(parentContext, contextType);
353-
arrayIterator = new BsonDocumentMarkableIterator<BsonValue>(array.iterator());
351+
arrayIterator = new BsonDocumentMarkableIterator<>(array.iterator());
354352
}
355353

356354
/**
@@ -362,7 +360,7 @@ protected Context(final Context parentContext, final BsonContextType contextType
362360
*/
363361
protected Context(final Context parentContext, final BsonContextType contextType, final BsonDocument document) {
364362
super(parentContext, contextType);
365-
documentIterator = new BsonDocumentMarkableIterator<Map.Entry<String, BsonValue>>(document.entrySet().iterator());
363+
documentIterator = new BsonDocumentMarkableIterator<>(document.entrySet().iterator());
366364
}
367365

368366
/**

bson/src/main/org/bson/Document.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class Document implements Map<String, Object>, Serializable, Bson {
7878
* Creates an empty Document instance.
7979
*/
8080
public Document() {
81-
documentAsMap = new LinkedHashMap<String, Object>();
81+
documentAsMap = new LinkedHashMap<>();
8282
}
8383

8484
/**
@@ -88,7 +88,7 @@ public Document() {
8888
* @param value value
8989
*/
9090
public Document(final String key, final Object value) {
91-
documentAsMap = new LinkedHashMap<String, Object>();
91+
documentAsMap = new LinkedHashMap<>();
9292
documentAsMap.put(key, value);
9393
}
9494

@@ -98,7 +98,7 @@ public Document(final String key, final Object value) {
9898
* @param map initial map
9999
*/
100100
public Document(final Map<String, ?> map) {
101-
documentAsMap = new LinkedHashMap<String, Object>(map);
101+
documentAsMap = new LinkedHashMap<>(map);
102102
}
103103

104104

@@ -131,7 +131,7 @@ public static Document parse(final String json, final Decoder<Document> decoder)
131131

132132
@Override
133133
public <C> BsonDocument toBsonDocument(final Class<C> documentClass, final CodecRegistry codecRegistry) {
134-
return new BsonDocumentWrapper<Document>(this, codecRegistry.get(Document.class));
134+
return new BsonDocumentWrapper<>(this, codecRegistry.get(Document.class));
135135
}
136136

137137
/**
@@ -186,7 +186,7 @@ public <T> T get(final Object key, final T defaultValue) {
186186
* Gets the value in an embedded document, casting it to the given {@code Class<T>}. The list of keys represents a path to the
187187
* embedded value, drilling down into an embedded document for each key. This is useful to avoid having casts in
188188
* client code, though the effect is the same.
189-
*
189+
* <p>
190190
* The generic type of the keys list is {@code ?} to be consistent with the corresponding {@code get} methods, but in practice
191191
* the actual type of the argument should be {@code List<String>}. So to get the embedded value of a key list that is of type String,
192192
* you would write {@code String name = doc.getEmbedded(List.of("employee", "manager", "name"), String.class)} instead of
@@ -210,7 +210,7 @@ public <T> T getEmbedded(final List<?> keys, final Class<T> clazz) {
210210
* Gets the value in an embedded document, casting it to the given {@code Class<T>} or returning the default value if null.
211211
* The list of keys represents a path to the embedded value, drilling down into an embedded document for each key.
212212
* This is useful to avoid having casts in client code, though the effect is the same.
213-
*
213+
* <p>
214214
* The generic type of the keys list is {@code ?} to be consistent with the corresponding {@code get} methods, but in practice
215215
* the actual type of the argument should be {@code List<String>}. So to get the embedded value of a key list that is of type String,
216216
* you would write {@code String name = doc.getEmbedded(List.of("employee", "manager", "name"), "John Smith")} instead of
@@ -414,7 +414,6 @@ private <T> List<T> constructValuesList(final Object key, final Class<T> clazz,
414414
* @see #toJson(JsonWriterSettings)
415415
* @see JsonWriterSettings
416416
*/
417-
@SuppressWarnings("deprecation")
418417
public String toJson() {
419418
return toJson(JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build());
420419
}
@@ -441,7 +440,6 @@ public String toJson(final JsonWriterSettings writerSettings) {
441440
* @return a JSON representation of this document
442441
* @throws org.bson.codecs.configuration.CodecConfigurationException if the registry does not contain a codec for the document values.
443442
*/
444-
@SuppressWarnings("deprecation")
445443
public String toJson(final Encoder<Document> encoder) {
446444
return toJson(JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build(), encoder);
447445
}

bson/src/main/org/bson/LazyBSONList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Iterator iterator() {
6868

6969
@Override
7070
public boolean containsAll(final Collection collection) {
71-
Set<Object> values = new HashSet<Object>();
71+
Set<Object> values = new HashSet<>();
7272
for (final Object o : this) {
7373
values.add(o);
7474
}

0 commit comments

Comments
 (0)