Skip to content

Commit

Permalink
chore(commons): Fix instanceof check and cast with pattern matching i…
Browse files Browse the repository at this point in the history
…n commons. [operaton#85]

* Fix instanceof check and cast with pattern matching in clients. (operaton#85)

* Fix instanceof check and cast with pattern matching in commons. (operaton#85)

* Fix instanceof check and cast with pattern matching in clients. (operaton#85)

---------

Co-authored-by: CBorowski-dev <[email protected]>
  • Loading branch information
CBorowski-dev and CBorowski-dev authored Nov 27, 2024
1 parent 5a73e49 commit e29b101
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public static VariableMap createVariables() {
* it is returned as is.
*/
public static VariableMap fromMap(Map<String, Object> map) {
if(map instanceof VariableMap) {
return (VariableMap) map;
if(map instanceof VariableMap variableMap) {
return variableMap;
}
else {
return new VariableMapImpl(map);
Expand Down Expand Up @@ -364,8 +364,8 @@ public static TypedValue untypedValue(Object value) {
if (untypedValue instanceof TypedValueBuilder) {
untypedValue = ((TypedValueBuilder<?>) untypedValue).create();
}
if (untypedValue instanceof TypedValue) {
return untypedValue(untypedValue, ((TypedValue) untypedValue).isTransient());
if (untypedValue instanceof TypedValue typedvalue) {
return untypedValue(typedvalue, typedvalue.isTransient());
}
else return untypedValue(untypedValue, false);
}
Expand All @@ -379,8 +379,7 @@ public static TypedValue untypedValue(Object value, boolean isTransient) {
return untypedNullValue(isTransient);
} else if (value instanceof TypedValueBuilder<?>) {
return ((TypedValueBuilder<?>) value).setTransient(isTransient).create();
} else if (value instanceof TypedValue) {
TypedValue transientValue = (TypedValue) value;
} else if (value instanceof TypedValue transientValue) {
if (value instanceof NullValueImpl) {
transientValue = untypedNullValue(isTransient);
} else if (value instanceof FileValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public Object remove(Object key) {

public void putAll(Map<? extends String, ? extends Object> m) {
if(m != null) {
if(m instanceof VariableMapImpl) {
variables.putAll(((VariableMapImpl)m).variables);
if(m instanceof VariableMapImpl variableMapImpl) {
variables.putAll(variableMapImpl.variables);
}
else {
for (java.util.Map.Entry<? extends String, ? extends Object> entry : m.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public boolean equals(Object obj) {

protected Boolean isTransient(Map<String, Object> valueInfo) {
if (valueInfo != null && valueInfo.containsKey(VALUE_INFO_TRANSIENT)) {
Object isTransient = valueInfo.get(VALUE_INFO_TRANSIENT);
if (isTransient instanceof Boolean) {
return (Boolean) isTransient;
Object valueInfoTransient = valueInfo.get(VALUE_INFO_TRANSIENT);
if (valueInfoTransient instanceof Boolean isTransient) {
return isTransient;
} else {
throw new IllegalArgumentException("The property 'transient' should have a value of type 'boolean'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public TypedValue createValue(Object value, Map<String, Object> valueInfo) {
throw new IllegalArgumentException("Cannot create file without filename! Please set a name into ValueInfo with key " + VALUE_INFO_FILE_NAME);
}
FileValueBuilder builder = Variables.fileValue(filename.toString());
if (value instanceof File) {
builder.file((File) value);
} else if (value instanceof InputStream) {
builder.file((InputStream) value);
} else if (value instanceof byte[]) {
builder.file((byte[]) value);
if (value instanceof File file) {
builder.file(file);
} else if (value instanceof InputStream inputStream) {
builder.file(inputStream);
} else if (value instanceof byte[] byteArray) {
builder.file(byteArray);
} else {
throw new IllegalArgumentException("Provided value is not of File, InputStream or byte[] type.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public SerializableValue createValueFromSerialized(String serializedValue, Map<S
protected void applyValueInfo(ObjectValueBuilder builder, Map<String, Object> valueInfo) {

String objectValueTypeName = (String) valueInfo.get(VALUE_INFO_OBJECT_TYPE_NAME);
if (builder instanceof SerializedObjectValueBuilder) {
((SerializedObjectValueBuilder) builder).objectTypeName(objectValueTypeName);
if (builder instanceof SerializedObjectValueBuilder serializedObjectValueBuilder) {
serializedObjectValueBuilder.objectTypeName(objectValueTypeName);
}

String serializationDataFormat = (String) valueInfo.get(VALUE_INFO_SERIALIZATION_DATA_FORMAT);
Expand Down

0 comments on commit e29b101

Please sign in to comment.