Deprecated StringUtils.mergeStringArrays
(cherry picked from commit 0f74052)
This commit is contained in:
@@ -815,7 +815,10 @@ public abstract class StringUtils {
|
|||||||
* @param array1 the first array (can be {@code null})
|
* @param array1 the first array (can be {@code null})
|
||||||
* @param array2 the second array (can be {@code null})
|
* @param array2 the second array (can be {@code null})
|
||||||
* @return the new array ({@code null} if both given arrays were {@code null})
|
* @return the new array ({@code null} if both given arrays were {@code null})
|
||||||
|
* @deprecated as of 4.3.15, in favor of manual merging via {@link LinkedHashSet}
|
||||||
|
* (with every entry included at most once, even entries within the first array)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String[] mergeStringArrays(String[] array1, String[] array2) {
|
public static String[] mergeStringArrays(String[] array1, String[] array2) {
|
||||||
if (ObjectUtils.isEmpty(array1)) {
|
if (ObjectUtils.isEmpty(array1)) {
|
||||||
return array2;
|
return array2;
|
||||||
@@ -824,9 +827,13 @@ public abstract class StringUtils {
|
|||||||
return array1;
|
return array1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> result = new LinkedHashSet<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
result.addAll(Arrays.asList(array1));
|
result.addAll(Arrays.asList(array1));
|
||||||
result.addAll(Arrays.asList(array2));
|
for (String str : array2) {
|
||||||
|
if (!result.contains(str)) {
|
||||||
|
result.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
return toStringArray(result);
|
return toStringArray(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -443,6 +443,7 @@ public class StringUtilsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
public void testMergeStringArrays() {
|
public void testMergeStringArrays() {
|
||||||
String[] input1 = new String[] {"myString2"};
|
String[] input1 = new String[] {"myString2"};
|
||||||
String[] input2 = new String[] {"myString1", "myString2"};
|
String[] input2 = new String[] {"myString1", "myString2"};
|
||||||
|
|||||||
Reference in New Issue
Block a user