List of usage examples for org.apache.commons.collections CollectionUtils forAllDo
public static void forAllDo(Collection collection, Closure closure)
From source file:com.projity.functor.StringList.java
public static String list(Collection collection, Transformer transformer) { StringList l = getInstance(transformer); CollectionUtils.forAllDo(collection, l); return l.toString(); }
From source file:net.sf.wickedshell.domain.configuration.ShellDescriptorPropertiesDao.java
/** * Persist the <code>List</code> of * <code>IShellDescriptorProperties</code>. * /* w w w. j a v a 2 s .c om*/ * @param shellDescriptorProperties * the <code>List</code> of * <code>IShellDescriptorProperties</code> */ public void writeShellDescriptorProperties(List<IShellDescriptorProperties> shellDescriptorProperties) throws IOException { String stateLocation = DomainPlugin.getDefault().getStateLocation().toOSString(); File shelldescriptorConfigurationDocumentFile = new File(stateLocation, DomainID.SHELL_DESCRIPTOR_CONFIGURATION_FILE); if (!shelldescriptorConfigurationDocumentFile.exists()) { shelldescriptorConfigurationDocumentFile.delete(); } final ShellDescriptorConfigurationDocument shelldescriptorConfigurationDocument = ShellDescriptorConfigurationDocument.Factory .newInstance(); shelldescriptorConfigurationDocument.addNewShellDescriptorConfiguration(); CollectionUtils.forAllDo(shellDescriptorProperties, new Closure() { /** * @see org.apache.commons.collections.Closure#execute(java.lang.Object) */ public void execute(Object object) { IShellDescriptorProperties shellDescriptorProperties = (IShellDescriptorProperties) object; ShellDescriptorConfiguration shelldescriptorConfiguration = shelldescriptorConfigurationDocument .getShellDescriptorConfiguration(); ShellDescriptorProperties staticShellDescriptorProperties = shelldescriptorConfiguration .addNewShellDescriptorProperties(); staticShellDescriptorProperties .setShellDescriptorId(shellDescriptorProperties.getShellDescriptorId()); staticShellDescriptorProperties.setRootDirectory(shellDescriptorProperties.getRootDirectory()); staticShellDescriptorProperties .setIsOSDefault(String.valueOf(shellDescriptorProperties.isOSDefault())); } }); shelldescriptorConfigurationDocument.save(shelldescriptorConfigurationDocumentFile); }
From source file:com.hiperium.bo.control.impl.TaskBOImpl.java
/** * {@inheritDoc}//from ww w .j a v a2 s .c o m */ @Override public List<Task> updateRegisterState(@NotNull List<Task> list, boolean newState, @NotNull String sessionId) throws InformationException { this.log.debug("changeRegisterState - START"); if (list != null && !list.isEmpty()) { List<Task> actualList = new ArrayList<Task>(); for (Task task : list) { Task actual = super.getDaoFactory().getTaskDAO().findById(task.getId(), false, true); actualList.add(actual); } list.clear(); BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("active", newState); CollectionUtils.forAllDo(actualList, closure); for (Task task : actualList) { Task updated = super.getDaoFactory().getTaskDAO().update(task); Task basic = new Task(); BeanUtils.copyProperties(updated, basic); list.add(basic); } } this.log.debug("changeRegisterState - END"); return list; }
From source file:com.projity.functor.StringList.java
public static String list(Collection collection, String separator, Transformer transformer) { StringList l = getInstance(transformer); l.setSeparator(separator);// www. j av a 2 s. co m CollectionUtils.forAllDo(collection, l); return l.toString(); }
From source file:com.redhat.rhn.domain.monitoring.TemplateProbe.java
/** * {@inheritDoc}/* w w w.java 2 s. c o m*/ */ public void setCommandParameterValue(CommandParameter paramIn, String valueIn) { super.setCommandParameterValue(paramIn, valueIn); Closure c = ClosureUtils.invokerClosure("setCommandParameterValue", new Class[] { CommandParameter.class, String.class }, new Object[] { paramIn, valueIn }); CollectionUtils.forAllDo(getServerProbes(), c); }
From source file:hudson.plugins.locksandlatches.LockWrapper.java
@Override public Environment setUp(AbstractBuild abstractBuild, Launcher launcher, BuildListener buildListener) throws IOException, InterruptedException { final List<NamedReentrantLock> backups = new ArrayList<NamedReentrantLock>(); List<LockWaitConfig> locks = new ArrayList<LockWaitConfig>(this.locks); // sort this list of locks so that we _always_ ask for the locks in order Collections.sort(locks, new Comparator<LockWaitConfig>() { public int compare(LockWaitConfig o1, LockWaitConfig o2) { return o1.getName().compareTo(o2.getName()); }//from w w w .ja v a 2 s. c om }); // build the list of "real" locks final Map<String, Boolean> sharedLocks = new HashMap<String, Boolean>(); for (LockWaitConfig lock : locks) { NamedReentrantLock backupLock; do { backupLock = DESCRIPTOR.backupLocks.get(lock.getName()); if (backupLock == null) { DESCRIPTOR.backupLocks.putIfAbsent(lock.getName(), new NamedReentrantLock(lock.getName())); } } while (backupLock == null); backups.add(backupLock); sharedLocks.put(lock.getName(), lock.isShared()); } final StringBuilder locksToGet = new StringBuilder(); CollectionUtils.forAllDo(backups, new Closure() { public void execute(Object input) { locksToGet.append(((NamedReentrantLock) input).getName()).append(", "); } }); buildListener.getLogger() .println("[locks-and-latches] Locks to get: " + locksToGet.substring(0, locksToGet.length() - 2)); boolean haveAll = false; while (!haveAll) { haveAll = true; List<NamedReentrantLock> locked = new ArrayList<NamedReentrantLock>(); DESCRIPTOR.lockingLock.lock(); try { for (NamedReentrantLock lock : backups) { boolean shared = sharedLocks.get(lock.getName()); buildListener.getLogger().print("[locks-and-latches] Trying to get " + lock.getName() + " in " + (shared ? "shared" : "exclusive") + " mode... "); Lock actualLock; if (shared) { actualLock = lock.readLock(); } else { actualLock = lock.writeLock(); } if (actualLock.tryLock()) { buildListener.getLogger().println(" Success"); locked.add(lock); } else { buildListener.getLogger().println(" Failed, releasing all locks"); haveAll = false; break; } } if (!haveAll) { // release them all for (NamedReentrantLock lock : locked) { boolean shared = sharedLocks.get(lock.getName()); Lock actualLock; if (shared) { actualLock = lock.readLock(); } else { actualLock = lock.writeLock(); } actualLock.unlock(); } } } finally { DESCRIPTOR.lockingLock.unlock(); } if (!haveAll) { buildListener.getLogger() .println("[locks-and-latches] Could not get all the locks, sleeping for 1 minute..."); TimeUnit.SECONDS.sleep(60); } } buildListener.getLogger().println("[locks-and-latches] Have all the locks, build can start"); return new Environment() { @Override public boolean tearDown(AbstractBuild abstractBuild, BuildListener buildListener) throws IOException, InterruptedException { buildListener.getLogger().println("[locks-and-latches] Releasing all the locks"); for (NamedReentrantLock lock : backups) { boolean shared = sharedLocks.get(lock.getName()); Lock actualLock; if (shared) { actualLock = lock.readLock(); } else { actualLock = lock.writeLock(); } actualLock.unlock(); } buildListener.getLogger().println("[locks-and-latches] All the locks released"); return super.tearDown(abstractBuild, buildListener); } }; }
From source file:net.sf.wickedshell.domain.completion.CompletionDao.java
/** * Persist the <code>List</code> of <code>ICompletions</code>. * /*from ww w. j a v a2s . co m*/ * @param completions * The <code>List</code> of <code>ICompletions</code> * @param staticCompletionListDocumentFile * The <code>File</code> to use */ public void writeCompletions(List<ICompletion> completions, File staticCompletionListDocumentFile) throws IOException { if (!staticCompletionListDocumentFile.exists()) { staticCompletionListDocumentFile.delete(); } final StaticCompletionListDocument staticCompletionListDocument = StaticCompletionListDocument.Factory .newInstance(); staticCompletionListDocument.addNewStaticCompletionList(); CollectionUtils.forAllDo(completions, new Closure() { /** * @see org.apache.commons.collections.Closure#execute(java.lang.Object) */ public void execute(Object object) { ICompletion completion = (ICompletion) object; StaticCompletionList staticCompletionList = staticCompletionListDocument.getStaticCompletionList(); StaticCompletion staticCompletion = staticCompletionList.addNewStaticCompletion(); staticCompletion.setContent(completion.getContent()); staticCompletion.setLabel(completion.getLabel()); staticCompletion.setImagePath(completion.getImagePath()); } }); staticCompletionListDocument.save(staticCompletionListDocumentFile); }
From source file:com.hiperium.bo.security.impl.ProfileBOImpl.java
/** * {@inheritDoc}/*w w w . j a va 2 s.c o m*/ */ @Override public List<Profile> updateRegisterState(@NotNull List<Profile> list, boolean newState, @NotNull String sessionId) throws InformationException { this.log.debug("updateRegisterState - START"); List<Profile> updatedList = new ArrayList<Profile>(); if (list != null && !list.isEmpty()) { // TODO: VALIDATE THAT DO NOT INACTIVATE ADMINISTRATOR PROFILE BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("state", newState); CollectionUtils.forAllDo(list, closure); for (Profile profile : list) { Profile updated = super.getDaoFactory().getProfileDAO().update(profile); updatedList.add(updated); } } this.log.debug("updateRegisterState - END"); return updatedList; }
From source file:com.projity.functor.StringList.java
/** * Utility function to dump out a collection on separate lines * @param collection// w ww . j a va 2 s . c o m * @return */ public static String rows(java.util.Collection collection) { StringList l = getInstance(); l.setSeparator("\n"); CollectionUtils.forAllDo(collection, l); return l.toString(); }
From source file:com.projity.pm.graphic.gantt.GanttPopupMenu.java
/** * Because the styles may change, rebuild the menu each time * *///w w w . ja v a 2 s . com protected void init() { removeAll(); add(new SplitModeMenuAction()); add(new AssignmentsMenuAction()); final JMenu bars = new JMenu(Messages.getString("Gantt.Popup.barStylesMenu")); final JMenu annotations = new JMenu(Messages.getString("Gantt.Popup.annotationStylesMenu")); CollectionUtils.forAllDo(interactor.getGraph().getBarStyles().getRows(), new Closure() { public void execute(Object arg0) { BarStyle barStyle = (BarStyle) arg0; BarMenuAction menuAction = new BarMenuAction(barStyle); if (barStyle.isLink()) // move the show links item to the main menu add(menuAction); else if (barStyle.isCalendar()) // move the show links item to the main menu add(menuAction); else if (barStyle.isHorizontalGrid()) // move the show links item to the main menu add(menuAction); else if (barStyle.isAnnotation()) annotations.add(menuAction); else bars.add(menuAction); } }); add(bars); add(annotations); }