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

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

Introduction

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

Prototype

public static Collection collect(Iterator inputIterator, Transformer transformer) 

Source Link

Document

Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection.

Usage

From source file:org.apache.carbondata.core.datamap.DataMapMeta.java

public List<String> getIndexedColumnNames() {
    return (List<String>) CollectionUtils.collect(indexedColumns, new Transformer() {
        @Override/*  ww  w .j a va2  s . c o  m*/
        public Object transform(Object input) {
            return ((CarbonColumn) input).getColName();
        }
    });
}

From source file:org.apache.cayenne.map.DbRelationship.java

/**
 * Returns a Collection of target attributes.
 * /*  w w w .jav a2 s  .  c  o  m*/
 * @since 1.1
 */
@SuppressWarnings("unchecked")
public Collection<DbAttribute> getTargetAttributes() {
    if (joins.size() == 0) {
        return Collections.emptyList();
    }

    return CollectionUtils.collect(joins, JoinTransformers.targetExtractor);
}

From source file:org.apache.cayenne.map.DbRelationship.java

/**
 * Returns a Collection of source attributes.
 * // w  ww .  ja v  a  2 s  .  c  om
 * @since 1.1
 */
@SuppressWarnings("unchecked")
public Collection<DbAttribute> getSourceAttributes() {
    if (joins.size() == 0) {
        return Collections.emptyList();
    }

    return CollectionUtils.collect(joins, JoinTransformers.sourceExtractor);
}

From source file:org.apache.cayenne.modeler.Application.java

/**
 * Reinitializes ModelerClassLoader from preferences.
 *///from w w w . ja  v a2 s.  c o  m
@SuppressWarnings("unchecked")
public void initClassLoader() {
    final FileClassLoadingService classLoader = new FileClassLoadingService();

    // init from preferences...
    Preferences classLoaderPreference = Application.getInstance().getPreferencesNode(ClasspathPreferences.class,
            "");

    Collection details = new ArrayList<>();
    String[] keys = null;
    ArrayList<String> values = new ArrayList<>();

    try {
        keys = classLoaderPreference.keys();
        for (String cpKey : keys) {
            values.add(classLoaderPreference.get(cpKey, ""));
        }
    } catch (BackingStoreException e) {
        // do nothing
    }

    for (int i = 0; i < values.size(); i++) {
        details.add(values.get(i));
    }

    if (details.size() > 0) {

        // transform preference to file...
        Transformer transformer = new Transformer() {

            public Object transform(Object object) {
                String pref = (String) object;
                return new File(pref);
            }
        };

        classLoader.setPathFiles(CollectionUtils.collect(details, transformer));
    }

    this.modelerClassLoader = classLoader;

    // set as EventDispatch thread default class loader
    if (SwingUtilities.isEventDispatchThread()) {
        Thread.currentThread().setContextClassLoader(classLoader.getClassLoader());
    } else {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                Thread.currentThread().setContextClassLoader(classLoader.getClassLoader());
            }
        });
    }
}

From source file:org.apache.cayenne.modeler.dialog.pref.DataSourcePreferences.java

/**
 * Tries to establish a DB connection, reporting the status of this
 * operation.//from   w w  w.jav a2s. co m
 */
