Example usage for org.apache.commons.collections CollectionUtils transform

List of usage examples for org.apache.commons.collections CollectionUtils transform

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils transform.

Prototype

public static void transform(Collection collection, Transformer transformer) 

Source Link

Document

Transform the collection by applying a Transformer to each element.

Usage

From source file:org.andromda.timetracker.domain.TimecardDaoBase.java

/**
 * {@inheritDoc}/*from   www . ja  va2 s.  c om*/
 */
@Override
public final void timecardVOToEntityCollection(Collection<?> instances) {
    if (instances != null) {
        for (final Iterator<?> iterator = instances.iterator(); iterator.hasNext();) {
            // - remove an objects that are null or not of the correct instance
            if (!(iterator.next() instanceof TimecardVO)) {
                iterator.remove();
            }
        }
        CollectionUtils.transform(instances, this.TimecardVOToEntityTransformer);
    }
}

From source file:org.andromda.timetracker.domain.UserDaoBase.java

/**
 * {@inheritDoc}//from   w ww .j a  v a2s  . com
 */
@Override
@SuppressWarnings({ "unchecked" })
public final Collection<UserVO> toUserVOCollection(Collection<?> entities) {
    Collection<UserVO> result = new ArrayList<UserVO>();
    if (entities != null) {
        CollectionUtils.transform(entities, this.USERVO_TRANSFORMER);
        result.addAll((Collection<? extends UserVO>) entities);
    }
    return result;
}

From source file:org.andromda.timetracker.domain.UserDaoBase.java

/**
 * {@inheritDoc}/* www .  ja  v  a 2 s  . com*/
 */
@Override
public final void userVOToEntityCollection(Collection<?> instances) {
    if (instances != null) {
        for (final Iterator<?> iterator = instances.iterator(); iterator.hasNext();) {
            // - remove an objects that are null or not of the correct instance
            if (!(iterator.next() instanceof UserVO)) {
                iterator.remove();
            }
        }
        CollectionUtils.transform(instances, this.UserVOToEntityTransformer);
    }
}

From source file:org.andromda.timetracker.domain.UserDaoBase.java

/**
 * {@inheritDoc}/*from  w w  w.  j  a v  a 2s.  c o m*/
 */
@Override
@SuppressWarnings({ "unchecked" })
public final Collection<UserDetailsVO> toUserDetailsVOCollection(Collection<?> entities) {
    Collection<UserDetailsVO> result = new ArrayList<UserDetailsVO>();
    if (entities != null) {
        CollectionUtils.transform(entities, this.USERDETAILSVO_TRANSFORMER);
        result.addAll((Collection<? extends UserDetailsVO>) entities);
    }
    return result;
}

From source file:org.andromda.timetracker.domain.UserDaoBase.java

/**
 * {@inheritDoc}//w w  w .j a v  a2s .com
 */
@Override
public final void userDetailsVOToEntityCollection(Collection<?> instances) {
    if (instances != null) {
        for (final Iterator<?> iterator = instances.iterator(); iterator.hasNext();) {
            // - remove an objects that are null or not of the correct instance
            if (!(iterator.next() instanceof UserDetailsVO)) {
                iterator.remove();
            }
        }
        CollectionUtils.transform(instances, this.UserDetailsVOToEntityTransformer);
    }
}

From source file:org.andromda.timetracker.domain.UserRoleDaoBase.java

/**
 * {@inheritDoc}/*from   w ww  .  j a v  a 2s .  c o  m*/
 */
@Override
@SuppressWarnings({ "unchecked" })
public final Collection<UserRoleVO> toUserRoleVOCollection(Collection<?> entities) {
    Collection<UserRoleVO> result = new ArrayList<UserRoleVO>();
    if (entities != null) {
        CollectionUtils.transform(entities, this.USERROLEVO_TRANSFORMER);
        result.addAll((Collection<? extends UserRoleVO>) entities);
    }
    return result;
}

From source file:org.andromda.timetracker.domain.UserRoleDaoBase.java

/**
 * {@inheritDoc}//  w ww. j  ava2  s .co m
 */
@Override
public final void userRoleVOToEntityCollection(Collection<?> instances) {
    if (instances != null) {
        for (final Iterator<?> iterator = instances.iterator(); iterator.hasNext();) {
            // - remove an objects that are null or not of the correct instance
            if (!(iterator.next() instanceof UserRoleVO)) {
                iterator.remove();
            }
        }
        CollectionUtils.transform(instances, this.UserRoleVOToEntityTransformer);
    }
}

