org.apache.commons.collections.CollectionUtils.forAllDo()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(167)

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

CollectionUtils.forAllDo介绍

[英]Executes the given closure on each element in the collection.

If the input collection or closure is null, there is no change made.
[中]对集合中的每个元素执行给定的闭包。
如果输入集合或闭包为null,则不会进行任何更改。

代码示例

代码示例来源:origin: commons-collections/commons-collections

public void testForAllDo() {
  Closure testClosure = ClosureUtils.invokerClosure("clear");
  Collection col = new ArrayList();
  col.add(collectionA);
  col.add(collectionB);
  CollectionUtils.forAllDo(col, testClosure);
  assertTrue(collectionA.isEmpty() && collectionB.isEmpty());
  CollectionUtils.forAllDo(col, null);
  assertTrue(collectionA.isEmpty() && collectionB.isEmpty());
  CollectionUtils.forAllDo(null, testClosure);
  col.add(null);
  // null should be OK
  CollectionUtils.forAllDo(col, testClosure);
  col.add("x");
  // This will lead to FunctorException
  try {
    CollectionUtils.forAllDo(col, testClosure);
    fail("Expecting FunctorException");
  } catch (FunctorException ex) {
    // expected from invoker -- method not found
  }
}

代码示例来源:origin: mulesoft/mule

