List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, final Transformer transformer, final Collection outputCollection)
From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java
/** * Reads the current classpath and identifies all possible executables and * directories was can currently be executed (accessed). * // ww w . ja v a 2s. c om * @return the <code>List</code> of <code>Completions</code> referring * to the system path */ @SuppressWarnings("unchecked") public static final List getCurrentPathCompletions(final IShellDescriptor descriptor, String currentPathString) { Set currentPathCompletionSet = new HashSet(); File currentPath = getPath(descriptor, currentPathString); if (currentPath != null) { File[] completions = currentPath.listFiles(new ExecutableFileFilter(descriptor, true)); if (completions != null) { CollectionUtils.collect(Arrays.asList(completions), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object object) { File completionFile = (File) object; String completionFileName = completionFile.getName(); String completion; String description; String imagePath; if (completionFile.isDirectory()) { // completion = "cd " + new // CmdShellPathManager().preparePath(completionFileName) // + descriptor.getPathSeparator(); completion = "cd " + completionFileName + descriptor.getPathSeparator(); description = "cd " + completionFileName + " - Change to directory <" + completionFileName + "> (Current path)"; imagePath = "img/changeDirectory.gif"; } else { completion = completionFileName; description = completionFileName + " - Execute <" + completionFileName + "> (Current path)"; imagePath = "img/executable.gif"; } return ICompletion.Factory.newInstance(completion, description, imagePath); } }, currentPathCompletionSet); } } List currentPathCompletions = new ArrayList(currentPathCompletionSet); Collections.sort(currentPathCompletions, new CompletionComparator()); return currentPathCompletions; }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.coordinator.degreeCurricularPlanManagement.ReadCurrentCurriculumByCurricularCourseCode.java
private static InfoCurriculum createInfoCurriculum(InfoCurriculum infoCurriculum, List activeCurricularCourseScopes, List associatedExecutionCourses) { List scopes = new ArrayList(); CollectionUtils.collect(activeCurricularCourseScopes, new Transformer() { @Override/*from w w w .ja v a 2 s . c o m*/ public Object transform(Object arg0) { CurricularCourseScope curricularCourseScope = (CurricularCourseScope) arg0; return InfoCurricularCourseScope.newInfoFromDomain(curricularCourseScope); } }, scopes); infoCurriculum.getInfoCurricularCourse().setInfoScopes(scopes); List<InfoExecutionCourse> infoExecutionCourses = new ArrayList<InfoExecutionCourse>(); Iterator iterExecutionCourses = associatedExecutionCourses.iterator(); while (iterExecutionCourses.hasNext()) { ExecutionCourse executionCourse = (ExecutionCourse) iterExecutionCourses.next(); infoExecutionCourses.add(InfoExecutionCourse.newInfoFromDomain(executionCourse)); } infoCurriculum.getInfoCurricularCourse().setInfoAssociatedExecutionCourses(infoExecutionCourses); return infoCurriculum; }
private static InfoCurriculum createInfoCurriculum(Curriculum curriculum, List allCurricularCourseScopes, List allExecutionCourses) { InfoCurriculum infoCurriculum = InfoCurriculumWithInfoCurricularCourse.newInfoFromDomain(curriculum); List scopes = new ArrayList(); CollectionUtils.collect(allCurricularCourseScopes, new Transformer() { @Override/*from w ww .ja va2 s. co m*/ public Object transform(Object arg0) { CurricularCourseScope curricularCourseScope = (CurricularCourseScope) arg0; return InfoCurricularCourseScope.newInfoFromDomain(curricularCourseScope); } }, scopes); infoCurriculum.getInfoCurricularCourse().setInfoScopes(scopes); List<InfoExecutionCourse> infoExecutionCourses = new ArrayList<InfoExecutionCourse>(); Iterator iterExecutionCourses = allExecutionCourses.iterator(); while (iterExecutionCourses.hasNext()) { ExecutionCourse executionCourse = (ExecutionCourse) iterExecutionCourses.next(); infoExecutionCourses.add(InfoExecutionCourse.newInfoFromDomain(executionCourse)); } infoCurriculum.getInfoCurricularCourse().setInfoAssociatedExecutionCourses(infoExecutionCourses); return infoCurriculum; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.academicAdministration.executionCourseManagement.InsertExecutionCourseDispatchAction.java
@EntryPoint public ActionForward prepareInsertExecutionCourse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { List infoExecutionPeriods = null; infoExecutionPeriods = ReadExecutionPeriods.run(); if (infoExecutionPeriods != null && !infoExecutionPeriods.isEmpty()) { // exclude closed execution periods infoExecutionPeriods = (List) CollectionUtils.select(infoExecutionPeriods, new Predicate() { @Override// w w w . j a va 2 s .c o m public boolean evaluate(Object input) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) input; if (!infoExecutionPeriod.getState().equals(PeriodState.CLOSED)) { return true; } return false; } }); ComparatorChain comparator = new ComparatorChain(); comparator.addComparator(new BeanComparator("infoExecutionYear.year"), true); comparator.addComparator(new BeanComparator("name"), true); Collections.sort(infoExecutionPeriods, comparator); List<LabelValueBean> executionPeriodLabels = new ArrayList<LabelValueBean>(); CollectionUtils.collect(infoExecutionPeriods, new Transformer() { @Override public Object transform(Object arg0) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) arg0; LabelValueBean executionPeriod = new LabelValueBean( infoExecutionPeriod.getName() + " - " + infoExecutionPeriod.getInfoExecutionYear().getYear(), infoExecutionPeriod.getExternalId().toString()); return executionPeriod; } }, executionPeriodLabels); request.setAttribute(PresentationConstants.LIST_EXECUTION_PERIODS, executionPeriodLabels); List<LabelValueBean> entryPhases = new ArrayList<LabelValueBean>(); for (EntryPhase entryPhase : EntryPhase.values()) { LabelValueBean labelValueBean = new LabelValueBean(entryPhase.getLocalizedName(), entryPhase.getName()); entryPhases.add(labelValueBean); } request.setAttribute("entryPhases", entryPhases); } return mapping.findForward("insertExecutionCourse"); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.ChooseExecutionYearDispatchAction.java
private List transformIntoLabels(List executionYearList) { List executionYearsLabels = new ArrayList(); CollectionUtils.collect(executionYearList, new Transformer() { @Override//www . j a v a2s.co m public Object transform(Object input) { InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) input; LabelValueBean labelValueBean = new LabelValueBean( infoExecutionDegree.getInfoExecutionYear().getYear(), infoExecutionDegree.getExternalId().toString()); return labelValueBean; } }, executionYearsLabels); Collections.sort(executionYearsLabels, new BeanComparator("label")); Collections.reverse(executionYearsLabels); return executionYearsLabels; }
From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeCreateAction.java
private static void setCommandGroups(HttpServletRequest req) { List groups = MonitoringFactory.loadAllCommandGroups(); ArrayList lv = new ArrayList(); CollectionUtils.collect(groups, new CommandGroupToLVBean(), lv); Collections.sort(lv, LabelValueBean.CASE_INSENSITIVE_ORDER); req.setAttribute("commandGroups", lv); }
From source file:gov.nih.nci.caarray.web.fileupload.MonitoredMultiPartRequest.java
private <T> T[] transformFileItemsForField(String fieldName, T[] emptyArray, Transformer t) { List<FileItem> items = files.get(fieldName); if (items == null) { return null; }//from w w w . j av a 2 s . c om List<T> result = new ArrayList<T>(items.size()); CollectionUtils.collect(items, t, result); return result.toArray(emptyArray); }
From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeCreateAction.java
private ArrayList toLabelValue(CommandGroup group, List commands) { CommandToLVBean t = new CommandToLVBean(group.getGroupName()); ArrayList result = new ArrayList(); CollectionUtils.collect(commands, t, result); Collections.sort(result, LabelValueBean.CASE_INSENSITIVE_ORDER); return result; }
From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java
/** * Computes cascading completions based on the path prefix. This prefix may * either be relative or absolut/*w w w.j av a 2 s . com*/ * * @param descriptor * The underlaying <code>IShellDescriptor</code> * @param command * The command which predesesses the prefix * @param pathPrefix * The prefix of the path to compute the completions for * @param cascadedPath * The path to search with the prefix * @return a <code>Collection</code> of <code>ICompletion</code> */ private static Collection<ICompletion> computeCascadeCompletions(final IShellDescriptor descriptor, final String command, final String pathPrefix, final File cascadedPath) { Set<ICompletion> cascadingCompletionSet = new HashSet<ICompletion>(); if (cascadedPath != null && cascadedPath.exists()) { File[] completions = cascadedPath.listFiles(); if (completions != null) { shellLogger.debug("Inspecting [" + completions.length + "] entries in path [" + cascadedPath + "]"); CollectionUtils.collect(Arrays.asList(completions), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object object) { File completionFile = (File) object; StringBuffer cascadedPathCompletionBuffer = new StringBuffer(); cascadedPathCompletionBuffer.append( pathPrefix.substring(0, pathPrefix.lastIndexOf(descriptor.getPathSeparator()))); cascadedPathCompletionBuffer.append(descriptor.getPathSeparator()); cascadedPathCompletionBuffer.append(completionFile.getName()); String completion; String description; String imagePath; if (completionFile.isDirectory()) { completion = command + " " + cascadedPathCompletionBuffer + descriptor.getPathSeparator(); description = cascadedPathCompletionBuffer.toString() + " - Folder (Cascading completion)"; imagePath = "img/cascadingFolder.gif"; } else { completion = command + " " + cascadedPathCompletionBuffer; description = cascadedPathCompletionBuffer.toString() + " - File (Cascading completion)"; imagePath = "img/cascadingFile.gif"; } return ICompletion.Factory.newInstance(completion, description, imagePath); } }, cascadingCompletionSet); } } shellLogger.debug("Found [" + cascadingCompletionSet.size() + "] entries in path [" + cascadedPath + "]"); return cascadingCompletionSet; }
From source file:de.hybris.platform.solrfacetsearch.integration.FacetDrillDownTest.java
private void checkFacets(final SearchResult result) { final List<Facet> facets3 = result.getFacets(); assertFalse("Facets collection must not be empty", facets3.isEmpty()); assertTrue("Result not contain facet price", result.containsFacet("price")); final Facet facet = result.getFacet("price"); final List<String> facetValues = (List<String>) CollectionUtils.collect(facet.getFacetValues(), new BeanToPropertyValueTransformer("name"), new ArrayList<String>()); final IndexedProperty priceProperty = indexedType.getIndexedProperties().get("price"); assertNotNull("No such indexed property: 'price'", priceProperty); final List<ValueRange> priceRanges = IndexedProperties.getValueRanges(priceProperty, null); assertNotNull("No priceRanges found", priceRanges); assertFalse("Price ranges must not be empty", priceRanges.isEmpty()); final List<String> ranngeValues = (List<String>) CollectionUtils.collect(priceRanges, new BeanToPropertyValueTransformer("name"), new ArrayList<String>()); final Iterator<String> facetValueItr = facetValues.iterator(); final Iterator<String> rangeValueItr = ranngeValues.iterator(); while (rangeValueItr.hasNext()) { final String rangeValue = rangeValueItr.next(); if (facetValues.contains(rangeValue)) { assertTrue("No more facet values", facetValueItr.hasNext()); final String facetValue = facetValueItr.next(); assertEquals("Facet value", rangeValue, facetValue); }/*from w ww . jav a 2s . c o m*/ } assertTrue("Result not contain facet manufacturerName", result.containsFacet("manufacturerName")); //assertTrue("Result not contain facet processor", result.containsFacet("processor")); assertTrue("Result not contain facet categoryName", result.containsFacet("categoryName")); }