Skip to content

Commit

Permalink
use Apache Commons where possible, instead of homegrown solutions (DA…
Browse files Browse the repository at this point in the history
…T-17303) (#5853)
  • Loading branch information
StevenMassaro committed May 1, 2024
1 parent bf82a43 commit fb4d03e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 162 deletions.
@@ -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);
}
}
32 changes: 12 additions & 20 deletions liquibase-standard/src/main/java/liquibase/util/CollectionUtil.java
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<>());
}

/**
* 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 @@ -424,13 +425,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

0 comments on commit fb4d03e

Please sign in to comment.