Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<PropertyName> findPropertyAliases(MapperConfig<?> config, Annotated
if (ann == null) {
return null;
}
return Collections.singletonList(PropertyName.construct(ann.alias()));
return List.of(PropertyName.construct(ann.alias()));
}

protected PropertyName _findName(Annotated a)
Expand All @@ -100,8 +100,7 @@ public Boolean hasRequiredMarker(MapperConfig<?> config, AnnotatedMember m) {

@Override
public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated a) {
if (a instanceof AnnotatedConstructor) {
AnnotatedConstructor constructor = (AnnotatedConstructor) a;
if (a instanceof AnnotatedConstructor constructor) {
// 09-Mar-2017, tatu: Ideally would allow mix-ins etc, but for now let's take
// a short-cut here:
Class<?> declClass = constructor.getDeclaringClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public abstract class AvroSchemaHelper
/**
* Default stringable classes
*/
protected static final Set<Class<?>> STRINGABLE_CLASSES = new HashSet<>(Arrays.asList(
protected static final Set<Class<?>> STRINGABLE_CLASSES = Set.of(
URI.class, URL.class, File.class,
BigInteger.class, BigDecimal.class,
String.class
));
);

/**
* Checks if a given type is "Stringable", that is one of the default
Expand Down Expand Up @@ -206,7 +206,7 @@ public static Schema typedSchema(Schema.Type nativeType, JavaType javaType) {

public static Schema anyNumberSchema()
{
return Schema.createUnion(Arrays.asList(
return Schema.createUnion(List.of(
Schema.create(Schema.Type.INT),
Schema.create(Schema.Type.LONG),
Schema.create(Schema.Type.DOUBLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ protected Schema.Field schemaFieldForWriter(BeanProperty prop, boolean optional)
ValueSerializer<?> ser = null;

// 23-Nov-2012, tatu: Ideally shouldn't need to do this but...
if (prop instanceof BeanPropertyWriter) {
BeanPropertyWriter bpw = (BeanPropertyWriter) prop;
if (prop instanceof BeanPropertyWriter bpw) {
ser = bpw.getSerializer();
// 2-Mar-2017, bryan: AvroEncode annotation expects to have the schema used directly
optional = optional && !(ser instanceof CustomEncodingSerializer); // Don't modify schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void serialize(T t, JsonGenerator jsonGenerator, SerializationContext ctx
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type)
{
if (visitor instanceof VisitorFormatWrapperImpl) {
((VisitorFormatWrapperImpl) visitor).expectAvroFormat(new AvroSchema(encoding.getSchema()));
if (visitor instanceof VisitorFormatWrapperImpl wrapper) {
wrapper.expectAvroFormat(new AvroSchema(encoding.getSchema()));
} else {
super.acceptJsonFormatVisitor(visitor, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ protected String _numberToName(int ch, boolean neg, TagList tags) throws Jackson
}

Object str = stringRefs.stringRefs.get(i);
if (str instanceof String) {
return (String) str;
if (str instanceof String s) {
return s;
}
return new String((byte[]) str, UTF8);
}
Expand All @@ -833,8 +833,8 @@ protected JsonToken _handleTaggedInt(TagList tags) throws JacksonException {
}

Object str = stringRefs.stringRefs.get(_numberInt);
if (str instanceof String) {
_sharedString = (String) str;
if (str instanceof String s) {
_sharedString = s;
return _updateToken(JsonToken.VALUE_STRING);
}
_binaryValue = (byte[]) str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public String toString() {
public boolean equals(Object o)
{
if (o == this) return true;
if (o instanceof CBORSimpleValue) {
CBORSimpleValue other = (CBORSimpleValue) o;
if (o instanceof CBORSimpleValue other) {
return _value == other._value;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public EnumAsIonSymbolSerializer() {

@Override
public void serialize(Enum<?> value, JsonGenerator g, SerializationContext provider) {
if (g instanceof IonGenerator) {
if (g instanceof IonGenerator ionGenerator) {
String valueString = provider.isEnabled(EnumFeature.WRITE_ENUMS_USING_TO_STRING)
? value.toString()
: value.name();

((IonGenerator) g).writeSymbol(valueString);
ionGenerator.writeSymbol(valueString);
} else {
throw new StreamWriteException(g, "Can only use EnumAsIonSymbolSerializer with IonGenerator");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ protected void _closeInput() throws IOException
_destination.close();
} else {
if (isEnabled(StreamWriteFeature.FLUSH_PASSED_TO_STREAM)) {
if (_destination instanceof Flushable) {
((Flushable) _destination).flush();
if (_destination instanceof Flushable flushable) {
flushable.flush();
}
}
}
Expand Down Expand Up @@ -692,8 +692,7 @@ public JsonGenerator writeStartSexp() throws JacksonException {

@Override
public JsonGenerator writeTypeId(Object rawId) throws JacksonException {
if (rawId instanceof String[]) {
String[] ids = (String[]) rawId;
if (rawId instanceof String[] ids) {
for (String id : ids) {
annotateNextValue(id);
}
Expand Down
4 changes: 2 additions & 2 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ protected void _closeInput() throws IOException {
// should only close if manage the resource
if (_ioContext.isResourceManaged()) {
Object src = _ioContext.contentReference().getRawContent();
if (src instanceof Closeable) {
if (src instanceof Closeable closeable) {
try {
((Closeable) src).close();
closeable.close();
} catch (IOException e) {
throw _wrapIOFailure(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanPr
public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws JacksonException
{
Object embeddedObject = jp.getEmbeddedObject();
if (embeddedObject instanceof IonValue) {
return (IonValue) embeddedObject;
if (embeddedObject instanceof IonValue ionValue) {
return ionValue;
}
// We rely on the IonParser's IonSystem to wrap supported types into an IonValue
if (!(jp instanceof IonParser)) {
Expand All @@ -58,8 +58,8 @@ public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws J
}

IonSystem ionSystem = ((IonParser) jp).getIonSystem();
if (embeddedObject instanceof Timestamp) {
return ionSystem.newTimestamp((Timestamp) embeddedObject);
if (embeddedObject instanceof Timestamp timestamp) {
return ionSystem.newTimestamp(timestamp);
}
if (embeddedObject instanceof byte[]) {
// The parser provides no distinction between BLOB and CLOB, deserializing to a BLOB is the safest choice.
Expand All @@ -74,8 +74,7 @@ public Object getNullValue(DeserializationContext ctxt) throws JacksonException
final JsonParser parser = ctxt.getParser();
if (parser != null && parser.currentToken() != JsonToken.END_OBJECT) {
final Object embeddedObj = parser.getEmbeddedObject();
if (embeddedObj instanceof IonValue) {
IonValue iv = (IonValue) embeddedObj;
if (embeddedObj instanceof IonValue iv) {
if (iv.isNullValue()) {
if (IonType.isContainer(iv.getType())) {
return iv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ protected TimestampSerializer() {

@Override
public void serialize(Timestamp value, JsonGenerator g, SerializationContext ctxt) {
if (g instanceof IonGenerator) {
((IonGenerator) g).writeValue(value);
if (g instanceof IonGenerator ionGenerator) {
ionGenerator.writeValue(value);
} else {
// Otherwise probably `TokenBuffer`, so
g.writeEmbeddedObject(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public JsonTypeInfo.As getTypeInclusion() {
}

private IonParser ionParser(JsonParser p) throws StreamReadException {
if (p instanceof IonParser) {
return (IonParser) p;
if (p instanceof IonParser ionParser) {
return ionParser;
}
throw new StreamReadException(p,
"Can only use IonAnnotationTypeDeserializer with IonParser");
Expand All @@ -68,8 +68,8 @@ private Object _deserialize(JsonParser p, DeserializationContext ctxt)
String[] typeIds = ionParser(p).getTypeAnnotations(); //cannot return null
String typeIdToUse = null;
TypeIdResolver typeIdResolver = super.getTypeIdResolver();
if (typeIdResolver instanceof MultipleTypeIdResolver) {
typeIdToUse = ((MultipleTypeIdResolver) typeIdResolver).selectId(typeIds);
if (typeIdResolver instanceof MultipleTypeIdResolver multiResolver) {
typeIdToUse = multiResolver.selectId(typeIds);
} else if (null != typeIdResolver) {
// Possibly multiple ids, but we don't have a polymorphic resolver; pick the first one which resolves
for (String typeId : typeIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ protected final void _generateTypeId(DatabindContext ctxt, WritableTypeId idMeta
if (id == null) {
final Object value = idMetadata.forValue;
TypeIdResolver resolver = getTypeIdResolver();
if (resolver instanceof MultipleTypeIdResolver) {
id = ((MultipleTypeIdResolver)resolver).idsFromValue(ctxt, value);
if (resolver instanceof MultipleTypeIdResolver multiResolver) {
id = multiResolver.idsFromValue(ctxt, value);
} else {
Class<?> typeForId = idMetadata.forValueType;
if (typeForId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

import tools.jackson.core.*;
Expand Down Expand Up @@ -1344,7 +1345,7 @@ protected void _releaseBuffers() {
/**********************************************************************
*/

private final static Charset UTF8 = Charset.forName("UTF-8");
private final static Charset UTF8 = StandardCharsets.UTF_8;

protected void _encodeLongerString(char[] text, int offset, int clen) throws JacksonException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int findEnumIndex(String key) {

@Override
public Collection<String> getEnumValues() {
return Collections.emptySet();
return Set.of();
}

@Override
Expand Down Expand Up @@ -113,7 +113,7 @@ public int findEnumIndex(String key) {

@Override
public Collection<String> getEnumValues() {
return Collections.singletonList(key1);
return List.of(key1);
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ public int findEnumIndex(String key) {

@Override
public Collection<String> getEnumValues() {
return Arrays.asList(key1, key2);
return List.of(key1, key2);
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ public int findEnumIndex(String key) {

@Override
public Collection<String> getEnumValues() {
return Arrays.asList(key1, key2, key3);
return List.of(key1, key2, key3);
}

private int _findIndex2(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static FieldType findType(DataType rawType) {
}

private FieldType _findType(DataType rawType) {
if (rawType instanceof DataType.ScalarType) {
return instance._types.get(rawType);
if (rawType instanceof DataType.ScalarType scalarType) {
return instance._types.get(scalarType);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ public String toString(String name) {

protected MessageElement _firstMessageType() {
for (TypeElement type : _nativeTypes) {
if (type instanceof MessageElement) {
return (MessageElement) type;
if (type instanceof MessageElement msg) {
return msg;
}
}
return null;
}

protected MessageElement _messageType(String name) {
for (TypeElement type : _nativeTypes) {
if ((type instanceof MessageElement)
if ((type instanceof MessageElement msg)
&& name.equals(type.name())) {
return (MessageElement) type;
return msg;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ private static Boolean _findBooleanOptionValue(FieldElement f, String key)
for (OptionElement opt : f.options()) {
if (key.equals(opt.name())) {
Object val = opt.value();
if (val instanceof Boolean) {
return (Boolean) val;
if (val instanceof Boolean boolVal) {
return boolVal;
}
return Boolean.valueOf("true".equals(String.valueOf(val).trim()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

import com.squareup.protoparser.ProtoFile;
Expand All @@ -22,7 +23,7 @@ public class ProtobufSchemaLoader
{
private static final long serialVersionUID = 1L;

private final static Charset UTF8 = Charset.forName("UTF-8");
private final static Charset UTF8 = StandardCharsets.UTF_8;

public final static String DEFAULT_SCHEMA_NAME = "Unnamed-protobuf-schema";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tools.jackson.dataformat.protobuf.schema;

import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -48,11 +46,11 @@ class ProtobufSchemaPreprocessor
* Statement-leading keywords that may appear in a message / extend body but
* do NOT begin a label-less field, and so must never receive an injected label.
*/
private static final Set<String> NON_FIELD_KEYWORDS = new HashSet<String>(Arrays.asList(
private static final Set<String> NON_FIELD_KEYWORDS = Set.of(
"message", "enum", "oneof", "extend", "group",
"option", "reserved", "extensions",
"required", "optional", "repeated"
));
);

private final char[] _data;
private final int _end;
Expand Down
Loading