Skip to content

Commit 653f792

Browse files
authored
Merge a (small) subset of #409 into 2.16 (no point merging into 2.15) (#413)
1 parent 7d5c543 commit 653f792

27 files changed

+60
-71
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroGenerator.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.OutputStream;
55
import java.math.BigDecimal;
66
import java.math.BigInteger;
7+
import java.nio.charset.StandardCharsets;
78

89
import org.apache.avro.io.BinaryEncoder;
910
import org.apache.avro.io.EncoderFactory;
@@ -68,7 +69,7 @@ public static int collectDefaults()
6869
return flags;
6970
}
7071

71-
private Feature(boolean defaultState) {
72+
Feature(boolean defaultState) {
7273
_defaultState = defaultState;
7374
_mask = (1 << ordinal());
7475
}
@@ -481,7 +482,7 @@ public void writeRawUTF8String(byte[] text, int offset, int len) throws IOExcept
481482

482483
@Override
483484
public final void writeUTF8String(byte[] text, int offset, int len) throws IOException {
484-
writeString(new String(text, offset, len, "UTF-8"));
485+
writeString(new String(text, offset, len, StandardCharsets.UTF_8));
485486
}
486487

487488
/*
@@ -568,12 +569,12 @@ public void writeNull() throws IOException {
568569

569570
@Override
570571
public void writeNumber(int i) throws IOException {
571-
_avroContext.writeValue(Integer.valueOf(i));
572+
_avroContext.writeValue(i);
572573
}
573574

574575
@Override
575576
public void writeNumber(long l) throws IOException {
576-
_avroContext.writeValue(Long.valueOf(l));
577+
_avroContext.writeValue(l);
577578
}
578579

579580
@Override
@@ -588,12 +589,12 @@ public void writeNumber(BigInteger v) throws IOException
588589

589590
@Override
590591
public void writeNumber(double d) throws IOException {
591-
_avroContext.writeValue(Double.valueOf(d));
592+
_avroContext.writeValue(d);
592593
}
593594

594595
@Override
595596
public void writeNumber(float f) throws IOException {
596-
_avroContext.writeValue(Float.valueOf(f));
597+
_avroContext.writeValue(f);
597598
}
598599

599600
@Override

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static int collectDefaults()
5555
return flags;
5656
}
5757

58-
private Feature(boolean defaultState) {
58+
Feature(boolean defaultState) {
5959
_defaultState = defaultState;
6060
_mask = (1 << ordinal());
6161
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class AvroSchema implements FormatSchema
3535
/**
3636
* Lazily instantiated value reader for this schema.
3737
*/
38-
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<AvroStructureReader>();
38+
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<>();
3939

4040
public AvroSchema(Schema asch)
4141
{

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/AvroFieldDefaulters.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static AvroFieldReader createDefaulter(String name,
4242
case START_OBJECT:
4343
{
4444
Iterator<Map.Entry<String,JsonNode>> it = defaultAsNode.fields();
45-
List<AvroFieldReader> readers = new ArrayList<AvroFieldReader>();
45+
List<AvroFieldReader> readers = new ArrayList<>();
4646
while (it.hasNext()) {
4747
Map.Entry<String,JsonNode> entry = it.next();
4848
String propName = entry.getKey();
@@ -52,7 +52,7 @@ public static AvroFieldReader createDefaulter(String name,
5252
}
5353
case START_ARRAY:
5454
{
55-
List<AvroFieldReader> readers = new ArrayList<AvroFieldReader>();
55+
List<AvroFieldReader> readers = new ArrayList<>();
5656
for (JsonNode value : defaultAsNode) {
5757
readers.add(createDefaulter("", value));
5858
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/AvroParserImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ protected final void convertNumberToInt() throws IOException
320320
protected final void convertNumberToLong() throws IOException
321321
{
322322
if ((_numTypesValid & NR_INT) != 0) {
323-
_numberLong = (long) _numberInt;
323+
_numberLong = _numberInt;
324324
} else if ((_numTypesValid & NR_BIGINT) != 0) {
325325
if (BI_MIN_LONG.compareTo(_numberBigInt) > 0
326326
|| BI_MAX_LONG.compareTo(_numberBigInt) < 0) {
@@ -370,6 +370,7 @@ protected final void convertNumberToBigInteger() throws IOException
370370
_numTypesValid |= NR_BIGINT;
371371
}
372372

373+
@Override
373374
protected final void convertNumberToFloat() throws IOException
374375
{
375376
// Note: this MUST start with more accurate representations, since we don't know which
@@ -398,13 +399,13 @@ protected final void convertNumberToDouble() throws IOException
398399
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
399400
_numberDouble = _numberBigDecimal.doubleValue();
400401
} else if ((_numTypesValid & NR_FLOAT) != 0) {
401-
_numberDouble = (double) _numberFloat;
402+
_numberDouble = _numberFloat;
402403
} else if ((_numTypesValid & NR_BIGINT) != 0) {
403404
_numberDouble = _numberBigInt.doubleValue();
404405
} else if ((_numTypesValid & NR_LONG) != 0) {
405406
_numberDouble = (double) _numberLong;
406407
} else if ((_numTypesValid & NR_INT) != 0) {
407-
_numberDouble = (double) _numberInt;
408+
_numberDouble = _numberInt;
408409
} else {
409410
_throwInternal();
410411
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/AvroReaderFactory.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public abstract class AvroReaderFactory
2727
* To resolve cyclic types, need to keep track of resolved named
2828
* types.
2929
*/
30-
protected final TreeMap<String, AvroStructureReader> _knownReaders
31-
= new TreeMap<String, AvroStructureReader>();
30+
protected final TreeMap<String, AvroStructureReader> _knownReaders = new TreeMap<>();
3231

3332
/*
3433
/**********************************************************************
@@ -306,10 +305,10 @@ protected AvroStructureReader createRecordReader(Schema writerSchema, Schema rea
306305

307306
// but first: find fields that only exist in reader-side and need defaults,
308307
// and remove those from
309-
Map<String,Schema.Field> readerFields = new HashMap<String,Schema.Field>();
310-
List<Schema.Field> defaultFields = new ArrayList<Schema.Field>();
308+
Map<String,Schema.Field> readerFields = new HashMap<>();
309+
List<Schema.Field> defaultFields = new ArrayList<>();
311310
{
312-
Set<String> writerNames = new HashSet<String>();
311+
Set<String> writerNames = new HashSet<>();
313312
for (Schema.Field f : writerFields) {
314313
writerNames.add(f.name());
315314
}

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public long decodeLong() throws IOException {
368368
_inputPtr = ptr;
369369
// should be ok to zigzag as int, then sign-extend
370370
i = (i >>> 1) ^ (-(i & 1));
371-
return (long) i;
371+
return i;
372372
}
373373

374374
private long _decodeLong2(int ptr, long lo) throws IOException
@@ -427,7 +427,7 @@ public long _decodeLongSlow() throws IOException {
427427
}
428428
}
429429
i = (i >>> 1) ^ (-(i & 1));
430-
return (long) i;
430+
return i;
431431
}
432432

433433
private long _decodeLongSlow2(long lo) throws IOException

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class AvroSchemaHelper
6565
*
6666
* @since 2.8.7
6767
*/
68-
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<Class<?>>(Arrays.asList(
68+
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<>(Arrays.asList(
6969
URI.class, URL.class, File.class,
7070
BigInteger.class, BigDecimal.class,
7171
String.class
@@ -121,15 +121,15 @@ protected static String getName(JavaType type) {
121121
protected static String getName(Class<?> cls) {
122122
String name = cls.getSimpleName();
123123
// Alas, some characters not accepted...
124-
while (name.indexOf("[]") >= 0) {
124+
while (name.contains("[]")) {
125125
name = name.replace("[]", "Array");
126126
}
127127
return name;
128128
}
129129

130130
protected static Schema unionWithNull(Schema otherSchema)
131131
{
132-
List<Schema> schemas = new ArrayList<Schema>();
132+
List<Schema> schemas = new ArrayList<>();
133133
schemas.add(Schema.create(Schema.Type.NULL));
134134

135135
// two cases: existing union
@@ -464,8 +464,7 @@ public FullNameKey(String namespace, String name) {
464464
}
465465

466466
public String nameWithSeparator(char sep) {
467-
final StringBuilder sb = new StringBuilder(1 + _namespace.length() + _name.length());
468-
return sb.append(_namespace).append(sep).append(_name).toString();
467+
return _namespace + sep + _name;
469468
}
470469

471470
@Override

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/DefinedSchemas.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public class DefinedSchemas
1515
{
16-
protected final Map<JavaType, Schema> _schemas = new LinkedHashMap<JavaType, Schema>();
16+
protected final Map<JavaType, Schema> _schemas = new LinkedHashMap<>();
1717

1818
protected SerializerProvider _provider;
1919

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/RecordVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RecordVisitor
3333

3434
protected Schema _avroSchema;
3535

36-
protected List<Schema.Field> _fields = new ArrayList<Schema.Field>();
36+
protected List<Schema.Field> _fields = new ArrayList<>();
3737

3838
public RecordVisitor(SerializerProvider p, JavaType type, VisitorFormatWrapperImpl visitorWrapper)
3939
{

0 commit comments

Comments
 (0)