本文整理了Java中java.util.HashMap.forEach()
方法的一些代码示例,展示了HashMap.forEach()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.forEach()
方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:forEach
暂无
代码示例来源:origin: stackoverflow.com
HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
/*
* Logic to put the Key,Value pair in your HashMap hm
*/
// Print the key value pair in one line.
hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));
代码示例来源:origin: stackoverflow.com
hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));
代码示例来源:origin: gchq/Gaffer
@Override
public String toString() {
final ToStringBuilder sb = new ToStringBuilder(this);
super.forEach((key, value) -> sb.append(key, String.format("<%s>%s", value.getClass().getCanonicalName(), value)));
return sb.build();
}
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public CompletableFuture<Void> closeAsync() {
if (closed) {
return closeFuture;
}
closed = true;
HashMap<RedisURI, ConnectionFuture<StatefulRedisPubSubConnection<String, String>>> connections = new HashMap<>(
pubSubConnections);
List<CompletableFuture<Void>> futures = new ArrayList<>();
connections.forEach((k, f) -> {
futures.add(f.exceptionally(t -> null).thenCompose(c -> {
if (c == null) {
return CompletableFuture.completedFuture(null);
}
c.removeListener(adapter);
return c.closeAsync();
}).toCompletableFuture());
pubSubConnections.remove(k);
});
Futures.allOf(futures).whenComplete((aVoid, throwable) -> {
if (throwable != null) {
closeFuture.completeExceptionally(throwable);
} else {
closeFuture.complete(null);
}
});
return closeFuture;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testRequestHeadersWithCharSequence() {
HashMap<CharSequence, String> headers = new HashMap<>();
headers.put(HttpHeaders.TEXT_HTML, "text/html");
headers.put(HttpHeaders.USER_AGENT, "User-Agent");
headers.put(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded");
server.requestHandler(req -> {
assertTrue(headers.size() < req.headers().size());
headers.forEach((k, v) -> assertEquals(v, req.headers().get(k)));
headers.forEach((k, v) -> assertEquals(v, req.getHeader(k)));
req.response().end();
});
server.listen(onSuccess(server -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete());
headers.forEach((k, v) -> req.headers().add(k, v));
req.end();
}));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testResponseHeadersWithCharSequence() {
HashMap<CharSequence, String> headers = new HashMap<>();
headers.put(HttpHeaders.TEXT_HTML, "text/html");
headers.put(HttpHeaders.USER_AGENT, "User-Agent");
headers.put(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded");
server.requestHandler(req -> {
headers.forEach((k, v) -> req.response().headers().add(k, v));
req.response().end();
});
server.listen(onSuccess(server -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> {
assertTrue(headers.size() < resp.headers().size());
headers.forEach((k,v) -> assertEquals(v, resp.headers().get(k)));
headers.forEach((k,v) -> assertEquals(v, resp.getHeader(k)));
testComplete();
})).end();
}));
await();
}
代码示例来源:origin: runelite/runelite
plugin.getObstaclesHull().forEach((obstacle, tile) ->
plugin.getObstaclesTile().forEach((obstacle, tile) ->
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: com.typesafe.play/play
/**
* @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: com.typesafe.play/play
/**
* @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
*/
@Deprecated
@Override
public void forEach(BiConsumer<? super String, ? super String> action) {
super.forEach(action);
}
代码示例来源:origin: stackoverflow.com
HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
/*
* Logic to put the Key,Value pair in your HashMap hm
*/
// Print the key value pair in one line.
hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));
// Just copy and paste above line to your code.
代码示例来源:origin: wildfly/wildfly
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
String contextID = deploymentUnit.getName();
if (deploymentUnit.getParent() != null) {
contextID = deploymentUnit.getParent().getName() + "!" + contextID;
}
EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
final boolean securityRequired = isExplicitSecurityDomainConfigured();
ejbComponentDescription.setSecurityRequired(securityRequired);
if (isSecurityDomainKnown()) {
final HashMap<Integer, InterceptorFactory> elytronInterceptorFactories = getElytronInterceptorFactories(contextID, ejbComponentDescription.isEnableJacc(), false);
elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> configuration.addPostConstructInterceptor(elytronInterceptorFactory, priority));
} else {
configuration.addPostConstructInterceptor(new SecurityContextInterceptorFactory(securityRequired, false, contextID), InterceptorOrder.View.SECURITY_CONTEXT);
}
}
});
代码示例来源:origin: wildfly/wildfly
if (ejbComponentDescription.isSecurityDomainKnown()) {
final HashMap<Integer, InterceptorFactory> elytronInterceptorFactories = getElytronInterceptorFactories(policyContextID, ejbComponentDescription.isEnableJacc(), true);
elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> configuration.addTimeoutViewInterceptor(elytronInterceptorFactory, priority));
} else if (deploymentUnit.hasAttachment(SecurityAttachments.SECURITY_ENABLED)) {
configuration.addTimeoutViewInterceptor(new SecurityContextInterceptorFactory(securityRequired, policyContextID), InterceptorOrder.View.SECURITY_CONTEXT);
代码示例来源:origin: wildfly/wildfly
elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> viewConfiguration.addViewInterceptor(elytronInterceptorFactory, priority));
} else {
viewConfiguration.addViewInterceptor(new SecurityContextInterceptorFactory(securityRequired, true, contextID), InterceptorOrder.View.SECURITY_CONTEXT);
代码示例来源:origin: stackoverflow.com
hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testRequestHeadersWithCharSequence() {
HashMap<CharSequence, String> headers = new HashMap<>();
headers.put(HttpHeaders.TEXT_HTML, "text/html");
headers.put(HttpHeaders.USER_AGENT, "User-Agent");
headers.put(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded");
server.requestHandler(req -> {
assertTrue(headers.size() < req.headers().size());
headers.forEach((k, v) -> assertEquals(v, req.headers().get(k)));
headers.forEach((k, v) -> assertEquals(v, req.getHeader(k)));
req.response().end();
});
server.listen(onSuccess(server -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> testComplete());
headers.forEach((k, v) -> req.headers().add(k, v));
req.end();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testResponseHeadersWithCharSequence() {
HashMap<CharSequence, String> headers = new HashMap<>();
headers.put(HttpHeaders.TEXT_HTML, "text/html");
headers.put(HttpHeaders.USER_AGENT, "User-Agent");
headers.put(HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded");
server.requestHandler(req -> {
headers.forEach((k, v) -> req.response().headers().add(k, v));
req.response().end();
});
server.listen(onSuccess(server -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
assertTrue(headers.size() < resp.headers().size());
headers.forEach((k,v) -> assertEquals(v, resp.headers().get(k)));
headers.forEach((k,v) -> assertEquals(v, resp.getHeader(k)));
testComplete();
}).end();
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!