Java Code Examples for io.vavr.collection.HashMap#of()

The following examples show how to use io.vavr.collection.HashMap#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionAPIUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenMap_whenMapApi_thenCorrect() {
    Map<Integer, List<Integer>> map = List.rangeClosed(0, 10)
      .groupBy(i -> i % 2);
    
    assertEquals(2, map.size());
    assertEquals(6, map.get(0).get().size());
    assertEquals(5, map.get(1).get().size());

    Map<String, String> map1
      = HashMap.of("key1", "val1", "key2", "val2", "key3", "val3");

    Map<String, String> fMap
      = map1.filterKeys(k -> k.contains("1") || k.contains("2"));
    assertFalse(fMap.containsKey("key3"));

    Map<String, String> fMap2
      = map1.filterValues(v -> v.contains("3"));
    assertEquals(fMap2.size(), 1);
    assertTrue(fMap2.containsValue("val3"));

    Map<String, Integer> map2 = map1.map(
      (k, v) -> Tuple.of(k, Integer.valueOf(v.charAt(v.length() - 1) + "") ));
    assertEquals(map2.get("key1").get().intValue(), 1);
}
 
Example 2
Source File: BindingClassTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testHashMapClass() throws Exception {
    HashMapClass src = new HashMapClass(HashMap.of(42, new ImplementedClass()));
    String json = MAPPER.writeValueAsString(src);
    HashMapClass restored = MAPPER.readValue(json, HashMapClass.class);
    Assertions.assertEquals(restored.value.head()._2.getClass(), ImplementedClass.class);
}
 
Example 3
Source File: ExtFieldsPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testHashMap() throws Exception {
    HashMap<String, A> src = HashMap.of("a", new B("a", "b"));
    String json = MAPPER.writeValueAsString(new HashMapPojo().setValue(src));
    Assertions.assertEquals(json, "{\"value\":{\"a\":{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}}}");
    HashMapPojo pojo = MAPPER.readValue(json, HashMapPojo.class);
    HashMap<String, A> restored = pojo.getValue();
    Assertions.assertTrue(restored.get("a").get() instanceof B);
    Assertions.assertEquals(restored.get("a").get().a, "a");
    Assertions.assertEquals(((B) restored.get("a").get()).b, "b");
}
 
Example 4
Source File: PolymorphicPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testHashMap() throws Exception {
    HashMap<String, I> src = HashMap.of("a", new A(), "b", new B());
    String json = MAPPER.writeValueAsString(new HashMapPojo().setValue(src));
    Assertions.assertEquals(json, "{\"value\":{\"a\":{\"type\":\"a\"},\"b\":{\"type\":\"b\"}}}");
    HashMapPojo pojo = MAPPER.readValue(json, HashMapPojo.class);
    HashMap<String, I> restored = pojo.getValue();
    Assertions.assertTrue(restored.get("a").get() instanceof A);
    Assertions.assertTrue(restored.get("b").get() instanceof B);
}
 
Example 5
Source File: CollectionsInteroperabilityUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenParams_whenVavrMap_thenReturnJavaMap() {
  Map<String, String> vavrMap = HashMap.of("1", "a", "2", "b", "3", "c");

  java.util.Map<String, String> javaMap = vavrMap.toJavaMap();
  assertTrue(javaMap instanceof java.util.Map);
}
 
Example 6
Source File: AbstractContentTest.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Test
void testMap() throws IOException {
    M m = new M(HashMap.of(1, new X("a", 1), 42, new X("bbb", 42)));
    json_roundtrip_test(m, M.class);
}