本文整理了Java中com.google.common.collect.Maps.newHashMap()
方法的一些代码示例,展示了Maps.newHashMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.newHashMap()
方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:newHashMap
[英]Creates a mutable, empty HashMap instance.
Note: if mutability is not required, use ImmutableMap#of() instead.
Note: if K is an enum type, use #newEnumMap instead.
[中]创建一个可变的空HashMap实例。
注意:如果不需要可变性,请改用ImmutableMap#of()。
注意:如果K是枚举类型,请改用#newEnumMap。
代码示例来源:origin: google/guava
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
Map<AnEnum, String> map = Maps.newHashMap();
for (Entry<AnEnum, String> entry : entries) {
// checkArgument(!map.containsKey(entry.getKey()));
map.put(entry.getKey(), entry.getValue());
}
return Maps.immutableEnumMap(map);
}
}
代码示例来源:origin: Graylog2/graylog2-server
public Periodicals(ScheduledExecutorService scheduler, ScheduledExecutorService daemonScheduler) {
this.scheduler = scheduler;
this.daemonScheduler = daemonScheduler;
this.periodicals = Lists.newArrayList();
this.futures = Maps.newHashMap();
}
代码示例来源:origin: alibaba/jstorm
@Override
public Map<K, V> getBatch(Collection<K> keys) throws IOException {
Map<K, V> batch = Maps.<K, V>newHashMap();
for (K key : keys) {
batch.put(key, kvStore.get(key));
}
return batch;
}
代码示例来源:origin: MovingBlocks/Terasology
private void loadBlocks() {
blockFamilyIds = Maps.newHashMap();
gameInfo.getManifest().getBlockIdMap().entrySet().forEach(blockId -> {
String familyName = blockId.getKey().split(":")[0].toLowerCase();
blockFamilyIds.computeIfAbsent(familyName, k -> new ArrayList<>());
blockFamilyIds.get(familyName).add(blockId.toString());
});
blocks.setList(Lists.newArrayList(blockFamilyIds.keySet()));
}
代码示例来源:origin: Graylog2/graylog2-server
@JsonIgnore
public Map<String, List<RequestedConfigurationField>> getRequestedConfiguration() {
Map<String, List<RequestedConfigurationField>> result = Maps.newHashMap();
for (Map.Entry<String, AvailableAlarmCallbackSummaryResponse> entry : types.entrySet()) {
result.put(entry.getKey(), entry.getValue().extractRequestedConfiguration(entry.getValue().requested_configuration));
}
return result;
}
}
代码示例来源:origin: spotify/helios
protected Map<String, MasterMain> startDefaultMasters(final int numMasters, String... args)
throws Exception {
final Map<String, MasterMain> masters = Maps.newHashMap();
for (int i = 0; i < numMasters; i++) {
final String name = TEST_MASTER + i;
final List<String> argsList = Lists.newArrayList(args);
argsList.addAll(asList("--name", name));
masters.put(name, startDefaultMaster(i, argsList.toArray(new String[argsList.size()])));
}
return masters;
}
代码示例来源:origin: spotify/helios
/**
* Get environment variables for the container.
*
* @return The environment variables.
*/
public Map<String, String> containerEnv() {
final Map<String, String> env = Maps.newHashMap(envVars);
// Put in variables that tell the container where it's exposed
for (final Entry<String, Integer> entry : ports.entrySet()) {
env.put("HELIOS_PORT_" + entry.getKey(), host + ":" + entry.getValue());
}
// Job environment variables take precedence.
env.putAll(job.getEnv());
return env;
}
代码示例来源:origin: Graylog2/graylog2-server
public void setMessage(String id, Map<String, Object> message) {
Map<String, Object> tmp = Maps.newHashMap();
tmp.putAll(message);
tmp.put(Message.FIELD_ID, id);
if (tmp.containsKey(Message.FIELD_TIMESTAMP)) {
final Object tsField = tmp.get(Message.FIELD_TIMESTAMP);
try {
tmp.put(Message.FIELD_TIMESTAMP, ES_DATE_FORMAT_FORMATTER.parseDateTime(String.valueOf(tsField)));
} catch (IllegalArgumentException e) {
// could not parse date string, this is likely a bug, but we will leave the original value alone
LOG.warn("Could not parse timestamp of message {}", message.get("id"), e);
}
}
this.message = new Message(tmp);
}
代码示例来源:origin: atomix/atomix
@Override
public CompletableFuture<Boolean> containsAll(Collection<? extends String> keys) {
Map<PartitionId, Collection<String>> partitions = Maps.newHashMap();
keys.forEach(key -> partitions.computeIfAbsent(getProxyClient().getPartitionId(key), k -> Lists.newArrayList()).add(key));
return Futures.allOf(partitions.entrySet().stream()
.map(entry -> getProxyClient()
.applyOn(entry.getKey(), service -> service.containsKeys(entry.getValue())))
.collect(Collectors.toList()))
.thenApply(results -> results.stream().reduce(Boolean::logicalAnd).orElse(false));
}
代码示例来源:origin: alibaba/jstorm
/**
* get the component's configuration
*/
public static Map getComponentMap(DefaultTopologyAssignContext context, Integer task) {
String componentName = context.getTaskToComponent().get(task);
ComponentCommon componentCommon = ThriftTopologyUtils.getComponentCommon(context.getSysTopology(), componentName);
Map componentMap = (Map) JStormUtils.from_json(componentCommon.get_json_conf());
if (componentMap == null) {
componentMap = Maps.newHashMap();
}
return componentMap;
}
代码示例来源:origin: syncany/syncany
public void stop() {
logger.log(Level.INFO, "Stopping watch server ... ");
Map<File, WatchRunner> copyOfWatchOperations = Maps.newHashMap(watchOperations);
for (Map.Entry<File, WatchRunner> folderEntry : copyOfWatchOperations.entrySet()) {
File localDir = folderEntry.getKey();
WatchRunner watchOperationThread = folderEntry.getValue();
logger.log(Level.INFO, "- Stopping watch operation at " + localDir + " ...");
watchOperationThread.stop();
watchOperations.remove(localDir);
}
}
代码示例来源:origin: google/guava
@Override
protected final Map<String, String> create(Entry<String, String>[] entries) {
HashMap<String, String> map = Maps.newHashMap();
for (Entry<String, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return wrap(map);
}
代码示例来源:origin: spotify/helios
@Override
public List<ACL> getAclForPath(final String path) {
// id -> permissions
final Map<Id, Integer> matching = Maps.newHashMap();
for (final Rule rule : rules) {
if (rule.matches(path)) {
final int existingPerms = matching.containsKey(rule.id) ? matching.get(rule.id) : 0;
matching.put(rule.id, rule.perms | existingPerms);
}
}
if (matching.isEmpty()) {
return null;
}
final List<ACL> acls = Lists.newArrayList();
for (final Map.Entry<Id, Integer> e : matching.entrySet()) {
acls.add(new ACL(e.getValue(), e.getKey()));
}
return acls;
}
代码示例来源:origin: apache/flume
private Map<String, String> selectByKeys(Map<String, String> map, String[] keys) {
Map<String, String> result = Maps.newHashMap();
for (String key : keys) {
if (map.containsKey(key)) {
result.put(key, map.get(key));
}
}
return result;
}
代码示例来源:origin: apache/hive
protected void createOutputMap() {
Preconditions.checkState(outMap == null, "Outputs should only be setup once");
outMap = Maps.newHashMap();
for (Entry<String, LogicalOutput> entry : outputs.entrySet()) {
TezKVOutputCollector collector = new TezKVOutputCollector(entry.getValue());
outMap.put(entry.getKey(), collector);
}
}
代码示例来源:origin: google/guava
@Override
public Map<Object, Object> loadAll(Iterable<?> keys) throws Exception {
Map<Object, Object> result = Maps.newHashMap();
// ignore request keys
result.put(extraKey, extraValue);
return result;
}
};
代码示例来源:origin: ctripcorp/apollo
String assembleQueryConfigUrl(String uri, String appId, String cluster, String namespace,
String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) {
String path = "configs/%s/%s/%s";
List<String> pathParams =
Lists.newArrayList(pathEscaper.escape(appId), pathEscaper.escape(cluster),
pathEscaper.escape(namespace));
Map<String, String> queryParams = Maps.newHashMap();
if (previousConfig != null) {
queryParams.put("releaseKey", queryParamEscaper.escape(previousConfig.getReleaseKey()));
}
if (!Strings.isNullOrEmpty(dataCenter)) {
queryParams.put("dataCenter", queryParamEscaper.escape(dataCenter));
}
String localIp = m_configUtil.getLocalIp();
if (!Strings.isNullOrEmpty(localIp)) {
queryParams.put("ip", queryParamEscaper.escape(localIp));
}
if (remoteMessages != null) {
queryParams.put("messages", queryParamEscaper.escape(gson.toJson(remoteMessages)));
}
String pathExpanded = String.format(path, pathParams.toArray());
if (!queryParams.isEmpty()) {
pathExpanded += "?" + MAP_JOINER.join(queryParams);
}
if (!uri.endsWith("/")) {
uri += "/";
}
return uri + pathExpanded;
}
代码示例来源:origin: apache/kylin
protected String generateSqoopConfigArgString() {
KylinConfig kylinConfig = getConfig();
Map<String, String> config = Maps.newHashMap();
config.put("mapreduce.job.queuename", getSqoopJobQueueName(kylinConfig)); // override job queue from mapreduce config
config.putAll(SourceConfigurationUtil.loadSqoopConfiguration());
config.putAll(kylinConfig.getSqoopConfigOverride());
StringBuilder args = new StringBuilder();
for (Map.Entry<String, String> entry : config.entrySet()) {
args.append(" -D" + entry.getKey() + "=" + entry.getValue() + " ");
}
return args.toString();
}
代码示例来源:origin: atomix/atomix
@Override
public CompletableFuture<Boolean> containsAll(Collection<? extends String> keys) {
Map<PartitionId, Collection<String>> partitions = Maps.newHashMap();
keys.forEach(key -> partitions.computeIfAbsent(getProxyClient().getPartitionId(key), k -> Lists.newArrayList()).add(key));
return Futures.allOf(partitions.entrySet().stream()
.map(entry -> getProxyClient()
.applyOn(entry.getKey(), service -> service.containsKeys(entry.getValue())))
.collect(Collectors.toList()))
.thenApply(results -> results.stream().reduce(Boolean::logicalAnd).orElse(false));
}
代码示例来源:origin: alibaba/canal
public synchronized Map<Long, PositionRange> listAllPositionRange() {
Set<Long> batchIdSets = batches.keySet();
List<Long> batchIds = Lists.newArrayList(batchIdSets);
Collections.sort(Lists.newArrayList(batchIds));
return Maps.newHashMap(batches);
}
内容来源于网络,如有侵权,请联系作者删除!