From source file:org.codice.ddf.admin.core.impl.AdminConsoleService.java

/**
 * @see AdminConsoleServiceMBean#updateForLocation(java.lang.String, java.lang.String,
 *     java.util.Map)/*ww  w.  ja  v  a2s.c  o  m*/
 */
public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable)
        throws IOException {
    if (pid == null || pid.length() < 1) {
        throw loggedException(ILLEGAL_PID_MESSAGE);
    }
    if (configurationTable == null) {
        throw loggedException(ILLEGAL_TABLE_MESSAGE);
    }

    final Configuration config = configurationAdmin.getConfiguration(pid, location);
    if (isPermittedToViewService(config.getPid())) {
        final Metatype metatype = configurationAdminImpl.findMetatypeForConfig(config);
        if (metatype == null) {
            throw loggedException("Could not find metatype for " + pid);
        }

        final List<Map.Entry<String, Object>> configEntries = new ArrayList<>();
        CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator());
        CollectionUtils.transform(configEntries,
                new CardinalityTransformer(metatype.getAttributeDefinitions(), pid));

        final Dictionary<String, Object> configProperties = config.getProperties();
        final Dictionary<String, Object> newConfigProperties = (configProperties != null) ? configProperties
                : new Hashtable<>();

        // If the configuration entry is a password, and its updated configuration value is
        // "password", do not update the password.
        for (Map.Entry<String, Object> configEntry : configEntries) {
            final String configEntryKey = configEntry.getKey();
            Object configEntryValue = sanitizeUIConfiguration(pid, configEntryKey, configEntry.getValue());
            if (configEntryValue.equals("password")) {
                for (Map<String, Object> metatypeProperties : metatype.getAttributeDefinitions()) {
                    if (metatypeProperties.get("id").equals(configEntry.getKey())
                            && AttributeDefinition.PASSWORD == (Integer) metatypeProperties.get("type")
                            && configProperties != null) {
                        configEntryValue = configProperties.get(configEntryKey);
                        break;
                    }
                }
            }
            newConfigProperties.put(configEntryKey, configEntryValue);
        }

        config.update(newConfigProperties);
    }
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

/**
 * @see ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String,
 * java.util.Map)/*  w w  w. ja  v  a  2 s . co m*/
 */
public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable)
        throws IOException {
    if (pid == null || pid.length() < 1) {
        throw loggedException("Argument pid cannot be null or empty");
    }
    if (configurationTable == null) {
        throw loggedException("Argument configurationTable cannot be null");
    }

    Configuration config = configurationAdmin.getConfiguration(pid, location);

    final List<Map<String, Object>> metatype = findMetatypeForConfig(config);
    List<Map.Entry<String, Object>> configEntries = new ArrayList<>();

    CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator());

    if (metatype == null) {
        throw loggedException("Could not find metatype for " + pid);
    }
    // now we have to filter each property based on its cardinality
    CollectionUtils.transform(configEntries, new CardinalityTransformer(metatype, pid));

    Dictionary<String, Object> configurationProperties = new Hashtable<>();
    for (Map.Entry<String, Object> configEntry : configEntries) {
        configurationProperties.put(configEntry.getKey(), configEntry.getValue());
    }
    config.update(configurationProperties);
}

From source file:org.fenixedu.academic.ui.faces.beans.coordinator.ListStudentThesis.java

private static List run(String degreeCurricularPlanID) throws FenixServiceException {

    DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID);

    List masterDegreeThesisDataVersions = MasterDegreeThesisDataVersion
            .readActiveMasterDegreeThesisDataVersions(degreeCurricularPlan);

    if (masterDegreeThesisDataVersions == null || masterDegreeThesisDataVersions.isEmpty()) {
        throw new NonExistingServiceException("error.exception.masterDegree.nonExistingMasterDegreeThesis");
    }/*www  . j  ava 2 s.c  om*/

    CollectionUtils.transform(masterDegreeThesisDataVersions, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            MasterDegreeThesisDataVersion masterDegreeThesisDataVersion = (MasterDegreeThesisDataVersion) arg0;
            return InfoMasterDegreeThesisDataVersionWithGuidersAndRespAndThesis
                    .newInfoFromDomain(masterDegreeThesisDataVersion);
        }
    });

    return masterDegreeThesisDataVersions;
}