List of usage examples for org.apache.commons.collections Transformer Transformer
Transformer
From source file:com.alkacon.opencms.photoalbum.CmsPhotoAlbumBean.java
/** * Returns a lazy initialized map that checks if downscaling is required * for the given resource used as a key in the Map.<p> * //from w w w .j a va2s .co m * @return a lazy initialized map */ public Map getIsDownscaleRequired() { if (m_downscaleRequired == null) { m_downscaleRequired = LazyMap.decorate(new HashMap(), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object input) { Boolean result = Boolean.FALSE; if (m_imageScaler == null) { return result; } CmsImageScaler scaler = new CmsImageScaler(getCmsObject(), (CmsResource) input); if (scaler.isDownScaleRequired(m_imageScaler)) { return Boolean.TRUE; } return result; } }); } return m_downscaleRequired; }
From source file:com.brightcove.zartan.common.catalog.TagSet.java
/** * If <tt>obj</tt> is a <tt>String</tt>, converts it to lower case. If * <tt>obj</tt> is a <tt>Collection</tt>, recursively calls * <tt>normalize</tt> on each of its elements. * @param obj the <tt>Object</tt> on which to perform text normalization. * @return the normalized input Object.// www. jav a 2 s . c o m */ public Object normalize(Object obj) { if (obj instanceof String) { obj = normalize((String) obj); } else if (obj instanceof Collection<?>) { Collection<?> collection = (Collection<?>) (obj); // convert all strings in the collection to lower case CollectionUtils.transform(collection, new Transformer() { public Object transform(Object input) { if (input instanceof Collection<?>) { for (Object element : ((Collection<?>) input)) { return transform(element); } // should be unreachable, but compiler error without it return null; } else if (input instanceof String) { return normalize((String) input); } else { System.out.println("Found an element that's not an " + "instance of String"); return input; } } }); } return obj; }
From source file:com.alkacon.opencms.v8.photoalbum.CmsPhotoAlbumBean.java
/** * Returns a lazy initialized map that checks if downscaling is required * for the given resource used as a key in the Map.<p> * // w ww. j a v a2s. co m * @return a lazy initialized map */ @SuppressWarnings("unchecked") public Map<CmsResource, Boolean> getIsDownscaleRequired() { if (m_downscaleRequired == null) { m_downscaleRequired = LazyMap.decorate(new HashMap<CmsResource, Boolean>(), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object input) { Boolean result = Boolean.FALSE; if (m_imageScaler == null) { return result; } CmsImageScaler scaler = new CmsImageScaler(getCmsObject(), (CmsResource) input); if (scaler.isDownScaleRequired(m_imageScaler)) { return Boolean.TRUE; } return result; } }); } return m_downscaleRequired; }
From source file:com.michelin.cio.hudson.plugins.clearcaseucmbaseline.ClearCaseUcmBaselineParameterDefinitionTest.java
/** * This method is more about building an algorithm than testing the method * which uses it.//from w w w. j a va 2s .c o m */ public void testGetBaselines() { List<String> expectedBaselines = new ArrayList<String>() { { add("xyz_v2.4.0_20051205"); add("xyz_v2.3.1_20050531"); add("xyz_v2.3.0_20050309"); add("xyz_v2.2.3_20050503"); add("xyz_v2.2.2_20041025"); add("xyz_v2.2.1_20040806"); add("xyz_v2.2.0_20040503"); add("xyz_v2.1.2_20040607"); add("xyz_v2.1.1_20040211"); add("xyz_v2.1.0_20031016"); add("xyz_v2.0.2_20040113"); add("xyz_v2.0.1_20030929"); add("xyz_v2.0.0_20030626"); add("xyz_v2.x_init"); add("xyz_INITIAL"); } }; String cleartoolOutput = "20051124.145458 xyz_INITIAL\n" + "20051124.163732 xyz_v2.x_init\n" + "20051128.085745 xyz_v2.0.0_20030626\n" + "20051128.135749 xyz_v2.0.1_20030929\n" + "20051128.140834 xyz_v2.0.2_20040113\n" + "20051128.175618 xyz_v2.1.1_20040211\n" + "20051128.160803 xyz_v2.1.0_20031016\n" + "20051129.094900 xyz_v2.1.2_20040607\n" + "20051129.115212 xyz_v2.2.0_20040503\n" + "20051129.141546 xyz_v2.2.1_20040806\n" + "20051129.143813 xyz_v2.2.2_20041025\n" + "20051129.145120 xyz_v2.2.3_20050503\n" + "20051130.110900 xyz_v2.3.1_20050531\n" + "20051130.091037 xyz_v2.3.0_20050309\n" + "20060228.152608 xyz_v2.4.0_20051205\n"; List<String> baselines = Arrays.asList(cleartoolOutput.split("\n")); Collections.sort(baselines, new Comparator() { // reverse comparator so that we get the latest baselines first public int compare(Object o1, Object o2) { return -1 * ((String) o1).compareTo((String) o2); } }); baselines = (List<String>) CollectionUtils.collect(baselines, new Transformer() { public Object transform(Object input) { return ((String) input).substring(16); } }); if (expectedBaselines.size() != baselines.size()) { fail(); } for (int i = expectedBaselines.size() - 1; i >= 0; i--) { if (!expectedBaselines.get(i).equals(baselines.get(i))) { fail(); } } }
From source file:com.redhat.rhn.frontend.action.errata.EditAction.java
/** * This method acts as the default if the dispatch parameter is not in the map * It also represents the SetupAction/*from w w w. j a v a 2s . c o m*/ * @param mapping ActionMapping * @param formIn ActionForm * @param request HttpServletRequest * @param response HttpServletResponse * @return ActionForward, the forward for the jsp */ public ActionForward unspecified(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext requestContext = new RequestContext(request); Errata errata = requestContext.lookupErratum(); DynaActionForm form = (DynaActionForm) formIn; String keywordDisplay = StringUtil.join(LocalizationService.getInstance().getMessage("list delimiter"), IteratorUtils.getIterator(CollectionUtils.collect(errata.getKeywords(), new Transformer() { public Object transform(Object o) { return o.toString(); } }))); //pre-populate form with current values form.set("synopsis", errata.getSynopsis()); form.set("advisoryName", errata.getAdvisoryName()); form.set("advisoryRelease", errata.getAdvisoryRel().toString()); form.set("advisoryType", errata.getAdvisoryType()); form.set("advisoryTypeLabels", ErrataManager.advisoryTypeLabels()); form.set("product", errata.getProduct()); form.set("errataFrom", errata.getErrataFrom()); form.set("topic", errata.getTopic()); form.set("description", errata.getDescription()); form.set("solution", errata.getSolution()); form.set("refersTo", errata.getRefersTo()); form.set("notes", errata.getNotes()); form.set("keywords", keywordDisplay); return setupPage(request, mapping, errata); }
From source file:info.magnolia.cms.i18n.MessagesManager.java
/** * The lazzy LRU Map creates messages objects with a fault back to the default locale. *///from w ww .j a v a 2 s .co m private static void intiLRUMap() { // FIXME use LRU //Map map = new LRUMap(20); Map map = new HashMap(); map = LazyMap.decorate(map, new Transformer() { public Object transform(Object input) { MessagesID id = (MessagesID) input; Messages msgs = new DefaultMessagesImpl(id.basename, id.locale); return msgs; } }); messages = Collections.synchronizedMap(map); }
From source file:edu.harvard.med.screensaver.db.ScreenResultsDAOImpl.java
public Map<WellKey, ResultValue> findResultValuesByPlate(final Integer plateNumber, final DataColumn col) { List<ResultValue> result = runQuery(new edu.harvard.med.screensaver.db.Query() { public List<?> execute(Session session) { // NOTE: added fetch of the library into the session to fix lazy update problem when calling rv.isEdgeWell()->well.isEdgeWell() which needs the library see: [#1376]- sde4 String hql = "select r from ResultValue r " + "left join fetch r.well w join fetch w.library l " + "where r.dataColumn.id = :colId and w.id >= :firstWellInclusive " + "and w.id < :lastWellExclusive"; Query query = session.createQuery(hql); query.setParameter("colId", col.getEntityId()); query.setParameter("firstWellInclusive", new WellKey(plateNumber, 0, 0).toString()); query.setParameter("lastWellExclusive", new WellKey(plateNumber + 1, 0, 0).toString()); return query.list(); }//from w ww. ja v a2s. co m }); Map<WellKey, ResultValue> result2 = CollectionUtils.indexCollection(result, // note: calling rv.getWell().getWellId() does *not* require a db hit, since // a proxy can return its ID w/o forcing Hibernate to access the db; // so we use the id to instantiate the WellKey new Transformer() { public Object transform(Object rv) { return new WellKey(((ResultValue) rv).getWell().getWellId()); } }, WellKey.class, ResultValue.class); return result2; }
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). * //from www .j a v a2 s . co m * @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//w ww. ja va 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; }
From source file:com.zuora.api.object.Dynamic.java
/** * Answers the name and values of the both static and dynamic properties of this object * @return this object's properties, as string-object pairs */// w ww . j a va2 s. com private Collection<Entry<String, Object>> propertyValues() { try { return collect(Arrays.asList(Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors()), new Transformer() { public Object transform(Object input) { PropertyDescriptor p = (PropertyDescriptor) input; return new DefaultMapEntry(p.getName(), NaiveProperties.get(Dynamic.this, p.getName())); } }); } catch (Exception e) { throw MuleSoftException.soften(e); } }