Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Apache Commons where possible, instead of homegrown solutions (DAT-17303) #5853

Merged
merged 8 commits into from
May 1, 2024
Merged
@@ -1,5 +1,7 @@
package liquibase.util;

import org.apache.commons.lang3.BooleanUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -39,8 +41,10 @@ private static boolean isTrue(String str) {
* - isTrue(null) = false
* - isTrue(false) = false
* - isTrue(true) = true
* @deprecated use {@link BooleanUtils#isTrue(Boolean)} instead
*/
@Deprecated
public static boolean isTrue(Boolean value) {
return Boolean.TRUE.equals(value);
return BooleanUtils.isTrue(value);
}
}
Expand Up @@ -57,46 +57,38 @@ private static <T> void permute(Map<String, T> basePermutation, List<String> rem
* Returns passed currentValue if it is not null and creates a new ArrayList if it is null.
* <br><br>
* Example: values = createIfNull(values)
* @deprecated use {@link org.apache.commons.collections4.CollectionUtils} instead
*/
@Deprecated
public static <T> List<T> createIfNull(List<T> currentValue) {
if (currentValue == null) {
return new ArrayList<>();
} else {
return currentValue;
}
return ObjectUtil.defaultIfNull(currentValue, new ArrayList<>());
StevenMassaro marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns a new empty array if the passed array is null.
* @deprecated use {@link org.apache.commons.collections4.CollectionUtils} instead
*/
@Deprecated
public static <T> T[] createIfNull(T[] arguments) {
if (arguments == null) {
return (T[]) new Object[0];
} else {
return arguments;
}
return ObjectUtil.defaultIfNull(arguments, (T[]) new Object[0]);
}

/**
* Returns a new empty set if the passed set is null.
* @deprecated use {@link org.apache.commons.collections4.CollectionUtils} instead
*/
@Deprecated
public static <T> Set<T> createIfNull(Set<T> currentValue) {
if (currentValue == null) {
return new HashSet<>();
} else {
return currentValue;
}
return ObjectUtil.defaultIfNull(currentValue, new HashSet<>());
}

/**
* Returns a new empty map if the passed map is null.
* @deprecated use {@link org.apache.commons.collections4.CollectionUtils} instead
*/
@Deprecated
public static <T, E> Map<T, E> createIfNull(Map<T, E> currentValue) {
if (currentValue == null) {
return new HashMap<>();
} else {
return currentValue;
}
return ObjectUtil.defaultIfNull(currentValue, new HashMap<>());
}

/**
Expand Down
Expand Up @@ -5,6 +5,7 @@
import liquibase.statement.DatabaseFunction;
import liquibase.statement.SequenceCurrentValueFunction;
import liquibase.statement.SequenceNextValueFunction;
import org.apache.commons.lang3.ObjectUtils;

import java.beans.IntrospectionException;
import java.beans.Introspector;
Expand Down Expand Up @@ -426,13 +427,11 @@ private static void raiseOverflowException(Number number, Class targetClass) {

/**
* Return the defaultValue if the passed value is null. Otherwise, return the original value.
* @deprecated use {@link ObjectUtils#defaultIfNull(Object, Object)} instead
*/
@Deprecated
public static <T> T defaultIfNull(T value, T defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
return ObjectUtils.defaultIfNull(value, defaultValue);
}

/**
Expand Down