add method

This commit is contained in:
Looly
2021-09-17 20:02:41 +08:00
parent 2f57c2aaf9
commit b935ace121
5 changed files with 62 additions and 52 deletions

View File

@@ -772,25 +772,4 @@ public class CollUtilTest {
final List<String> sort = CollUtil.sort(of, new ComparableComparator<>());
Assert.assertEquals("a,b,c", CollUtil.join(sort, ","));
}
@Test
public void swapIndex() {
List<Integer> list = Arrays.asList(7, 2, 8, 9);
CollUtil.swapIndex(list, 8, 1);
Assert.assertTrue(list.get(1) == 8);
}
@Test
public void swapElement() {
Map<String, String> map1 = new HashMap<>();
map1.put("1", "张三");
Map<String, String> map2 = new HashMap<>();
map2.put("2", "李四");
Map<String, String> map3 = new HashMap<>();
map3.put("3", "王五");
List<Map<String, String>> list = Arrays.asList(map1, map2, map3);
CollUtil.swapElement(list, map2, map3);
Map<String, String> map = list.get(2);
Assert.assertTrue(map.get("2").equals("李四"));
}
}

View File

@@ -12,7 +12,9 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ListUtilTest {
@@ -202,4 +204,25 @@ public class ListUtilTest {
Assert.assertEquals("test4", order.get(3).getName());
Assert.assertEquals("test5", order.get(4).getName());
}
@Test
public void swapIndex() {
List<Integer> list = Arrays.asList(7, 2, 8, 9);
ListUtil.swapTo(list, 8, 1);
Assert.assertEquals(8, (int) list.get(1));
}
@Test
public void swapElement() {
Map<String, String> map1 = new HashMap<>();
map1.put("1", "张三");
Map<String, String> map2 = new HashMap<>();
map2.put("2", "李四");
Map<String, String> map3 = new HashMap<>();
map3.put("3", "王五");
List<Map<String, String>> list = Arrays.asList(map1, map2, map3);
ListUtil.swapElement(list, map2, map3);
Map<String, String> map = list.get(2);
Assert.assertEquals("李四", map.get("2"));
}
}