Example usage for org.apache.commons.collections.set ListOrderedSet add

List of usage examples for org.apache.commons.collections.set ListOrderedSet add

Introduction

In this page you can find the example usage for org.apache.commons.collections.set ListOrderedSet add.

Prototype

public boolean add(Object object) 

Source Link

Usage

From source file:com.nextep.designer.beng.services.BENGServices.java

/**
 * Retrieves the container (modules) on which depend the specified one. Used by the build engine
 * to determine dependent deliveries./* w ww  . j av a  2 s.  c o m*/
 * 
 * @param c the container for which the dependencies will be retrieved
 * @return the containers on which the specified container depend
 */
@SuppressWarnings("unchecked")
public static List<IVersionContainer> getContainerDependencies(IVersionContainer c) {
    ListOrderedSet dependencies = new ListOrderedSet();
    // Retrieving the reference map of our current container
    Map<IReference, IReferenceable> containerRefMap = VersionHelper.getVersionable(c).getReferenceMap();
    // We browse all versionable of our container
    for (IVersionable<?> v : c.getContents()) {
        // For each of them we retrieve the loose dependencies
        Collection<IReference> references = v.getReferenceDependencies();
        for (IReference r : references) {
            // If the remote dependency is not from our container we save it
            if (!containerRefMap.containsKey(r)) {
                IReferenceable instance = VersionHelper.getReferencedItem(r);
                if (instance instanceof IVersionable) {
                    final IVersionable<?> versionedDependency = (IVersionable<?>) instance;
                    if (!versionedDependency.getContainer().equals(c)) {
                        dependencies.add(versionedDependency.getContainer());
                    }

                }
            }
        }
    }
    return (List<IVersionContainer>) dependencies.asList();
}

From source file:com.nextep.designer.beng.services.impl.DeliveryService.java

@SuppressWarnings("unchecked")
@Override/*w  w w.j av  a  2s  .  c om*/
public List<IVersionInfo> buildDependencies(List<IVersionInfo> processed, IDeliveryModule module) {
    IVersionInfo moduleRelease = module.getTargetRelease();
    if (processed.contains(moduleRelease)) {
        return Collections.EMPTY_LIST;
    } else {
        processed.add(moduleRelease);
    }
    // FIXME transform the collection to IVersionable<IVersionContainer>
    // collection
    ListOrderedSet containers = new ListOrderedSet();
    // containers.addAll(getContainerDependencies(moduleContainer));
    for (IVersionInfo vc : module.getDependencies()) {
        containers.add(vc);
    }
    for (IVersionInfo c : new ArrayList<IVersionInfo>(containers)) {
        final IDeliveryModule depModule = loadDelivery(c);
        if (depModule != null) {
            containers.addAll(0, buildDependencies(processed, depModule));
        } else {
            throw new ErrorException(BengMessages.getString("missingDependentDelivery")); //$NON-NLS-1$
        }
    }
    // containers.add(moduleRelease);
    return containers.asList();
}

From source file:net.sourceforge.vulcan.core.support.ProjectImporterImpl.java

