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

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

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

HashMap.empty介绍

暂无

代码示例

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

/**
 * Alias for {@link HashMap#empty()}
 *
 * @param <K> The key type.
 * @param <V> The value type.
 * @return A singleton instance of empty {@link HashMap}
 */
public static <K, V> Map<K, V> Map() {
  return HashMap.empty();
}

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

@Override
protected <K2, V2> Map<K2, V2> emptyMapSupplier() {
  return HashMap.empty();
}

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

/**
 * Returns the empty {@code HashMultimap}.
 *
 * @param <K> The key type
 * @param <V2> The value type
 * @return A new empty HashMultimap.
 */
public <K, V2 extends V> HashMultimap<K, V2> empty() {
  return new HashMultimap<>(HashMap.empty(), containerType, emptyContainer);
}

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

@Override
public <K2> HashMap<K2, V> mapKeys(Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) {
  return Collections.mapKeys(this, HashMap.empty(), keyMapper, valueMerge);
}

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

/**
 * Converts this to a {@link Map}.
 *
 * @param f   A function that maps an element to a key/value pair represented by Tuple2
 * @param <K> The key type
 * @param <V> The value type
 * @return A new {@link HashMap}.
 */
default <K, V> Map<K, V> toMap(Function<? super T, ? extends Tuple2<? extends K, ? extends V>> f) {
  Objects.requireNonNull(f, "f is null");
  final Function<Tuple2<? extends K, ? extends V>, Map<K, V>> ofElement = HashMap::of;
  final Function<Iterable<Tuple2<? extends K, ? extends V>>, Map<K, V>> ofAll = HashMap::ofEntries;
  return ValueModule.toMap(this, HashMap.empty(), ofElement, ofAll, f);
}

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

/**
 * Returns a {@code HashMap}, from entries mapped from stream.
 *
 * @param stream      the source stream
 * @param entryMapper the entry mapper
 * @param <T>         The stream element type
 * @param <K>         The key type
 * @param <V>         The value type
 * @return A new Map
 */
public static <T, K, V> HashMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream,
    Function<? super T, Tuple2<? extends K, ? extends V>> entryMapper) {
  return Maps.ofStream(empty(), stream, entryMapper);
}

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

/**
 * Returns a {@code HashMap}, from entries mapped from stream.
 *
 * @param stream      the source stream
 * @param keyMapper   the key mapper
 * @param valueMapper the value mapper
 * @param <T>         The stream element type
 * @param <K>         The key type
 * @param <V>         The value type
 * @return A new Map
 */
public static <T, K, V> HashMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream,
    Function<? super T, ? extends K> keyMapper,
    Function<? super T, ? extends V> valueMapper) {
  return Maps.ofStream(empty(), stream, keyMapper, valueMapper);
}

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

@Override
public <K2, V2> HashMap<K2, V2> flatMap(BiFunction<? super K, ? super V, ? extends Iterable<Tuple2<K2, V2>>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  return foldLeft(HashMap.<K2, V2> empty(), (acc, entry) -> {
    for (Tuple2<? extends K2, ? extends V2> mappedEntry : mapper.apply(entry._1, entry._2)) {
      acc = acc.put(mappedEntry);
    }
    return acc;
  });
}

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

@SuppressWarnings("unchecked")
@Override
protected <K2, V2> HashMultimap<K2, V2> emptyInstance() {
  return new HashMultimap<>(HashMap.empty(), getContainerType(), emptyContainer);
}

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

private static <K, V> HashMap<K, V> wrap(HashArrayMappedTrie<K, V> trie) {
  return trie.isEmpty() ? empty() : new HashMap<>(trie);
}

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

@Override
public <K2, V2> HashMap<K2, V2> map(BiFunction<? super K, ? super V, Tuple2<K2, V2>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  return foldLeft(HashMap.empty(), (acc, entry) -> acc.put(entry.map(mapper)));
}

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

/**
 * Creates a LinkedHashMap of the given entries.
 *
 * @param entries Map entries
 * @param <K>     The key type
 * @param <V>     The value type
 * @return A new Map containing the given entries
 */