@Test
public void filteredStackIncludingNonMuleCode() {
 int calls = 5;
 try {
  generateStackEntries(calls, input -> forAllDo(singleton(null), input1 -> {
   throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo")));
  }));
  fail("Expected exception");
 } catch (Exception e) {
  assertThat(getExceptionStack(e),
        StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  org.apache.commons.collections.CollectionUtils.forAllDo\\(CollectionUtils.java:[0-9]+\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  \\(" + (calls + 16) + " more...\\)")); // recursive
 }
}

代码示例来源:origin: com.googlecode.jannocessor/jannocessor-collections

@SuppressWarnings("unchecked")
@Override
public PowerList<E> each(final Operation<? super E> operation) {
  CollectionUtils.forAllDo(this, new Closure() {
    public void execute(Object input) {
      operation.execute((E) input);
    }
  });
  return this;
}

代码示例来源:origin: com.googlecode.jannocessor/jannocessor-collections

public PowerSet<E> each(final Operation<? super E> operation) {
  CollectionUtils.forAllDo(this, new Closure() {
    @SuppressWarnings("unchecked")
    public void execute(Object input) {
      operation.execute((E) input);
    }
  });
  return this;
}

代码示例来源:origin: org.andromda.cartridges/andromda-spring-cartridge

/**
 * Retrieves all roles from the given <code>services</code> collection.
 *
 * @param services the collection services.
 * @return all roles from the collection.
 */
public Collection<Role> getAllRoles(Collection<Service> services)
{
  final Collection<Role> allRoles = new LinkedHashSet<Role>();
  CollectionUtils.forAllDo(
    services,
    new Closure()
    {
      public void execute(Object object)
      {
        if (object != null && Service.class.isAssignableFrom(object.getClass()))
        {
          allRoles.addAll(((Service)object).getAllRoles());
        }
      }
    });
  return allRoles;
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

private void doForSitemapFiles(Closure actOnFile) {
  File[] files = listFilesWithPrefix(new File(outputPath), filenamePrefix);
  CollectionUtils.forAllDo(Arrays.asList(files), actOnFile);
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

private Collection<ContributorInfo> contribInfos(YElement yElem) {
  final List<ContributorInfo> result = new ArrayList<>();
  CollectionUtils.forAllDo(yElem.getContributors(), new Closure() {
    @Override
    public void execute(Object input) {
      YContributor contrib = (YContributor) input;
      if (ArrayUtils.contains(ALLOWED_ROLES, contrib.getRole())) {
        result.add(contributorInfoBuilder.prepareContributorInfo(contrib));
      }
    }
  });
  return result;
}

代码示例来源:origin: org.mule.runtime/mule-core

public int size(QueueStore queue) {
 final AtomicInteger addSize = new AtomicInteger(0);
 CollectionUtils.forAllDo(this.transactionJournal.getLogEntriesForTx(xid), new Closure() {
  @Override
  public void execute(Object value) {
   if (((XaQueueTxJournalEntry) value).isAdd() || ((XaQueueTxJournalEntry) value).isAddFirst()) {
    addSize.incrementAndGet();
   }
  }
 });
 return queue.getSize() + addSize.get();
}

代码示例来源:origin: org.mule/mule-core

public int size(QueueStore queue)
{
  final AtomicInteger addSize = new AtomicInteger(0);
  CollectionUtils.forAllDo(this.transactionJournal.getLogEntriesForTx(xid), new Closure()
  {
    @Override
    public void execute(Object value)
    {
      if (((XaQueueTxJournalEntry)value).isAdd() ||  ((XaQueueTxJournalEntry)value).isAddFirst())
      {
        addSize.incrementAndGet();
      }
    }
  });
  return queue.getSize() + addSize.get();
}

代码示例来源:origin: net.sourceforge.wurfl/wng

public int getColumnIndex(TableCell cell) {
  
  Validate.isTrue(cells.contains(cell), "The given cell must be child of this row");
  final MutableInt column = new MutableInt();
  
  List previousCells = cells.subList(0, cells.indexOf(cell));
  CollectionUtils.forAllDo(previousCells, new Closure(){
    
    public void execute(Object input) {
      TableCell currentCell = (TableCell)input;
      column.add(currentCell.getColspan());
    }
  });
  
  return column.intValue();
}

代码示例来源:origin: net.sourceforge.wurfl/wng

public int getColumnIndex(TableColumn column) {
  
  Validate.isTrue(columns.contains(column), "The given cell must be child of this row");
  final MutableInt columnIndex = new MutableInt();
  
  List previousColumns = columns.subList(0, columns.indexOf(column));
  CollectionUtils.forAllDo(previousColumns, new Closure(){
    
    public void execute(Object input) {
      TableColumn currentColumn = (TableColumn)input;
      columnIndex.add(currentColumn.getColspan());
    }
  });
  
  return columnIndex.intValue();
}

代码示例来源:origin: org.andromda.bootstrap.metafacades/andromda-metafacades-emf-uml22

/**
 * @see org.andromda.metafacades.uml.Service#getAllEntityReferences()
 */
@Override
protected Collection<DependencyFacade> handleGetAllEntityReferences()
{
  final Collection<DependencyFacade> result = new LinkedHashSet<DependencyFacade>();
  // get references of the service itself
  result.addAll(this.getEntityReferences());
  // get references of all super classes
  CollectionUtils.forAllDo(this.getAllGeneralizations(), new Closure()
  {
    public void execute(final Object object)
    {
      if (object instanceof Service)
      {
        final Service service = (Service)object;
        result.addAll(service.getEntityReferences());
      }
    }
  });
  return result;
}

代码示例来源:origin: org.andromda.metafacades/andromda-metafacades-emf-uml22

/**
 * @see org.andromda.metafacades.uml.Service#getAllEntityReferences()
 */
@Override
protected Collection<DependencyFacade> handleGetAllEntityReferences()
{
  final Collection<DependencyFacade> result = new LinkedHashSet<DependencyFacade>();
  // get references of the service itself
  result.addAll(this.getEntityReferences());
  // get references of all super classes
  CollectionUtils.forAllDo(this.getAllGeneralizations(), new Closure()
  {
    public void execute(final Object object)
    {
      if (object instanceof Service)
      {
        final Service service = (Service)object;
        result.addAll(service.getEntityReferences());
      }
    }
  });
  return result;
}

代码示例来源:origin: org.andromda.bootstrap.metafacades/andromda-metafacades-emf-uml22

/**
 * @see org.andromda.metafacades.uml.Entity#getAllEntityReferences()
 */
@Override
protected Collection<DependencyFacade> handleGetAllEntityReferences()
{
  final Collection<DependencyFacade> result = new LinkedHashSet<DependencyFacade>();
  // get references of the service itself
  result.addAll(this.getEntityReferences());
  // get references of all super classes
  CollectionUtils.forAllDo(this.getAllGeneralizations(), new Closure()
  {
    public void execute(final Object object)
    {
      if (object instanceof Entity)
      {
        final Entity entity = (Entity)object;
        result.addAll(entity.getEntityReferences());
      }
    }
  });
  return result;
}

代码示例来源:origin: org.andromda.bootstrap.metafacades/andromda-metafacades-emf-uml22

/**
 * @see org.andromda.metafacades.uml.Service#getAllRoles()
 */
@Override
protected Collection<Role> handleGetAllRoles()
{
  final Collection<Role> roles = new LinkedHashSet<Role>(this.getRoles());
  CollectionUtils.forAllDo(
    this.getOperations(),
    new Closure()
    {
      public void execute(final Object object)
      {
        if (object instanceof ServiceOperation)
        {
          roles.addAll(((ServiceOperation)object).getRoles());
        }
      }
    });
  return roles;
}

代码示例来源:origin: org.apache.archiva/archiva-repository-scanner

@Override
public void directoryWalkFinished()
{
  TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, true );
  CollectionUtils.forAllDo( knownConsumers, scanCompletedClosure );
  CollectionUtils.forAllDo( invalidConsumers, scanCompletedClosure );
  stats.setConsumerTimings( consumerTimings );
  stats.setConsumerCounts( consumerCounts );
  log.info( "Walk Finished: [{}] {}", this.repository.getId(), this.repository.getLocation() );
  stats.triggerFinished();
}

代码示例来源:origin: net.sourceforge.wurfl/wng

private void applyDefaultStyle(Component component) {
  // Header
  if (component.getClass() == Header.class) {
    updateWidthCssProperty(component);
  } else if (component instanceof RackMenu) {
    updateWidthCssProperty(component);
  }
  // BannerRow
  else if (component.getClass() == BannerRow.class) {
    BannerRow item = (BannerRow) component;
    if (!item.getStyle().containsProperty("width")) {
      SumClosure sumClosure = new SumClosure("width");
      CollectionUtils.forAllDo(item.getChildren(), sumClosure);
      String widthInPixel = String.valueOf(sumClosure.getSumValue())
          + "px";
      item.getStyle().addProperty("width", widthInPixel);
    }
  }
}

代码示例来源:origin: org.apache.archiva/archiva-rest-services

@Override
public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
  throws ArchivaRestServiceException
{
  try
  {
    AddAdminRepoConsumerClosure addAdminRepoConsumer =
      new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
    CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
    List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
    Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
    return knownContentConsumers;
  }
  catch ( RepositoryAdminException e )
  {
    throw new ArchivaRestServiceException( e.getMessage(), e );
  }
}

代码示例来源:origin: org.apache.archiva/archiva-rest-services

@Override
  public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
    throws ArchivaRestServiceException
  {
    try
    {
      AddAdminRepoConsumerClosure addAdminRepoConsumer =
        new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
      CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
      List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
      Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
      return invalidContentConsumers;
    }
    catch ( RepositoryAdminException e )
    {
      throw new ArchivaRestServiceException( e.getMessage(), e );
    }
  }
}

代码示例来源:origin: org.mule.runtime/mule-core-tests

@Test
public void filteredStackIncludingNonMuleCode() {
 int calls = 5;
 try {
  generateStackEntries(calls, input -> forAllDo(singleton(null), input1 -> {
   throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo")));
  }));
  fail("Expected exception");
 } catch (Exception e) {
  assertThat(getExceptionStack(e),
        StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  org.apache.commons.collections.CollectionUtils.forAllDo\\(CollectionUtils.java:[0-9]+\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  " + ExceptionHelperTestCase.class.getName()
                             + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)",
                           "  \\(" + (calls + 16) + " more...\\)")); // recursive
 }
}

相关文章