Merge branch '6.0.x'

This commit is contained in:
Sam Brannen
2023-07-05 17:02:35 +02:00
2 changed files with 50 additions and 10 deletions

View File

@@ -58,6 +58,9 @@ public abstract class ObjectUtils {
private static final String EMPTY_ARRAY = ARRAY_START + ARRAY_END;
private static final String ARRAY_ELEMENT_SEPARATOR = ", ";
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
private static final String NON_EMPTY_ARRAY = ARRAY_START + "..." + ARRAY_END;
private static final String EMPTY_COLLECTION = "[]";
private static final String NON_EMPTY_COLLECTION = "[...]";
/**
@@ -936,6 +939,16 @@ public abstract class ObjectUtils {
return (optional.isEmpty() ? "Optional.empty" :
"Optional[%s]".formatted(nullSafeConciseToString(optional.get())));
}
if (obj.getClass().isArray()) {
return (Array.getLength(obj) == 0 ? EMPTY_ARRAY : NON_EMPTY_ARRAY);
}
if (obj instanceof Collection<?> collection) {
return (collection.isEmpty() ? EMPTY_COLLECTION : NON_EMPTY_COLLECTION);
}
if (obj instanceof Map<?, ?> map) {
// EMPTY_ARRAY and NON_EMPTY_ARRAY are also used for maps.
return (map.isEmpty() ? EMPTY_ARRAY : NON_EMPTY_ARRAY);
}
if (obj instanceof Class<?> clazz) {
return clazz.getName();
}