mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
MapBuilder condition put
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MapBuilderTest {
|
||||
|
||||
@Test
|
||||
public void conditionPutTest() {
|
||||
Map<String, String> map = MapBuilder.<String, String>create()
|
||||
.put(true, "a", "1")
|
||||
.put(false, "b", "2")
|
||||
.put(true, "c", () -> getValue(3))
|
||||
.put(false, "d", () -> getValue(4))
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(map.get("a"), "1");
|
||||
Assert.assertFalse(map.containsKey("b"));
|
||||
Assert.assertEquals(map.get("c"), "3");
|
||||
Assert.assertFalse(map.containsKey("d"));
|
||||
}
|
||||
|
||||
public String getValue(int value) {
|
||||
System.out.println("getValue: " + value);
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user