mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
精简XXXTypeGetter
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.map.MapProxy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.map.MapProxy;
|
||||
|
||||
public class MapProxyTest {
|
||||
|
||||
@Test
|
||||
@@ -26,6 +25,7 @@ public class MapProxyTest {
|
||||
Assert.assertFalse(keys.isEmpty());
|
||||
|
||||
final Set<Entry<Object,Object>> entrys = mapProxy.entrySet();
|
||||
//noinspection ConstantConditions
|
||||
Assert.assertFalse(entrys.isEmpty());
|
||||
}
|
||||
|
||||
|
@@ -360,6 +360,8 @@ public class ConvertTest {
|
||||
final String str = "33020000210909112800000124";
|
||||
final BigDecimal bigDecimal = Convert.toBigDecimal(str);
|
||||
Assert.assertEquals(str, bigDecimal.toPlainString());
|
||||
|
||||
Assert.assertNull(Convert.toBigDecimal(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -62,11 +62,15 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
public void testToMap() {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
final Map<String, Integer> identityMap = wrap(list).toMap(String::valueOf);
|
||||
Assert.assertEquals(new HashMap<String, Integer>() {{
|
||||
put("1", 1);
|
||||
put("2", 2);
|
||||
put("3", 3);
|
||||
}}, identityMap);
|
||||
Assert.assertEquals(new HashMap<String, Integer>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put("1", 1);
|
||||
put("2", 2);
|
||||
put("3", 3);
|
||||
}
|
||||
}, identityMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,11 +86,15 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
final List<Integer> orders = asList(1, 2, 3);
|
||||
final List<String> list = asList("dromara", "hutool", "sweet");
|
||||
final Map<Integer, String> toZip = wrap(orders).toZip(list);
|
||||
Assert.assertEquals(new HashMap<Integer, String>() {{
|
||||
put(1, "dromara");
|
||||
put(2, "hutool");
|
||||
put(3, "sweet");
|
||||
}}, toZip);
|
||||
Assert.assertEquals(new HashMap<Integer, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put(1, "dromara");
|
||||
put(2, "hutool");
|
||||
put(3, "sweet");
|
||||
}
|
||||
}, toZip);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,11 +158,15 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
@Test
|
||||
public void testGrouping() {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
final Map<String, List<Integer>> map = new HashMap<String, List<Integer>>() {{
|
||||
put("1", singletonList(1));
|
||||
put("2", singletonList(2));
|
||||
put("3", singletonList(3));
|
||||
}};
|
||||
final Map<String, List<Integer>> map = new HashMap<String, List<Integer>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put("1", singletonList(1));
|
||||
put("2", singletonList(2));
|
||||
put("3", singletonList(3));
|
||||
}
|
||||
};
|
||||
|
||||
Map<String, List<Integer>> group = wrap(list).group(String::valueOf, HashMap::new, Collectors.toList());
|
||||
Assert.assertEquals(map, group);
|
||||
@@ -167,10 +179,13 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
@Test
|
||||
public void testPartitioning() {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
final Map<Boolean, List<Integer>> map = new HashMap<Boolean, List<Integer>>() {{
|
||||
put(Boolean.TRUE, singletonList(2));
|
||||
put(Boolean.FALSE, asList(1, 3));
|
||||
}};
|
||||
final Map<Boolean, List<Integer>> map = new HashMap<Boolean, List<Integer>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put(Boolean.TRUE, singletonList(2));
|
||||
put(Boolean.FALSE, asList(1, 3));
|
||||
}
|
||||
};
|
||||
|
||||
Map<Boolean, List<Integer>> partition = wrap(list).partition(t -> (t & 1) == 0, Collectors.toList());
|
||||
Assert.assertEquals(map, partition);
|
||||
@@ -553,7 +568,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
|
||||
@Test
|
||||
public void testFlatTree() {
|
||||
final Tree root = new Tree(1, asList(new Tree(2, asList(new Tree(3, Collections.emptyList())))));
|
||||
final Tree root = new Tree(1, ListUtil.of(new Tree(2, ListUtil.of(new Tree(3, Collections.emptyList())))));
|
||||
Assert.assertEquals(3L, wrap(root).flatTree(Tree::getChildren, Tree::setChildren).count());
|
||||
}
|
||||
|
||||
@@ -567,7 +582,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
@Test
|
||||
public void testMapNonNull() {
|
||||
Assert.assertEquals(
|
||||
asList("3"), wrap(null, 2, 3, 4).mapNonNull(t -> ((t & 1) == 0) ? null : String.valueOf(t)).toList()
|
||||
ListUtil.of("3"), wrap(null, 2, 3, 4).mapNonNull(t -> ((t & 1) == 0) ? null : String.valueOf(t)).toList()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -636,7 +651,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
List<String> zip = wrap(orders).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip);
|
||||
|
||||
zip = this.wrap((Stream<Integer>)EasyStream.iterate(1, i -> i + 1)).limit(10).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
zip = this.wrap((Stream<Integer>) EasyStream.iterate(1, i -> i + 1)).limit(10).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user