@Override
public void createProjectsForUrl(String startUrl, String username, String password, boolean createSubprojects,
        NameCollisionResolutionMode nameCollisionResolutionMode, String[] schedulerNames, Set<String> labels,
        ProjectImportStatusDto statusDto) throws ConfigException, StoreException, DuplicateNameException {
    final List<RepositoryAdaptorPlugin> repositoryPlugins = pluginManager
            .getPlugins(RepositoryAdaptorPlugin.class);
    final List<BuildToolPlugin> buildToolPlugins = pluginManager.getPlugins(BuildToolPlugin.class);

    final ListOrderedSet urls = new ListOrderedSet();
    urls.add(startUrl);

    final List<ProjectConfigDto> newProjects = new ArrayList<ProjectConfigDto>();
    final List<ProjectRepositoryConfigurator> repoConfigurators = new ArrayList<ProjectRepositoryConfigurator>();

    final List<String> existingProjectNames = new ArrayList<String>(stateManager.getProjectConfigNames());

    for (int i = 0; i < urls.size(); i++) {
        final String url = (String) urls.get(i);

        if (statusDto != null) {
            statusDto.setCurrentUrl(url);
            statusDto.setNumProjectsCreated(newProjects.size());
            statusDto.setNumRemainingModules(urls.size() - i);
        }//from   w  ww  .j a  v  a2 s  . c  o  m

        final ProjectConfigDto projectConfig = new ProjectConfigDto();
        projectConfig.setSchedulerNames(schedulerNames);

        final ProjectRepositoryConfigurator repoConfigurator = createRepositoryConfiguratorForUrl(
                repositoryPlugins, projectConfig, url, username, password);

        File buildSpecFile = null;
        final ProjectBuildConfigurator buildConfigurator;

        try {
            buildSpecFile = downloadBuildSpecFile(repoConfigurator);
            final Document xmlDocument = tryParse(buildSpecFile);
            buildConfigurator = createBuildToolConfigurator(buildToolPlugins, projectConfig, url, buildSpecFile,
                    xmlDocument);
        } finally {
            deleteIfPresent(buildSpecFile);
        }

        final boolean shouldCreate = configureProject(projectConfig, repoConfigurator, buildConfigurator, url,
                existingProjectNames, nameCollisionResolutionMode, createSubprojects, labels);

        if (createSubprojects) {
            final List<String> subprojectUrls = buildConfigurator.getSubprojectUrls();

            makeAbsolute(url, subprojectUrls);

            if (subprojectUrls != null) {
                urls.addAll(subprojectUrls);
            }
        }

        if (shouldCreate) {
            existingProjectNames.add(projectConfig.getName());

            newProjects.add(projectConfig);
            repoConfigurators.add(repoConfigurator);

            log.info("Configured project " + projectConfig.getName());
        } else {
            log.info("Skipping project " + projectConfig.getName());
        }
    }

    final Map<String, PluginConfigDto> pluginConfigs = new HashMap<String, PluginConfigDto>();

    for (int i = 0; i < newProjects.size(); i++) {
        final ProjectConfigDto projectConfig = newProjects.get(i);
        try {
            final String pluginId = projectConfig.getRepositoryAdaptorPluginId();
            PluginConfigDto pluginConfig = pluginConfigs.get(pluginId);

            if (pluginConfig == null) {
                pluginConfig = (PluginConfigDto) pluginManager.getPluginConfigInfo(pluginId).copy();
            }

            if (repoConfigurators.get(i).updateGlobalConfig(pluginConfig)) {
                pluginConfigs.put(pluginId, pluginConfig);
            }
        } catch (PluginNotConfigurableException ignore) {
        } catch (PluginNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    final ConfigUpdatesDto updates = new ConfigUpdatesDto();

    updates.setNewProjectConfigs(newProjects);

    if (!pluginConfigs.isEmpty()) {
        updates.setModifiedPluginConfigs(pluginConfigs);
    }

    try {
        stateManager.applyMultipleUpdates(updates);
    } catch (PluginNotFoundException e) {
        // Very unlikely...
        throw new RuntimeException(e);
    }

    log.info("Successfully imported project(s) for URL " + startUrl);
}

From source file:org.apache.ddlutils.platform.mysql.MySqlBuilder.java

/**
 * {@inheritDoc}/*ww  w .j a  va2s.  co  m*/
 */
protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable,
        Table targetTable, Map parameters, List changes) throws IOException {
    // in order to utilize the ALTER TABLE ADD COLUMN AFTER statement
    // we have to apply the add column changes in the correct order
    // thus we first gather all add column changes and then execute them
    ArrayList addColumnChanges = new ArrayList();

    for (Iterator changeIt = changes.iterator(); changeIt.hasNext();) {
        TableChange change = (TableChange) changeIt.next();

        if (change instanceof AddColumnChange) {
            addColumnChanges.add((AddColumnChange) change);
            changeIt.remove();
        }
    }
    for (Iterator changeIt = addColumnChanges.iterator(); changeIt.hasNext();) {
        AddColumnChange addColumnChange = (AddColumnChange) changeIt.next();

        processChange(currentModel, desiredModel, addColumnChange);
        changeIt.remove();
    }

    ListOrderedSet changedColumns = new ListOrderedSet();

    // we don't have to care about the order because the comparator will have ensured
    // that a add primary key change comes after all necessary columns are present
    for (Iterator changeIt = changes.iterator(); changeIt.hasNext();) {
        TableChange change = (TableChange) changeIt.next();

        if (change instanceof RemoveColumnChange) {
            processChange(currentModel, desiredModel, (RemoveColumnChange) change);
            changeIt.remove();
        } else if (change instanceof AddPrimaryKeyChange) {
            processChange(currentModel, desiredModel, (AddPrimaryKeyChange) change);
            changeIt.remove();
        } else if (change instanceof PrimaryKeyChange) {
            processChange(currentModel, desiredModel, (PrimaryKeyChange) change);
            changeIt.remove();
        } else if (change instanceof RemovePrimaryKeyChange) {
            processChange(currentModel, desiredModel, (RemovePrimaryKeyChange) change);
            changeIt.remove();
        } else if (change instanceof ColumnChange) {
            // we gather all changed columns because we can use the ALTER TABLE MODIFY COLUMN
            // statement for them
            changedColumns.add(((ColumnChange) change).getChangedColumn());
            changeIt.remove();
        }
    }
    for (Iterator columnIt = changedColumns.iterator(); columnIt.hasNext();) {
        Column sourceColumn = (Column) columnIt.next();
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                getPlatform().isDelimitedIdentifierModeOn());

        processColumnChange(sourceTable, targetTable, sourceColumn, targetColumn);
    }
}

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * Determines the columns that are present in the given result set.
 * //from   w  w  w .ja  v a 2s . c o m
 * @param resultSet The result set
 * @return The columns
 */