public void testDataSourceAction() {
    DBConnectionInfo currentDataSource = getConnectionInfo();
    if (currentDataSource == null) {
        return;
    }

    if (currentDataSource.getJdbcDriver() == null) {
        JOptionPane.showMessageDialog(null, "No JDBC Driver specified", "Warning", JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (currentDataSource.getUrl() == null) {
        JOptionPane.showMessageDialog(null, "No Database URL specified", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    try {

        FileClassLoadingService classLoader = new FileClassLoadingService();

        List<File> oldPathFiles = ((FileClassLoadingService) getApplication().getClassLoadingService())
                .getPathFiles();

        Collection<String> details = new ArrayList<>();
        for (File oldPathFile : oldPathFiles) {
            details.add(oldPathFile.getAbsolutePath());
        }

        Preferences classPathPreferences = getApplication().getPreferencesNode(ClasspathPreferences.class, "");
        if (editor.getChangedPreferences().containsKey(classPathPreferences)) {
            Map<String, String> map = editor.getChangedPreferences().get(classPathPreferences);

            for (Map.Entry<String, String> en : map.entrySet()) {
                String key = en.getKey();
                if (!details.contains(key)) {
                    details.add(key);
                }
            }
        }

        if (editor.getRemovedPreferences().containsKey(classPathPreferences)) {
            Map<String, String> map = editor.getRemovedPreferences().get(classPathPreferences);

            for (Map.Entry<String, String> en : map.entrySet()) {
                String key = en.getKey();
                if (details.contains(key)) {
                    details.remove(key);
                }
            }
        }

        if (details.size() > 0) {

            // transform preference to file...
            Transformer transformer = new Transformer() {

                public Object transform(Object object) {
                    String pref = (String) object;
                    return new File(pref);
                }
            };

            classLoader.setPathFiles(CollectionUtils.collect(details, transformer));
        }

        Class<Driver> driverClass = classLoader.loadClass(Driver.class, currentDataSource.getJdbcDriver());
        Driver driver = driverClass.newInstance();

        // connect via Cayenne DriverDataSource - it addresses some driver
        // issues...
        // can't use try with resource here as we can loose meaningful exception
        Connection c = new DriverDataSource(driver, currentDataSource.getUrl(), currentDataSource.getUserName(),
                currentDataSource.getPassword()).getConnection();
        try {
            c.close();
        } catch (SQLException ignored) {
            // i guess we can ignore this...
        }

        JOptionPane.showMessageDialog(null, "Connected Successfully", "Success",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Throwable th) {
        th = Util.unwindException(th);
        String message = "Error connecting to DB: " + th.getLocalizedMessage();

        StringTokenizer st = new StringTokenizer(message);
        StringBuilder sbMessage = new StringBuilder();
        int len = 0;

        String tempString;
        while (st.hasMoreTokens()) {
            tempString = st.nextElement().toString();
            if (len < 110) {
                len = len + tempString.length() + 1;
            } else {
                sbMessage.append("\n");
                len = 0;
            }
            sbMessage.append(tempString).append(" ");
        }

        JOptionPane.showMessageDialog(null, sbMessage.toString(), "Warning", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:org.apache.isis.core.progmodel.facets.collections.collection.JavaCollectionFacet.java

@Override
@SuppressWarnings("unchecked")
public Collection<ObjectAdapter> collection(final ObjectAdapter wrappedCollection) {
    final Collection<?> collectionOfUnderlying = collectionOfUnderlying(wrappedCollection);
    return CollectionUtils.collect(collectionOfUnderlying, new ObjectToAdapterTransformer(getAdapterManager()));
}

From source file:org.apache.spark.streaming.JavaWriteAheadLogSuiteHandle.java

@Override
public java.util.Iterator<java.nio.ByteBuffer> readAll() {
    Collection<ByteBuffer> buffers = CollectionUtils.collect(records, new Transformer() {
        @Override/*from ww w  .  j a v a  2  s.co  m*/
        public Object transform(Object input) {
            return ((Record) input).buffer;
        }
    });
    return buffers.iterator();
}

From source file:org.archive.crawler.frontier.precedence.SuccessCountsQueuePrecedencePolicy.java

@SuppressWarnings("unchecked")
@Override/*from ww w . j av  a2s . co m*/
protected int calculatePrecedence(WorkQueue wq) {
    // FIXME: it's ridiculously inefficient to do this every time, 
    // and optimizing will probably require inserting stateful policy 
    // helper object into WorkQueue -- expected when URI-precedence is
    // also supported
    int precedence = getBasePrecedence() - 1;
    Collection<Integer> increments = CollectionUtils.collect(Arrays.asList(getIncrementCounts().split(",")),
            new Transformer() {
                public Object transform(final Object string) {
                    return Integer.parseInt((String) string);
                }
            });
    Iterator<Integer> iter = increments.iterator();
    int increment = iter.next();
    long successes = wq.getSubstats().getFetchSuccesses();
    while (successes >= 0) {
        successes -= increment;
        precedence++;
        increment = iter.hasNext() ? iter.next() : increment;
    }
    return precedence;
}

From source file:org.broadleafcommerce.common.util.BLCCollectionUtils.java

/**
 * Delegates to {@link CollectionUtils#collect(Collection, Transformer)}, but performs the necessary type coercion 
 * to allow the returned collection to be correctly casted based on the TypedTransformer.
 * /*from www.j  av  a  2s .  c  o  m*/
 * @param inputCollection
 * @param transformer
 * @return the typed, collected Collection
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> Collection<T> collect(Collection inputCollection, TypedTransformer<T> transformer) {
    return CollectionUtils.collect(inputCollection, transformer);
}

From source file:org.broadleafcommerce.core.catalog.domain.CategoryImpl.java

@Override
public List<CategorySearchFacet> getCumulativeSearchFacets() {
    List<CategorySearchFacet> returnCategoryFacets = new ArrayList<CategorySearchFacet>();
    returnCategoryFacets.addAll(getSearchFacets());
    Collections.sort(returnCategoryFacets, facetPositionComparator);

    final Collection<SearchFacet> facets = CollectionUtils.collect(returnCategoryFacets, new Transformer() {

        @Override//from   ww w .  jav  a2 s  .c  om
        public Object transform(Object input) {
            return ((CategorySearchFacet) input).getSearchFacet();
        }
    });

    // Add in parent facets unless they are excluded
    List<CategorySearchFacet> parentFacets = null;
    if (defaultParentCategory != null) {
        parentFacets = defaultParentCategory.getCumulativeSearchFacets();
        CollectionUtils.filter(parentFacets, new Predicate() {
            @Override
            public boolean evaluate(Object arg) {
                CategorySearchFacet csf = (CategorySearchFacet) arg;
                return !getExcludedSearchFacets().contains(csf.getSearchFacet())
                        && !facets.contains(csf.getSearchFacet());
            }
        });
    }
    if (parentFacets != null) {
        returnCategoryFacets.addAll(parentFacets);
    }

    return returnCategoryFacets;
}