mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add sortJoin
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Editor;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MapUtilTest {
|
||||
|
||||
@@ -20,16 +21,7 @@ public class MapUtilTest {
|
||||
map.put("c", "3");
|
||||
map.put("d", "4");
|
||||
|
||||
Map<String, String> map2 = MapUtil.filter(map, new Filter<Entry<String, String>>() {
|
||||
|
||||
@Override
|
||||
public boolean accept(Entry<String, String> t) {
|
||||
if (Convert.toInt(t.getValue()) % 2 == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
Map<String, String> map2 = MapUtil.filter(map, (Filter<Entry<String, String>>) t -> Convert.toInt(t.getValue()) % 2 == 0);
|
||||
|
||||
Assert.assertEquals(2, map2.size());
|
||||
|
||||
@@ -45,14 +37,10 @@ public class MapUtilTest {
|
||||
map.put("c", "3");
|
||||
map.put("d", "4");
|
||||
|
||||
Map<String, String> map2 = MapUtil.filter(map, new Editor<Entry<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Entry<String, String> edit(Entry<String, String> t) {
|
||||
// 修改每个值使之*10
|
||||
t.setValue(t.getValue() + "0");
|
||||
return t;
|
||||
}
|
||||
Map<String, String> map2 = MapUtil.filter(map, (Editor<Entry<String, String>>) t -> {
|
||||
// 修改每个值使之*10
|
||||
t.setValue(t.getValue() + "0");
|
||||
return t;
|
||||
});
|
||||
|
||||
Assert.assertEquals(4, map2.size());
|
||||
@@ -97,4 +85,21 @@ public class MapUtilTest {
|
||||
Assert.assertEquals("d", objectArray[3][0]);
|
||||
Assert.assertEquals("4", objectArray[3][1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortJoinTest(){
|
||||
Map<String, String> build = MapUtil.builder(new HashMap<String, String>())
|
||||
.put("key1", "value1")
|
||||
.put("key3", "value3")
|
||||
.put("key2", "value2").build();
|
||||
|
||||
String join1 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false);
|
||||
Assert.assertEquals("key1value1key2value2key3value3", join1);
|
||||
|
||||
String join2 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false, "123");
|
||||
Assert.assertEquals("key1value1key2value2key3value3123", join2);
|
||||
|
||||
String join3 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false, "123", "abc");
|
||||
Assert.assertEquals("key1value1key2value2key3value3123abc", join3);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user