Example usage for org.apache.commons.collections IteratorUtils transformedIterator

List of usage examples for org.apache.commons.collections IteratorUtils transformedIterator

Introduction

In this page you can find the example usage for org.apache.commons.collections IteratorUtils transformedIterator.

Prototype

public static Iterator transformedIterator(Iterator iterator, Transformer transform) 

Source Link

Document

Gets an iterator that transforms the elements of another iterator.

Usage

From source file:com.texeltek.accumulocloudbaseshim.FormatterShim.java

@Override
@SuppressWarnings("unchecked")
public void initialize(final Iterable<Map.Entry<Key, Value>> scanner, boolean printTimestamps) {
    impl.initialize(new Iterable<Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>>() {
        @Override/*w  w  w .j a  v  a2s  .c om*/
        public Iterator<Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>> iterator() {
            return IteratorUtils.transformedIterator(scanner.iterator(), new Transformer() {
                @Override
                public Map.Entry<cloudbase.core.data.Key, cloudbase.core.data.Value> transform(Object input) {
                    Map.Entry<Key, Value> entry = (Map.Entry<Key, Value>) input;
                    return new AbstractMap.SimpleEntry<cloudbase.core.data.Key, cloudbase.core.data.Value>(
                            entry.getKey().impl, entry.getValue().impl);
                }
            });
        }
    }, printTimestamps);
}

From source file:de.tudarmstadt.lt.nlkg.EvaluateArgs.java

static boolean predictEntailingContainedInNTopEntries(DT dt, String arg_l, String arg_r) {
    DT.Entry e = dt.get(arg_l, ntop);//from  w  ww  . j  av  a2s .  co  m
    @SuppressWarnings("unchecked")
    Iterator<String> string_iter = IteratorUtils.transformedIterator(e.dtwords, new Transformer() {
        @Override
        public Object transform(Object input) {
            return ((Word) input).word;
        }
    });

    Set<String> dtwords = new HashSet<String>(
            Arrays.asList((String[]) IteratorUtils.toArray(string_iter, String.class)));
    return dtwords.contains(arg_r);
}

From source file:info.magnolia.freemarker.models.ContentModel.java

@Override
public TemplateCollectionModel keys() throws TemplateModelException {
    final Iterator it = IteratorUtils.transformedIterator(content.getNodeDataCollection().iterator(),
            new Transformer() {
                @Override//from   w  w  w  . j av a2s  .  co m
                public Object transform(Object input) {
                    return ((NodeData) input).getName();
                }
            });
    return new SimpleCollection(it);
}

From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java

@Override
public Iterator<List<W>> getNgramIterator() {
    @SuppressWarnings("unchecked")
    Iterator<List<W>> iter = IteratorUtils.transformedIterator(getNgramIdIterator(), new Transformer() {
        @Override//from w w w  .  j  a v a  2 s  .  c o  m
        public Object transform(final Object o) {
            List<Integer> ngram = (List<Integer>) o;
            return toWordList(ngram);
        }
    });
    return iter;
}

From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java

@Override
public Iterator<List<Integer>> getNgramIdIterator() {
    @SuppressWarnings("unchecked")
    Iterator<List<Integer>> iter = IteratorUtils.transformedIterator(_ngrams_of_order.entrySet().iterator(),
            new Transformer() {
                @Override//from   w w  w .java  2 s .co  m
                public Object transform(final Object o) {
                    Entry<List<Integer>, Integer> ngram_counts = (Entry<List<Integer>, Integer>) o;
                    return ngram_counts.getKey();
                }
            });
    return iter;
}

From source file:io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider.java

@SuppressWarnings("unchecked")
private Iterator<Resource> getResourceInheritanceChainInternal(final String configName,
        final Iterator<String> paths, final ResourceResolver resourceResolver) {

    // find all matching items among all configured paths
    Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() {
        @Override/*from w ww.  j a  v  a2s .co  m*/
        public Object transform(Object input) {
            String configPath = buildResourcePath((String) input, configName);
            Resource resource = resourceResolver.getResource(configPath);
            if (resource != null) {
                log.trace("+ Found matching config resource for inheritance chain: {}", configPath);
            } else {
                log.trace("- No matching config resource for inheritance chain: {}", configPath);
            }
            return resource;
        }
    });
    Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources,
            PredicateUtils.notNullPredicate());
    if (result.hasNext()) {
        return result;
    } else {
        return null;
    }
}