@SuppressWarnings("unchecked")
public static <K, V> LinkedHashMap<K, V> ofEntries(java.util.Map.Entry<? extends K, ? extends V>... entries) {
  HashMap<K, V> map = HashMap.empty();
  Queue<Tuple2<K, V>> list = Queue.empty();
  for (java.util.Map.Entry<? extends K, ? extends V> entry : entries) {
    final Tuple2<K, V> tuple = Tuple.of(entry.getKey(), entry.getValue());
    map = map.put(tuple);
    list = list.append(tuple);
  }
  return wrapNonUnique(list, map);
}

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

/**
 * Creates a HashMap of the given entries.
 *
 * @param entries Map entries
 * @param <K>     The key type
 * @param <V>     The value type
 * @return A new Map containing the given entries
 */
@SuppressWarnings("unchecked")
public static <K, V> HashMap<K, V> ofEntries(Iterable<? extends Tuple2<? extends K, ? extends V>> entries) {
  Objects.requireNonNull(entries, "entries is null");
  if (entries instanceof HashMap) {
    return (HashMap<K, V>) entries;
  } else {
    HashArrayMappedTrie<K, V> trie = HashArrayMappedTrie.empty();
    for (Tuple2<? extends K, ? extends V> entry : entries) {
      trie = trie.put(entry._1, entry._2);
    }
    return trie.isEmpty() ? empty() : wrap(trie);
  }
}

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

/**
 * Creates a LinkedHashMap of the given entries.
 *
 * @param entries Map entries
 * @param <K>     The key type
 * @param <V>     The value type
 * @return A new Map containing the given entries
 */
@SuppressWarnings("unchecked")
public static <K, V> LinkedHashMap<K, V> ofEntries(Iterable<? extends Tuple2<? extends K, ? extends V>> entries) {
  Objects.requireNonNull(entries, "entries is null");
  if (entries instanceof LinkedHashMap) {
    return (LinkedHashMap<K, V>) entries;
  } else {
    HashMap<K, V> map = HashMap.empty();
    Queue<Tuple2<K, V>> list = Queue.empty();
    for (Tuple2<? extends K, ? extends V> entry : entries) {
      map = map.put(entry);
      list = list.append((Tuple2<K, V>) entry);
    }
    return wrapNonUnique(list, map);
  }
}

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

@Override
public HashMap<K, V> removeAll(Iterable<? extends K> keys) {
  Objects.requireNonNull(keys, "keys is null");
  HashArrayMappedTrie<K, V> result = trie;
  for (K key : keys) {
    result = result.remove(key);
  }
  if (result.isEmpty()) {
    return empty();
  } else if (result.size() == trie.size()) {
    return this;
  } else {
    return wrap(result);
  }
}

代码示例来源:origin: apache/incubator-pinot

private static <T> Map<String, ?> serialize(T object, Class<? extends T> clazz, String pathContext)
  throws Exception {
 if (object == null) {
  return HashMap.empty();
 Map<String, Object> values = HashMap.empty();
 Map<String, Map<String, Object>> dslValues = HashMap.empty();
 Map<String, Class<? extends SingleKeyDsl>> dslClasses = HashMap.empty();
    Map<String, Object> dslValue = dslValues.getOrElse(keyName, HashMap.empty());
    dslValue = dslValue.put(useDsl.value(), field.get(object));
    dslValues = dslValues.put(keyName, dslValue);

代码示例来源:origin: apache/incubator-pinot

io.vavr.collection.Map<String, ConfigValue> overrideConfigMap = HashMap.empty();

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

/**
 * Alias for {@link HashMap#empty()}
 *
 * @param <K> The key type.
 * @param <V> The value type.
 * @return A singleton instance of empty {@link HashMap}
 */
public static <K, V> Map<K, V> Map() {
  return HashMap.empty();
}

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

@Override
public <K2, V2> HashMap<K2, V2> flatMap(BiFunction<? super K, ? super V, ? extends Iterable<Tuple2<K2, V2>>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  return foldLeft(HashMap.<K2, V2> empty(), (acc, entry) -> {
    for (Tuple2<? extends K2, ? extends V2> mappedEntry : mapper.apply(entry._1, entry._2)) {
      acc = acc.put(mappedEntry);
    }
    return acc;
  });
}

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

@Override
public <K2, V2> HashMap<K2, V2> map(BiFunction<? super K, ? super V, Tuple2<K2, V2>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  return foldLeft(HashMap.empty(), (acc, entry) -> acc.put(entry.map(mapper)));
}

相关文章