java.util.ArrayList.forEach()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(332)

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

ArrayList.forEach介绍

暂无

代码示例

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

void free()
 {
  open = false;
  buffers.forEach(ByteBufferUtils::free);
  buffers.clear();
  headBufferIndex = -1;
  headBuffer = null;
  size = 0;
  capacity = 0;
 }
}

代码示例来源:origin: real-logic/aeron

public void onClose()
{
  publicationImages.forEach(PublicationImage::free);
  networkPublications.forEach(NetworkPublication::free);
  ipcPublications.forEach(IpcPublication::free);
  ctx.close();
}

代码示例来源:origin: SonarSource/sonarqube

private static Map<String, String> getHeaders(HttpServletRequest request) {
 Map<String, String> headers = new HashMap<>();
 Collections.list(request.getHeaderNames()).forEach(header -> headers.put(header.toLowerCase(Locale.ENGLISH), request.getHeader(header)));
 return headers;
}

代码示例来源:origin: stackoverflow.com

public void timeForEachAnonymousClass(int reps){
  for (int i = 0; i < reps; i++) {
    list.forEach(new Consumer<TestObject>() {
      @Override
      public void accept(TestObject t) {
public void timeForEachLambda(int reps){
  for (int i = 0; i < reps; i++) {
    list.forEach(t -> t.result++);

代码示例来源:origin: SonarSource/sonarqube

public void executeRecorded() {
  ArrayList<Runnable> runnables = new ArrayList<>(runnableList);
  runnableList.clear();
  runnables.forEach(Runnable::run);
 }
}

代码示例来源:origin: jooby-project/jooby

/**
 * Read a svg file and return the svg element (original) and a new symbol element (created from
 * original).
 *
 * @param file Svg file.
 * @param id   ID to use.
 * @return Svg element (original) and a symbol element (converted).
 * @throws IOException If something goes wrong.
 */
private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException {
 Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first();
 Element symbol = new Element(Tag.valueOf("symbol"), "")
   .attr("id", id)
   .attr("viewBox", svg.attr("viewBox"));
 new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild);
 return new Tuple(svg, symbol);
}

代码示例来源:origin: eclipse-vertx/vert.x

new ArrayList<>(namedWorkerPools.values()).forEach(WorkerPool::close);

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public void onLocalJoin(DiscoveryEvent evt, DiscoCache discoCache) {
  assert ctx.localNodeId().equals(evt.eventNode().id());
  assert evt.type() == EVT_NODE_JOINED;
  if (isLocalNodeCoordinator()) {
    // First node start, method onGridDataReceived(DiscoveryDataBag.GridDiscoveryData) has not been called.
    ArrayList<ServiceInfo> staticServicesInfo = staticallyConfiguredServices(false);
    staticServicesInfo.forEach(desc -> registeredServices.put(desc.serviceId(), desc));
  }
  ServiceDeploymentActions depActions = null;
  if (!registeredServices.isEmpty()) {
    depActions = new ServiceDeploymentActions();
    depActions.servicesToDeploy(new HashMap<>(registeredServices));
  }
  depMgr.onLocalJoin(evt, discoCache, depActions);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private static void addLemmata(Tree tree) {
 tree.yield().forEach(l -> {
  CoreLabel w = (CoreLabel) l;
  if(w.lemma() == null) {
   w.setLemma(MORPH.lemma(w.word(), w.tag()));
  }
 });
}

代码示例来源:origin: org.apache.ant/ant

classpathAttribute.setName(ATTRIBUTE_CLASSPATH);
  Collections.list(attribute.getValues()).forEach(classpathAttribute::addValue);
} else {
  Attribute currentCp = getAttribute(ATTRIBUTE_CLASSPATH);
  if (currentCp != null) {
    Collections.list(currentCp.getValues()).forEach(classpathAttribute::addValue);

代码示例来源:origin: org.apache.ant/ant

private void executeLocal() {
  try {
    inetAddrs = new LinkedList<>();
    Collections.list(NetworkInterface.getNetworkInterfaces())
        .forEach(netInterface -> inetAddrs.addAll(Collections.list(netInterface.getInetAddresses())));
    selectAddresses();
    if (nameAddr != null && hasHostName(nameAddr)) {
      setDomainAndName(nameAddr.getCanonicalHostName());
    } else {
      setProperty(DOMAIN, DEF_DOMAIN);
      setProperty(NAME, DEF_LOCAL_NAME);
    }
    if (best4 != null) {
      setProperty(ADDR4, best4.getHostAddress());
    } else {
      setProperty(ADDR4, DEF_LOCAL_ADDR4);
    }
    if (best6 != null) {
      setProperty(ADDR6, best6.getHostAddress());
    } else {
      setProperty(ADDR6, DEF_LOCAL_ADDR6);
    }
  } catch (Exception e) {
    log("Error retrieving local host information", e, Project.MSG_WARN);
    setProperty(DOMAIN, DEF_DOMAIN);
    setProperty(NAME, DEF_LOCAL_NAME);
    setProperty(ADDR4, DEF_LOCAL_ADDR4);
    setProperty(ADDR6, DEF_LOCAL_ADDR6);
  }
}

代码示例来源:origin: org.apache.ant/ant

warnings.add(
  "Multiple Class-Path attributes are supported but violate the Jar specification and may not be correctly processed in all environments");
Collections.list(attribute.getValues()).forEach(classpathAttribute::addValue);

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Remove the specified shape from this group
 */
@Override
public boolean removeShape(XSLFShape xShape) {
  XmlObject obj = xShape.getXmlObject();
  CTGroupShape grpSp = (CTGroupShape)getXmlObject();
  getSheet().deregisterShapeId(xShape.getShapeId());
  if(obj instanceof CTShape){
    grpSp.getSpList().remove(obj);
  } else if (obj instanceof CTGroupShape){
    XSLFGroupShape gs = (XSLFGroupShape)xShape;
    new ArrayList<>(gs.getShapes()).forEach(gs::removeShape);
    grpSp.getGrpSpList().remove(obj);
  } else if (obj instanceof CTConnector){
    grpSp.getCxnSpList().remove(obj);
  } else if (obj instanceof CTGraphicalObjectFrame) {
    grpSp.getGraphicFrameList().remove(obj);
  } else if (obj instanceof CTPicture) {
    XSLFPictureShape ps = (XSLFPictureShape)xShape;
    XSLFSheet sh = getSheet();
    if (sh != null) {
      sh.removePictureRelation(ps);
    }
    grpSp.getPicList().remove(obj);
  } else {
    throw new IllegalArgumentException("Unsupported shape: " + xShape);
  }
  return _shapes.remove(xShape);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

} else if (obj instanceof CTGroupShape) {
  XSLFGroupShape gs = (XSLFGroupShape)xShape;
  new ArrayList<>(gs.getShapes()).forEach(gs::removeShape);
  spTree.getGrpSpList().remove(obj);
} else if (obj instanceof CTConnector) {

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testHttpClientMetricsQueueClose() throws Exception {
 server = vertx.createHttpServer();
 List<Runnable> requests = Collections.synchronizedList(new ArrayList<>());
 server.requestHandler(req -> {
  requests.add(() -> {
   vertx.runOnContext(v -> {
    req.connection().close();
   });
  });
 });
 CountDownLatch listenLatch = new CountDownLatch(1);
 server.listen(8080, "localhost", onSuccess(s -> { listenLatch.countDown(); }));
 awaitLatch(listenLatch);
 client = vertx.createHttpClient();
 FakeHttpClientMetrics metrics = FakeHttpClientMetrics.getMetrics(client);
 for (int i = 0;i < 5;i++) {
  client.getNow(8080, "localhost", "/somepath", resp -> {
  });
 }
 assertWaitUntil(() -> requests.size() == 5);
 EndpointMetric endpoint = metrics.endpoint("localhost:8080");
 assertEquals(5, endpoint.connectionCount.get());
 ArrayList<Runnable> copy = new ArrayList<>(requests);
 requests.clear();
 copy.forEach(Runnable::run);
 assertWaitUntil(() -> metrics.endpoints().isEmpty());
 assertEquals(0, endpoint.connectionCount.get());
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Get a description handler.
 * @param srcDir the source directory.
 * @return the handler.
 */
protected DescriptorHandler getWebsphereDescriptorHandler(final File srcDir) {
  DescriptorHandler handler =
    new DescriptorHandler(getTask(), srcDir) {
      @Override
      protected void processElement() {
      }
    };
  getConfig().dtdLocations.forEach(l -> handler.registerDTD(l.getPublicId(), l.getLocation()));
  return handler;
}

代码示例来源:origin: org.apache.ant/ant

/** {@inheritDoc}. */
@Override
protected DescriptorHandler getDescriptorHandler(File srcDir) {
  DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir);
  // register all the DTDs, both the ones that are known and
  // any supplied by the user
  handler.registerDTD(PUBLICID_EJB11, ejb11DTD);
  getConfig().dtdLocations.forEach(l -> handler.registerDTD(l.getPublicId(), l.getLocation()));
  return handler;
}

代码示例来源:origin: eclipse-vertx/vert.x

vertx.setTimer(300, v -> {
 assertEquals(maxRequests, requests.size());
 requests.forEach(r -> r.response().end());
});

代码示例来源:origin: eclipse-vertx/vert.x

ArrayList<Runnable> copy = new ArrayList<>(requests);
requests.clear();
copy.forEach(Runnable::run);
awaitLatch(responsesLatch);
assertWaitUntil(() -> requests.size() == 5);
copy = new ArrayList<>(requests);
requests.clear();
copy.forEach(Runnable::run);
assertWaitUntil(() -> requests.size() == 3);
assertEquals(Collections.singleton("localhost:8080"), metrics.endpoints());

代码示例来源:origin: org.apache.ant/ant

handler.registerDTD(PUBLICID_WEBLOGIC_EJB600, weblogicDTD);
getConfig().dtdLocations.forEach(l -> handler.registerDTD(l.getPublicId(), l.getLocation()));
return handler;

相关文章