From source file:io.wcm.caconfig.extensions.persistence.impl.ToolsConfigPagePersistenceStrategy.java

@SuppressWarnings("unchecked")
private Iterator<Resource> getResourceInheritanceChainInternal(final Collection<String> bucketNames,
        final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) {

    // find all matching items among all configured paths
    Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() {

        @Override//from   w  w  w  .j a va  2s  .  co m
        public Object transform(Object input) {
            String path = (String) input;
            for (String bucketName : bucketNames) {
                final String name = bucketName + "/" + configName;
                final String configPath = buildResourcePath(path, name);
                Resource resource = resourceResolver.getResource(configPath);
                if (resource != null) {
                    log.trace("+ Found matching config resource for inheritance chain: {}", configPath);
                    return resource;
                } else {
                    log.trace("- No matching config resource for inheritance chain: {}", configPath);
                }
            }
            return null;
        }
    });
    Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources,
            PredicateUtils.notNullPredicate());
    if (result.hasNext()) {
        return result;
    }
    return null;
}

From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w . j  a v a 2s. c  o m*/
public Iterator<List<Integer>> getNgramIdIterator() {
    return IteratorUtils.transformedIterator(getNgramIterator(), new Transformer() {
        @Override
        public Object transform(Object ngram) {
            return getNgramAsIds((List<String>) ngram);
        }
    });
}

From source file:io.wcm.caconfig.extensions.persistence.impl.ToolsConfigPagePersistenceStrategy.java

@SuppressWarnings("unchecked")
@Override// w  w  w . j  ava 2 s.c o  m
public Collection<Iterator<Resource>> getResourceCollectionInheritanceChain(
        @NotNull final Resource contentResource, @NotNull final Collection<String> bucketNames,
        @NotNull final String configName) {
    if (!isEnabledAndParamsValid(contentResource, bucketNames, configName)) {
        return null;
    }
    final ResourceResolver resourceResolver = contentResource.getResourceResolver();
    final List<String> paths = IteratorUtils.toList(findConfigRefs(contentResource, bucketNames));

    // get resource collection with respect to collection inheritance
    Collection<Resource> resourceCollection = getResourceCollectionInternal(bucketNames, configName,
            paths.iterator(), resourceResolver);

    // get inheritance chain for each item found
    // yes, this resolves the closest item twice, but is the easiest solution to combine both logic aspects
    Iterator<Iterator<Resource>> result = IteratorUtils.transformedIterator(resourceCollection.iterator(),
            new Transformer() {

                @Override
                public Object transform(Object input) {
                    Resource item = (Resource) input;
                    return getResourceInheritanceChainInternal(bucketNames, configName + "/" + item.getName(),
                            paths.iterator(), resourceResolver);
                }
            });
    if (result.hasNext()) {
        return IteratorUtils.toList(result);
    } else {
        return null;
    }
}

From source file:org.apache.accumulo.core.util.format.FormatterFactory.java

@SuppressWarnings("unchecked")
public static Formatter getDefaultFormatter(final Iterable<Entry<Key, Value>> scanner,
        boolean printTimestamps) {
    return new FormatterShim(cloudbase.core.util.format.FormatterFactory
            .getDefaultFormatter(new Iterable<Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>>() {
                @Override/*from   w ww  . j  a va2  s  .  c  o m*/
                public Iterator<Entry<cloudbase.core.data.Key, cloudbase.core.data.Value>> iterator() {
                    return IteratorUtils.transformedIterator(scanner.iterator(), new Transformer() {
                        @Override
                        public Entry<cloudbase.core.data.Key, cloudbase.core.data.Value> transform(
                                Object input) {
                            Entry<Key, Value> entry = (Entry<Key, Value>) input;
                            return new AbstractMap.SimpleEntry<cloudbase.core.data.Key, cloudbase.core.data.Value>(
                                    entry.getKey().impl, entry.getValue().impl);
                        }
                    });
                }
            }, printTimestamps));
}