List of usage examples for org.apache.commons.collections Transformer Transformer
Transformer
From source file:edu.buffalo.fusim.FusionGene.java
private void setIds() { this.geneId = StringUtils.join(CollectionUtils.collect(this.genes, new Transformer() { public Object transform(Object g) { return ((TranscriptRecord) g).getGeneId(); }//from w w w .j a v a2s.co m }), "-"); this.transcriptId = StringUtils.join(CollectionUtils.collect(this.genes, new Transformer() { public Object transform(Object g) { return ((TranscriptRecord) g).getTranscriptId(); } }), "-"); }
From source file:com.redhat.rhn.frontend.servlets.test.PxtSessionDelegateImplTest.java
public final void testLoadPxtSessionWhenPxtSessionIdIsNotNull() { setUpLoadPxtSession();/*from w w w.j a va 2s .com*/ mockRequest.stubs().method("getCookies").will(returnValue(new Cookie[] { getPxtCookie() })); pxtSessionDelegate.setFindPxtSessionByIdCallback(new Transformer() { public Object transform(Object arg) { if (PXT_SESSION_ID.equals(arg)) { return getPxtSession(); } return null; } }); pxtSessionDelegate.loadPxtSession(getRequest()); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.teachersBody.ReadProfessorshipsAndResponsibilitiesByDepartmentAndExecutionPeriod.java
protected static List getDetailedProfessorships(List professorships, final List responsibleFors, final Integer teacherType) { List detailedProfessorshipList = (List) CollectionUtils.collect(professorships, new Transformer() { @Override//from www. j a va2s.c o m public Object transform(Object input) { Professorship professorship = (Professorship) input; InfoProfessorship infoProfessorShip = InfoProfessorship.newInfoFromDomain(professorship); List executionCourseCurricularCoursesList = getInfoCurricularCourses( professorship.getExecutionCourse()); DetailedProfessorship detailedProfessorship = new DetailedProfessorship(); Boolean isResponsible = Boolean.valueOf(professorship.getResponsibleFor()); if ((teacherType.intValue() == 1) && (!isResponsible.booleanValue())) { return null; } detailedProfessorship.setResponsibleFor(isResponsible); detailedProfessorship.setInfoProfessorship(infoProfessorShip); detailedProfessorship.setExecutionCourseCurricularCoursesList(executionCourseCurricularCoursesList); return detailedProfessorship; } private List getInfoCurricularCourses(ExecutionCourse executionCourse) { List infoCurricularCourses = (List) CollectionUtils .collect(executionCourse.getAssociatedCurricularCoursesSet(), new Transformer() { @Override public Object transform(Object input) { CurricularCourse curricularCourse = (CurricularCourse) input; InfoCurricularCourse infoCurricularCourse = InfoCurricularCourse .newInfoFromDomain(curricularCourse); return infoCurricularCourse; } }); return infoCurricularCourses; } }); return detailedProfessorshipList; }
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//from ww w . ja v a 2s . c om 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:gov.nih.nci.caarray.util.owlparser.SqlOntologyOwlParser.java
@SuppressWarnings(UNCHECKED) private void writeSqlLine(String toTable, String[] fromTables, String[] columns, String[] selectEntries, Map<String, String> whereEntries) throws ParseException { StringBuilder sqlLine = new StringBuilder("insert into ").append(toTable); sqlLine.append(" (").append(StringUtils.join(columns, ",")).append(")"); sqlLine.append(" select ").append(StringUtils.join(selectEntries, ", ")); sqlLine.append(" from ").append(StringUtils.join(fromTables, ", ")); sqlLine.append(" where "); sqlLine.append(/*from ww w . j a v a 2 s . com*/ StringUtils.join(CollectionUtils.transformedCollection(whereEntries.entrySet(), new Transformer() { public Object transform(Object o) { Map.Entry<String, String> whereEntry = (Map.Entry<String, String>) o; return new StringBuilder(whereEntry.getKey()).append(" = ").append(whereEntry.getValue()) .toString(); } }), " and ")); sqlLine.append(";\n"); try { sqlFileWriter.write(sqlLine.toString()); } catch (IOException e) { throw new ParseException(e); } }
From source file:edu.northwestern.bioinformatics.studycalendar.service.StudySiteService.java
@SuppressWarnings({ "unchecked" }) public List<List<StudySite>> refreshStudySitesForStudies(final List<Study> studies) { if (studies == null) { throw new IllegalArgumentException(STUDY_IS_NULL); }//from ww w.j av a 2 s. co m List<List<StudySite>> refreshed = new ArrayList<List<StudySite>>(); final Map<String, List<Site>> sites = buildProvidedSiteMap(); List<List<StudySite>> allProvided = studySiteConsumer.refreshSites(studies); for (int i = 0; i < studies.size(); i++) { final Study study = studies.get(i); List<StudySite> provided = allProvided.get(i); if (provided == null) { provided = EMPTY_LIST; } Collection<StudySite> qualifying = CollectionUtils.select(provided, new Predicate() { public boolean evaluate(Object o) { StudySite potential = (StudySite) o; // Verify Study Provider and StudySite Provider Are Equal if (study.getProvider() == null || !study.getProvider().equals(potential.getProvider())) { return false; } // Verify Site Provider and StudySite Provider Are Equal (And Site Exists) List<Site> providerSpecific = sites.get(potential.getProvider()); if (providerSpecific == null || !providerSpecific.contains(potential.getSite())) { return false; } // Verify new study site Site site = providerSpecific.get(providerSpecific.indexOf(potential.getSite())); if (StudySite.findStudySite(study, site) != null) { return false; } return true; } }); logger.debug("Found " + qualifying.size() + " new study sites from the provider."); for (StudySite u : qualifying) { logger.debug("- " + u); } // StudySites returned from provider are proxied by CGLIB. This causes problems when saving, // so we want to create a fresh StudySite instance. Also, we want to populate the site with a // valid Site from SiteService. Collection<StudySite> enhanced = CollectionUtils.collect(qualifying, new Transformer() { public Object transform(Object o) { StudySite s = (StudySite) o; List<Site> providerSpecific = sites.get(s.getProvider()); Site site = providerSpecific.get(providerSpecific.indexOf(s.getSite())); StudySite e = new StudySite(study, site); e.getStudy().addStudySite(e); e.getSite().addStudySite(e); e.setProvider(s.getProvider()); e.setLastRefresh(s.getLastRefresh()); return e; } }); for (StudySite s : enhanced) { studySiteDao.save(s); } refreshed.add(study.getStudySites()); } return refreshed; }
From source file:net.sf.wickedshell.facade.descriptor.ExtensionShellDescriptor.java
/** * Constructor for ExtensionShellDescriptor. * //from w w w . ja va 2s .co m * @param extension * The <code>IConfigurationElement</code> representing the * <code>IShellDescriptor</code> */ @SuppressWarnings("unchecked") public ExtensionShellDescriptor(IConfigurationElement configurationElement) { super(); shellName = configurationElement.getAttribute(SHELL_NAME_ATTRIBUTE); shellExecutable = configurationElement.getAttribute(EXECUTABLE_ATTRIBUTE); characterEncoding = configurationElement.getAttribute(CHARACTER_ENCODING_ATTRIBUTE); String lineFeed = configurationElement.getAttribute(LINE_FEED_ATTRIBUTE); StringBuffer buffer = new StringBuffer(); if (lineFeed.equals(DomainID.CR_LF_VALUE)) { buffer.append(SWT.CR); } buffer.append(SWT.LF); lineFeedString = buffer.toString(); pathDelimiter = configurationElement.getAttribute(PATH_DELIMITER_ATTRIBUTE).replace(BLANK_SUBSTITUTE, ' '); String pathSeparatorDefinition = configurationElement.getAttribute(PATH_SEPARATOR_ATTRIBUTE); if (pathSeparatorDefinition.equals(DomainID.SLASH_VALUE)) { pathSeparator = "/"; } else { pathSeparator = "\\"; } systemPathSeparator = configurationElement.getAttribute(SYSTEM_PATH_SEPARATOR_ATTRIBUTE); hasCustomRoot = Boolean.valueOf(configurationElement.getAttribute(HAS_CUSTOM_ROOT_ATTRIBUTE)) .booleanValue(); if (hasCustomRoot) { binariesDirectory = configurationElement.getAttribute(BINARIES_DIRECTORY_ATTRIBUTE); } else { binariesDirectory = new String(); } commandDelimiter = configurationElement.getAttribute(COMMAND_DELIMITER_ATTRIBUTE); isUILineFeedProvided = Boolean .valueOf(configurationElement.getAttribute(IS_UI_LINE_FEED_PROVIDED_ATTRIBUTE)).booleanValue(); isExecutedComandProvided = Boolean .valueOf(configurationElement.getAttribute(IS_EXECUTED_COMMAND_PROVIDED_ATTIBUTE)).booleanValue(); id = configurationElement.getAttribute(SHELL_ID_ATTRIBUTE); executableFiles = (IExecutableFile[]) CollectionUtils.collect( Arrays.asList(configurationElement.getChildren(EXECUTABLE_FILES_ATTRIBUTE)), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object object) { IConfigurationElement executableFileElement = (IConfigurationElement) object; String extension = executableFileElement.getAttribute(EXTENSION_ATTRIBUTE); String description = executableFileElement.getAttribute(DESCRIPTION_ATTRIBUTE); Boolean isBatchFile = Boolean .valueOf(executableFileElement.getAttribute(IS_BATCH_FILE_ATTRIBUTE)); return IExecutableFile.Factory.newInstance(description, extension, isBatchFile.booleanValue()); } }).toArray(new IExecutableFile[0]); supportingOperatingSystems = (String[]) CollectionUtils.collect( Arrays.asList(configurationElement.getChildren(SUPPORTING_OS_ATTRIBUTE)), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object object) { IConfigurationElement executableFileElement = (IConfigurationElement) object; return executableFileElement.getAttribute(OS_NAME_ATTRIBUTE); } }).toArray(new String[0]); externalShellInvoker = null; if (configurationElement.getAttribute(EXTERNAL_SHELL_INVOKER_ATTRIBUTE) != null) { try { externalShellInvoker = (IExternalShellInvoker) configurationElement .createExecutableExtension(EXTERNAL_SHELL_INVOKER_ATTRIBUTE); } catch (CoreException exception) { shellLogger.error(exception.getMessage(), exception); } } environmentalValueProvider = null; if (configurationElement.getAttribute(ENVIRONMENTAL_VALUE_PROVIDER_ATTRIBUTE) != null) { try { environmentalValueProvider = (IEnvironmentalValueProvider) configurationElement .createExecutableExtension(ENVIRONMENTAL_VALUE_PROVIDER_ATTRIBUTE); } catch (CoreException exception) { shellLogger.error(exception.getMessage(), exception); } } commandProvider = null; if (configurationElement.getAttribute(COMMAND_PROVIDER_ATTRIBUTE) != null) { try { commandProvider = (ICommandProvider) configurationElement .createExecutableExtension(COMMAND_PROVIDER_ATTRIBUTE); } catch (CoreException exception) { shellLogger.error(exception.getMessage(), exception); } } }
From source file:com.alkacon.opencms.survey.CmsFormReportingBean.java
/** * Returns a lazy initialized map that provides if the user can see the detail page or not * for each group used as a key in the Map.<p> * //from w w w . j a v a2 s.co m * @return a lazy initialized map */ public Map getShowDetail() { if (m_group == null) { m_group = LazyMap.decorate(new HashMap(), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object input) { String value = String.valueOf(input); if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) { return new Boolean(true); } try { CmsUser user = getCmsObject().getRequestContext().currentUser(); List list = getCmsObject().getGroupsOfUser(user.getName(), false); CmsGroup group; for (int i = 0; i < list.size(); i++) { group = (CmsGroup) list.get(i); if (group.getName().equals(value)) { return new Boolean(true); } } } catch (Exception e) { // NOOP } return new Boolean(false); } }); } return m_group; }
From source file:edu.northwestern.bioinformatics.studycalendar.dataproviders.coppa.CoppaStudySiteProvider.java
@SuppressWarnings("unchecked") private Set<String> collectStudyProtocolIdentifiers(gov.nih.nci.coppa.services.pa.StudySite[] raw) { if (raw == null || raw.length <= 0) { return Collections.EMPTY_SET; }//from w w w .j av a2 s . com return new HashSet(collect(Arrays.asList(raw), new Transformer() { public Object transform(Object o) { gov.nih.nci.coppa.services.pa.StudySite s = (gov.nih.nci.coppa.services.pa.StudySite) o; if (s != null && s.getStudyProtocolIdentifier() != null) { return s.getStudyProtocolIdentifier().getExtension(); } return null; } })); }
From source file:com.alkacon.opencms.survey.CmsFormWorkBean.java
/** * Returns a lazy initialized map that provides the answers with the count * for each field used as a key in the Map.<p> * /*from w w w.ja v a2 s . com*/ * @return a lazy initialized map */ public Map getAnswers() { if (m_answers == null) { m_answers = LazyMap.decorate(new HashMap(), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object input) { String value = String.valueOf(input); return getAnswersWithCount(value); } }); } return m_answers; }