Skip to content

Commit

Permalink
Merge a (small) subset of #409 into 2.16 (no point merging into 2.15) (
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 3, 2023
1 parent 7d5c543 commit 653f792
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.EncoderFactory;
Expand Down Expand Up @@ -68,7 +69,7 @@ public static int collectDefaults()
return flags;
}

private Feature(boolean defaultState) {
Feature(boolean defaultState) {
_defaultState = defaultState;
_mask = (1 << ordinal());
}
Expand Down Expand Up @@ -481,7 +482,7 @@ public void writeRawUTF8String(byte[] text, int offset, int len) throws IOExcept

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

/*
Expand Down Expand Up @@ -568,12 +569,12 @@ public void writeNull() throws IOException {

@Override
public void writeNumber(int i) throws IOException {
_avroContext.writeValue(Integer.valueOf(i));
_avroContext.writeValue(i);
}

@Override
public void writeNumber(long l) throws IOException {
_avroContext.writeValue(Long.valueOf(l));
_avroContext.writeValue(l);
}

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

@Override
public void writeNumber(double d) throws IOException {
_avroContext.writeValue(Double.valueOf(d));
_avroContext.writeValue(d);
}

@Override
public void writeNumber(float f) throws IOException {
_avroContext.writeValue(Float.valueOf(f));
_avroContext.writeValue(f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static int collectDefaults()
return flags;
}

private Feature(boolean defaultState) {
Feature(boolean defaultState) {
_defaultState = defaultState;
_mask = (1 << ordinal());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AvroSchema implements FormatSchema
/**
* Lazily instantiated value reader for this schema.
*/
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<AvroStructureReader>();
protected final AtomicReference<AvroStructureReader> _reader = new AtomicReference<>();

public AvroSchema(Schema asch)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static AvroFieldReader createDefaulter(String name,
case START_OBJECT:
{
Iterator<Map.Entry<String,JsonNode>> it = defaultAsNode.fields();
List<AvroFieldReader> readers = new ArrayList<AvroFieldReader>();
List<AvroFieldReader> readers = new ArrayList<>();
while (it.hasNext()) {
Map.Entry<String,JsonNode> entry = it.next();
String propName = entry.getKey();
Expand All @@ -52,7 +52,7 @@ public static AvroFieldReader createDefaulter(String name,
}
case START_ARRAY:
{
List<AvroFieldReader> readers = new ArrayList<AvroFieldReader>();
List<AvroFieldReader> readers = new ArrayList<>();
for (JsonNode value : defaultAsNode) {
readers.add(createDefaulter("", value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected final void convertNumberToInt() throws IOException
protected final void convertNumberToLong() throws IOException
{
if ((_numTypesValid & NR_INT) != 0) {
_numberLong = (long) _numberInt;
_numberLong = _numberInt;
} else if ((_numTypesValid & NR_BIGINT) != 0) {
if (BI_MIN_LONG.compareTo(_numberBigInt) > 0
|| BI_MAX_LONG.compareTo(_numberBigInt) < 0) {
Expand Down Expand Up @@ -370,6 +370,7 @@ protected final void convertNumberToBigInteger() throws IOException
_numTypesValid |= NR_BIGINT;
}

@Override
protected final void convertNumberToFloat() throws IOException
{
// Note: this MUST start with more accurate representations, since we don't know which
Expand Down Expand Up @@ -398,13 +399,13 @@ protected final void convertNumberToDouble() throws IOException
if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
_numberDouble = _numberBigDecimal.doubleValue();
} else if ((_numTypesValid & NR_FLOAT) != 0) {
_numberDouble = (double) _numberFloat;
_numberDouble = _numberFloat;
} else if ((_numTypesValid & NR_BIGINT) != 0) {
_numberDouble = _numberBigInt.doubleValue();
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberDouble = (double) _numberLong;
} else if ((_numTypesValid & NR_INT) != 0) {
_numberDouble = (double) _numberInt;
_numberDouble = _numberInt;
} else {
_throwInternal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public abstract class AvroReaderFactory
* To resolve cyclic types, need to keep track of resolved named
* types.
*/
protected final TreeMap<String, AvroStructureReader> _knownReaders
= new TreeMap<String, AvroStructureReader>();
protected final TreeMap<String, AvroStructureReader> _knownReaders = new TreeMap<>();

/*
/**********************************************************************
Expand Down Expand Up @@ -306,10 +305,10 @@ protected AvroStructureReader createRecordReader(Schema writerSchema, Schema rea

// but first: find fields that only exist in reader-side and need defaults,
// and remove those from
Map<String,Schema.Field> readerFields = new HashMap<String,Schema.Field>();
List<Schema.Field> defaultFields = new ArrayList<Schema.Field>();
Map<String,Schema.Field> readerFields = new HashMap<>();
List<Schema.Field> defaultFields = new ArrayList<>();
{
Set<String> writerNames = new HashSet<String>();
Set<String> writerNames = new HashSet<>();
for (Schema.Field f : writerFields) {
writerNames.add(f.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public long decodeLong() throws IOException {
_inputPtr = ptr;
// should be ok to zigzag as int, then sign-extend
i = (i >>> 1) ^ (-(i & 1));
return (long) i;
return i;
}

private long _decodeLong2(int ptr, long lo) throws IOException
Expand Down Expand Up @@ -427,7 +427,7 @@ public long _decodeLongSlow() throws IOException {
}
}
i = (i >>> 1) ^ (-(i & 1));
return (long) i;
return i;
}

private long _decodeLongSlow2(long lo) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public abstract class AvroSchemaHelper
*
* @since 2.8.7
*/
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<Class<?>>(Arrays.asList(
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<>(Arrays.asList(
URI.class, URL.class, File.class,
BigInteger.class, BigDecimal.class,
String.class
Expand Down Expand Up @@ -121,15 +121,15 @@ protected static String getName(JavaType type) {
protected static String getName(Class<?> cls) {
String name = cls.getSimpleName();
// Alas, some characters not accepted...
while (name.indexOf("[]") >= 0) {
while (name.contains("[]")) {
name = name.replace("[]", "Array");
}
return name;
}

protected static Schema unionWithNull(Schema otherSchema)
{
List<Schema> schemas = new ArrayList<Schema>();
List<Schema> schemas = new ArrayList<>();
schemas.add(Schema.create(Schema.Type.NULL));

// two cases: existing union
Expand Down Expand Up @@ -464,8 +464,7 @@ public FullNameKey(String namespace, String name) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class DefinedSchemas
{
protected final Map<JavaType, Schema> _schemas = new LinkedHashMap<JavaType, Schema>();
protected final Map<JavaType, Schema> _schemas = new LinkedHashMap<>();

protected SerializerProvider _provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RecordVisitor

protected Schema _avroSchema;

protected List<Schema.Field> _fields = new ArrayList<Schema.Field>();
protected List<Schema.Field> _fields = new ArrayList<>();

public RecordVisitor(SerializerProvider p, JavaType type, VisitorFormatWrapperImpl visitorWrapper)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.apache.avro.Schema;

public interface SchemaBuilder {
public Schema builtAvroSchema();
Schema builtAvroSchema();
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ public JsonArrayFormatVisitor expectArrayFormat(final JavaType convertedType) {
if (convertedType.isArrayType()) {
JavaType vt = convertedType.getContentType();
if (vt.hasRawClass(Byte.TYPE)) {
_builder = new SchemaBuilder() {
@Override
public Schema builtAvroSchema() {
return AvroSchemaHelper.typedSchema(Schema.Type.BYTES, convertedType);
}
};
_builder = () -> AvroSchemaHelper.typedSchema(Schema.Type.BYTES, convertedType);
return null;
}
}
Expand Down Expand Up @@ -251,9 +246,6 @@ protected <T> T _throwUnsupported(String msg) {
}

private boolean _isDateTimeType(JavaType type) {
if (Temporal.class.isAssignableFrom(type.getRawClass())) {
return true;
}
return false;
return Temporal.class.isAssignableFrom(type.getRawClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected GenericArray<Object> _createArray(Schema schema)
}
schema = schema.getTypes().get(arraySchemaIndex);
}
return new GenericData.Array<Object>(8, schema);
return new GenericData.Array<>(8, schema);
}

// Removed from 2.10, should not be needed any more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MapWriteContext(AvroWriteContext parent, AvroGenerator generator,
Schema schema, Object currValue)
{
super(parent, generator, schema, currValue);
_data = new HashMap<String,Object>();
_data = new HashMap<>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void _reportError() {
private final NonBSGenericDatumWriter<Object> _writer() {
NonBSGenericDatumWriter<Object> w = _writer;
if (w == null){
w = new NonBSGenericDatumWriter<Object>(_schema);
w = new NonBSGenericDatumWriter<>(_schema);
_writer = w;
}
return w;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.core.*;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void testStringArraySequence() throws Exception
AvroSchema schema = getStringArraySchema();
List<String> input1 = Arrays.asList("foo", "bar",
"...........................................................!");
List<String> input2 = Arrays.asList("foobar");
List<String> input2 = Collections.singletonList("foobar");
String[] input3 = new String[] { "a",
"Something very much longer than the first entry: and with \u00DCnicod\u00E9 -- at least "
+"2 lines full of stuff... 12235u4039680346 -346-0436 34-6 -43609 4363469 436-09",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public MediaItem(MediaContent c) {

public void addPhoto(Image p) {
if (_images == null) {
_images = new ArrayList<Image>();
_images = new ArrayList<>();
}
_images.add(p);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ protected MediaContent(MediaContent src) {

public void addPerson(String p) {
if (_persons == null) {
_persons = new ArrayList<String>();
_persons = new ArrayList<>();
}
_persons.add(p);
}
Expand Down Expand Up @@ -331,7 +331,7 @@ public static void verifyException(Throwable e, String... matches)
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
if (lmsg.contains(lmatch)) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fasterxml.jackson.dataformat.avro;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonParser;
Expand All @@ -16,8 +16,8 @@ public class BinaryDataTest extends AvroTestBase
@JsonPropertyOrder({ "filename", "data", "size" })
static class FilePojo {
protected FilePojo() { }
public FilePojo(String text) throws IOException {
data = text.getBytes("UTF-8");
public FilePojo(String text) {
data = text.getBytes(StandardCharsets.UTF_8);
size = data.length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ private void _testFileFormatOutput(boolean useApacheImpl) throws Exception
assertNotNull(bytes);
assertEquals(301, bytes.length);

DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema.getAvroSchema());
DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(schema.getAvroSchema());
@SuppressWarnings("resource")
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(new SeekableByteArrayInput(bytes),
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new SeekableByteArrayInput(bytes),
datumReader);
GenericRecord output = dataFileReader.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public EventLog(Integer version, Byte eventCount, List<Event> events, List<Probl

public void testIssue19() throws Exception
{
List<Event> sampleEvents = new ArrayList<Event>();
List<Event> sampleEvents = new ArrayList<>();
sampleEvents.add(new Event(10, new EventID("sample1", 1, 2)));
sampleEvents.add(new Event(20, new EventID("sample2", 10, 20)));
sampleEvents.add(new Event(30, new EventID("sample3", 100, 200)));

List<Problem> sampleProblems = new ArrayList<Problem>();
List<Problem> sampleProblems = new ArrayList<>();
sampleProblems.add(new Problem(800, 801));
sampleProblems.add(new Problem(900, 901));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MapTest extends AvroTestBase
+"]}"
;
static class Container {
public Map<String,String> stuff = new LinkedHashMap<String,String>();
public Map<String,String> stuff = new LinkedHashMap<>();

public void setStuff(Map<String,String> arg) {
stuff = arg;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testRootMapSequence() throws Exception
}

private Map<String,String> _map(String... stuff) {
Map<String,String> map = new LinkedHashMap<String,String>();
Map<String,String> map = new LinkedHashMap<>();
for (int i = 0, end = stuff.length; i < end; i += 2) {
map.put(stuff[i], stuff[i+1]);
}
Expand Down
Loading

0 comments on commit 653f792

Please sign in to comment.