private Set getColumnsInResultSet(ResultSet resultSet) throws SQLException {
    ListOrderedSet result = new ListOrderedSet();
    ResultSetMetaData metaData = resultSet.getMetaData();

    for (int idx = 1; idx <= metaData.getColumnCount(); idx++) {
        result.add(metaData.getColumnName(idx).toUpperCase());
    }

    return result;
}

From source file:org.dentaku.services.metadata.validator.ValidatingVisitorBase.java

private ListOrderedSet getVisitMethodsForClass(Class c) {
    ListOrderedSet result = (ListOrderedSet) superclassCache.get(c);
    if (result == null) {
        result = new ListOrderedSet();
        superclassCache.put(c, result);//from  w ww. ja  v a 2s . co  m
        Class current = c;
        while (current != null) {
            Class interfaces[] = current.getInterfaces();
            try {
                Method method = getClass().getMethod("visit", new Class[] { current, Object.class });
                if (!methodFilter.contains(method)) {
                    result.add(method);
                }
            } catch (NoSuchMethodException e) {
                // do nothing and loop
            }

            for (int i = 0; i < interfaces.length; i++) {
                Class thisInterface = interfaces[i];
                result.addAll(getVisitMethodsForClass(thisInterface));
            }

            current = current.getSuperclass();
        }
    }
    return result;
}

From source file:org.openmrs.util.databasechange.ConceptValidatorChangeSet.java

/**
 * Retrieves the list of allowed locales from the database, sets the default locale, english and
 * the default locale will be added to the list allowed locales if not yet included
 *
 * @param connection The database connection
 * @return A list of allowed locales//w ww  .  ja va2  s.  co  m
 */
@SuppressWarnings("unchecked")
private List<Locale> getAllowedLocalesList(JdbcConnection connection) {
    Statement stmt = null;
    ListOrderedSet allowedLocales = new ListOrderedSet();

    try {
        //get the default locale
        stmt = connection.createStatement();
        ResultSet rs_defaultLocale = stmt
                .executeQuery("SELECT property_value FROM global_property WHERE property = '"
                        + OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE + "'");

        if (rs_defaultLocale.next()) {
            String defaultLocaleStr = rs_defaultLocale.getString("property_value");
            if (!StringUtils.isBlank(defaultLocaleStr) && defaultLocaleStr.length() > 1) {
                Locale defaultLocale_GP = LocaleUtility.fromSpecification(defaultLocaleStr);
                if (defaultLocale_GP != null) {
                    defaultLocale = defaultLocale_GP;
                }
            } else {
                updateWarnings.add("'" + defaultLocaleStr
                        + "' is an invalid value for the global property default locale");
            }
        }

        allowedLocales.add(defaultLocale);

        //get the locale.allowed.list
        ResultSet rs_allowedLocales = stmt
                .executeQuery("SELECT property_value FROM global_property WHERE property = '"
                        + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST + "'");

        if (rs_allowedLocales.next()) {
            String allowedLocaleStr = rs_allowedLocales.getString("property_value");
            if (!StringUtils.isBlank(allowedLocaleStr)) {
                String[] localesArray = allowedLocaleStr.split(",");
                for (String localeStr : localesArray) {
                    if (localeStr.trim().length() > 1) {
                        allowedLocales.add(LocaleUtility.fromSpecification(localeStr.trim()));
                    } else {
                        updateWarnings.add("'" + localeStr
                                + "' is an invalid value for the global property locale.allowed.list");
                    }
                }
            }
        } else {
            log.warn("The global property '" + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST
                    + "' isn't set");
        }
    } catch (DatabaseException e) {
        log.warn("Error generated", e);
    } catch (SQLException e) {
        log.warn("Error generated", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                log.warn("Failed to close the statement object");
            }
        }
    }

    //if it isn't among
    allowedLocales.add(new Locale("en"));

    return allowedLocales.asList();
}