io.vavr.collection.HashMap.get()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中io.vavr.collection.HashMap.get()方法的一些代码示例,展示了HashMap.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.get()方法的具体详情如下:
包路径:io.vavr.collection.HashMap
类名称:HashMap
方法名:get

HashMap.get介绍

暂无

代码示例

代码示例来源:origin: vavr-io/vavr

@Override
public Option<V> get(K key) {
  return map.get(key);
}

代码示例来源:origin: vavr-io/vavr

@Override
public LinkedHashMap<K, V> replace(Tuple2<K, V> currentElement, Tuple2<K, V> newElement) {
  Objects.requireNonNull(currentElement, "currentElement is null");
  Objects.requireNonNull(newElement, "newElement is null");
  // We replace the whole element, i.e. key and value have to be present.
  if (!Objects.equals(currentElement, newElement) && contains(currentElement)) {
    Queue<Tuple2<K, V>> newList = list;
    HashMap<K, V> newMap = map;
    final K currentKey = currentElement._1;
    final K newKey = newElement._1;
    // If current key and new key are equal, the element will be automatically replaced,
    // otherwise we need to remove the pair (newKey, ?) from the list manually.
    if (!Objects.equals(currentKey, newKey)) {
      final Option<V> value = newMap.get(newKey);
      if (value.isDefined()) {
        newList = newList.remove(Tuple.of(newKey, value.get()));
      }
    }
    newList = newList.replace(currentElement, newElement);
    newMap = newMap.remove(currentKey).put(newElement);
    return wrap(newList, newMap);
  } else {
    return this;
  }
}

代码示例来源:origin: io.vavr/vavr

@Override
public Option<V> get(K key) {
  return map.get(key);
}

代码示例来源:origin: io.vavr/vavr

@Override
public LinkedHashMap<K, V> replace(Tuple2<K, V> currentElement, Tuple2<K, V> newElement) {
  Objects.requireNonNull(currentElement, "currentElement is null");
  Objects.requireNonNull(newElement, "newElement is null");
  // We replace the whole element, i.e. key and value have to be present.
  if (!Objects.equals(currentElement, newElement) && contains(currentElement)) {
    Queue<Tuple2<K, V>> newList = list;
    HashMap<K, V> newMap = map;
    final K currentKey = currentElement._1;
    final K newKey = newElement._1;
    // If current key and new key are equal, the element will be automatically replaced,
    // otherwise we need to remove the pair (newKey, ?) from the list manually.
    if (!Objects.equals(currentKey, newKey)) {
      final Option<V> value = newMap.get(newKey);
      if (value.isDefined()) {
        newList = newList.remove(Tuple.of(newKey, value.get()));
      }
    }
    newList = newList.replace(currentElement, newElement);
    newMap = newMap.remove(currentKey).put(newElement);
    return wrap(newList, newMap);
  } else {
    return this;
  }
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashMap() throws Exception {
  HashMap<String, A> src = HashMap.of("a", new B("a", "b"));
  String json = MAPPER.writeValueAsString(new HashMapPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":{\"a\":{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}}}");
  HashMapPojo pojo = MAPPER.readValue(json, HashMapPojo.class);
  HashMap<String, A> restored = pojo.getValue();
  Assert.assertTrue(restored.get("a").get() instanceof B);
  Assert.assertEquals(restored.get("a").get().a, "a");
  Assert.assertEquals(((B) restored.get("a").get()).b, "b");
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashMap() throws Exception {
  HashMap<String, I> src = HashMap.of("a", new A(), "b", new B());
  String json = MAPPER.writeValueAsString(new HashMapPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":{\"a\":{\"type\":\"a\"},\"b\":{\"type\":\"b\"}}}");
  HashMapPojo pojo = MAPPER.readValue(json, HashMapPojo.class);
  HashMap<String, I> restored = pojo.getValue();
  Assert.assertTrue(restored.get("a").get() instanceof A);
  Assert.assertTrue(restored.get("b").get() instanceof B);
}

相关文章