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 } }
@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 } }
@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; }
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; }
/** * 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; }
private void doForSitemapFiles(Closure actOnFile) { File[] files = listFilesWithPrefix(new File(outputPath), filenamePrefix); CollectionUtils.forAllDo(Arrays.asList(files), actOnFile); }
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; }
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(); }
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(); }
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(); }
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(); }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
@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(); }
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); } } }
@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 ); } }
@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 ); } } }
@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 } }