Apply "instanceof pattern matching" to remaining Validation classes
This commit is contained in:
parent
9305a64a50
commit
024d02225c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -169,8 +169,8 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
public List<FieldError> getFieldErrors() {
|
||||
List<FieldError> result = new ArrayList<>();
|
||||
for (ObjectError objectError : this.errors) {
|
||||
if (objectError instanceof FieldError) {
|
||||
result.add((FieldError) objectError);
|
||||
if (objectError instanceof FieldError fieldError) {
|
||||
result.add(fieldError);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
|
|
@ -180,8 +180,8 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
@Nullable
|
||||
public FieldError getFieldError() {
|
||||
for (ObjectError objectError : this.errors) {
|
||||
if (objectError instanceof FieldError) {
|
||||
return (FieldError) objectError;
|
||||
if (objectError instanceof FieldError fieldError) {
|
||||
return fieldError;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -192,8 +192,8 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
List<FieldError> result = new ArrayList<>();
|
||||
String fixedField = fixedField(field);
|
||||
for (ObjectError objectError : this.errors) {
|
||||
if (objectError instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) objectError)) {
|
||||
result.add((FieldError) objectError);
|
||||
if (objectError instanceof FieldError fieldError && isMatchingFieldError(fixedField, fieldError)) {
|
||||
result.add(fieldError);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
|
|
@ -204,10 +204,8 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
public FieldError getFieldError(String field) {
|
||||
String fixedField = fixedField(field);
|
||||
for (ObjectError objectError : this.errors) {
|
||||
if (objectError instanceof FieldError fieldError) {
|
||||
if (isMatchingFieldError(fixedField, fieldError)) {
|
||||
return fieldError;
|
||||
}
|
||||
if (objectError instanceof FieldError fieldError && isMatchingFieldError(fixedField, fieldError)) {
|
||||
return fieldError;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -42,10 +42,15 @@ public abstract class BindingResultUtils {
|
|||
Assert.notNull(model, "Model map must not be null");
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name);
|
||||
if (attr != null && !(attr instanceof BindingResult)) {
|
||||
if (attr == null) {
|
||||
return null;
|
||||
}
|
||||
if (attr instanceof BindingResult bindingResult) {
|
||||
return bindingResult;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("BindingResult attribute is not of type BindingResult: " + attr);
|
||||
}
|
||||
return (BindingResult) attr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -849,8 +849,8 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
|||
PropertyValue pv = propertyValues.get(field);
|
||||
boolean empty = (pv == null || pv.getValue() == null);
|
||||
if (!empty) {
|
||||
if (pv.getValue() instanceof String) {
|
||||
empty = !StringUtils.hasText((String) pv.getValue());
|
||||
if (pv.getValue() instanceof String text) {
|
||||
empty = !StringUtils.hasText(text);
|
||||
}
|
||||
else if (pv.getValue() instanceof String[] values) {
|
||||
empty = (values.length == 0 || !StringUtils.hasText(values[0]));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -105,8 +105,8 @@ public class ObjectError extends DefaultMessageSourceResolvable {
|
|||
if (sourceType.isInstance(this.source)) {
|
||||
return sourceType.cast(this.source);
|
||||
}
|
||||
else if (this.source instanceof Throwable) {
|
||||
Throwable cause = ((Throwable) this.source).getCause();
|
||||
else if (this.source instanceof Throwable throwable) {
|
||||
Throwable cause = throwable.getCause();
|
||||
if (sourceType.isInstance(cause)) {
|
||||
return sourceType.cast(cause);
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ public class ObjectError extends DefaultMessageSourceResolvable {
|
|||
*/
|
||||
public boolean contains(Class<?> sourceType) {
|
||||
return (sourceType.isInstance(this.source) ||
|
||||
(this.source instanceof Throwable && sourceType.isInstance(((Throwable) this.source).getCause())));
|
||||
(this.source instanceof Throwable throwable && sourceType.isInstance(throwable.getCause())));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -64,7 +64,7 @@ public abstract class ValidationAnnotationUtils {
|
|||
if (hints == null) {
|
||||
return EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
return (hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
|
||||
return (hints instanceof Object[] objectHints ? objectHints : new Object[] {hints});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue