Example usage for com.google.common.collect Iterables transform

List of usage examples for com.google.common.collect Iterables transform

Introduction

In this page you can find the example usage for com.google.common.collect Iterables transform.

Prototype

@CheckReturnValue
public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterable that applies function to each element of fromIterable .

Usage

From source file:pl.nort.dayoneevernote.convert.NotesConverter.java

@Override
public void run() {
    Set<Note> notes = fetcher.getNotes();

    Iterable<Note> filteredNotes = Iterables.filter(notes, filter);
    Iterable<Note> transformedNotes = Iterables.transform(filteredNotes, transformer);

    LOG.info("Matched " + Iterables.size(transformedNotes) + " of " + notes.size() + " notes");

    for (Pusher pusher : pushers) {
        if (!pusher.push(transformedNotes)) {
            LOG.error("Import of some notes failed!");
        }//from   w ww. j  av a2s  .co m
    }
}

From source file:com.facebook.buck.android.ReplaceManifestPlaceholdersStep.java

@VisibleForTesting
static String replacePlaceholders(String content, ImmutableMap<String, String> placeholders) {
    Iterable<String> escaped = Iterables.transform(placeholders.keySet(), Pattern::quote);

    Joiner joiner = Joiner.on("|");
    String patternString = Pattern.quote("${") + "(" + joiner.join(escaped) + ")" + Pattern.quote("}");
    Pattern pattern = Pattern.compile(patternString);
    Matcher matcher = pattern.matcher(content);

    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(sb, placeholders.get(matcher.group(1)));
    }//from   ww  w  .j a v  a  2 s  .  com
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:biz.ganttproject.impex.csv.XlsReaderImpl.java

private List<String> getCellValues(Row row) {
    return Lists.newArrayList(Iterables.transform(row, Cell::getStringCellValue));
}

From source file:org.apache.isis.core.unittestsupport.soap.SoapEndpointPublishingRule.java

public SoapEndpointPublishingRule(final List<Class<?>> endpointClasses) {
    this(Iterables.transform(endpointClasses, SoapEndpointSpec.asSoapEndpointSpec()));
}

From source file:com.flaptor.indextank.util.Union.java

@Override
public SkippableIterator<V> iterator() {
    return new AbstractSkippableIterator<V>() {
        private List<PeekingSkippableIterator<K>> iterators = Lists
                .newArrayList(Iterables.transform(cursors, Union.<K>peekingIteratorFunction()));
        /*/*from  w  w w .  j ava  2  s.c  om*/
         * SortedSet with all the heads (first elements) for all the iterators and the position in the iterators list of the
         * SkippableIterator the element is in.
         */
        private TreeSet<Head<K>> heads = new TreeSet<Head<K>>(new Comparator<Head<K>>() {
            @Override
            public int compare(Head<K> o1, Head<K> o2) {
                int compare = comp(o1.value, o2.value);
                if (compare != 0) {
                    return compare;
                } else {
                    return o1.position - o2.position;
                }
            }
        });

        private List<Head<K>> prebuiltHeads = Lists.newArrayListWithExpectedSize(iterators.size());
        {
            for (int i = 0; i < iterators.size(); i++) {
                prebuiltHeads.add(new Head<K>(i));
            }
        }

        private Head<K> getHead(int position, K value) {
            Head<K> head = prebuiltHeads.get(position);
            head.value = value;
            return head;
        }

        {
            /*
             *  Keep all the heads of all the iterators sorted.  
             */
            for (int i = 0; i < iterators.size(); i++) {
                PeekingSkippableIterator<K> it = iterators.get(i);
                if (it.hasNext()) {
                    heads.add(getHead(i, it.next()));
                }
            }

        }

        private List<K> ks = Lists.newArrayList();
        private BitSet nextsToDo = new BitSet();

        @Override
        protected V computeNext() {
            while (true) {
                int pos = 0;
                while (true) {
                    pos = nextsToDo.nextSetBit(pos);
                    if (pos < 0) {
                        break;
                    }
                    if (iterators.get(pos).hasNext()) {
                        heads.add(getHead(pos, iterators.get(pos).next()));
                    }
                    nextsToDo.clear(pos);
                    pos++;
                }

                Head<K> currentElement = heads.pollFirst();
                if (currentElement == null) {
                    return endOfData();
                }
                int position = currentElement.position;
                nextsToDo.set(position);

                // advance the iterator from which we took the last element
                PeekingSkippableIterator<K> peekingSkippableIterator = iterators.get(position);

                ks.clear();

                K currentK = currentElement.value;
                ks.add(currentK);

                // add all other heads while the key is the same
                while (heads.size() > 0 && comp(heads.first().value, currentK) == 0) {
                    Head<K> newElement = heads.pollFirst();
                    nextsToDo.set(newElement.position);

                    PeekingSkippableIterator<K> newElementIterator = iterators.get(newElement.position);
                    ks.add(newElement.value);
                }

                V v = transform(ks.get(0));
                if (shouldUse(v, ks)) {
                    return v;
                }
            }
        }

        @Override
        public void skipTo(int i) {
            for (SkippableIterator<K> it : iterators) {
                it.skipTo(i);
            }
        }
    };
}

From source file:org.vclipse.constraint.scoping.ConstraintScopeProvider.java

IScope scope_ShortVarDefinition_ref(ConstraintSource context, EReference ref) {
    return Scopes.scopeFor(Iterables.concat(Iterables.transform(context.getObjects(),
            new Function<ConstraintObject, Iterable<ShortVarDefinition>>() {
                public Iterable<ShortVarDefinition> apply(ConstraintObject constraintObject) {
                    return constraintObject.getShortVars();
                }/*ww  w  .j  ava 2s  . c om*/
            })));
}

From source file:com.davidbracewell.parsing.handlers.CommentHandler.java

@Override
public Expression parse(Parser parser, ParserToken token) throws ParseException {
    List<ParserToken> tokens = parser.tokenStream().consumeUntil(endOfLine);
    if (parser.tokenStream().lookAheadType(0) != null) {
        parser.tokenStream().consume(endOfLine);
    }//from   w  w  w . ja  v  a2s.c o m
    return new CommentExpression(token.type,
            token.text + Joiner.on("").join(Iterables.transform(tokens, new Function<ParserToken, String>() {
                @Nullable
                @Override
                public String apply(ParserToken input) {
                    return input == null ? null : input.text;
                }
            })));
}

From source file:org.vclipse.dependency.scoping.DependencyScopeProvider.java

IScope scope_Table_characteristics(org.vclipse.vcml.vcml.Table context, EReference ref) {
    VariantTable vt = context.getTable();
    return Scopes.scopeFor(
            Iterables.transform(vt.getArguments(), new Function<VariantTableArgument, Characteristic>() {
                public Characteristic apply(VariantTableArgument object) {
                    return object.getCharacteristic();
                }/*  w  ww.j  av a  2 s .  com*/
            }));
}

From source file:org.apache.druid.query.spec.MultipleSpecificSegmentSpec.java

@Override
public List<Interval> getIntervals() {
    if (intervals != null) {
        return intervals;
    }//from   ww w  .  j  ava  2 s  .  com

    intervals = JodaUtils
            .condenseIntervals(Iterables.transform(descriptors, new Function<SegmentDescriptor, Interval>() {
                @Override
                public Interval apply(SegmentDescriptor input) {
                    return input.getInterval();
                }
            }));

    return intervals;
}

From source file:org.openrdf.sail.lucene3.LuceneDocumentScore.java

@Override
public Iterable<String> getSnippets(final String field) {
    List<String> values = getDocument().getProperty(field);
    if (values == null) {
        return null;
    }//  www .  ja va2  s .  co m
    return Iterables.transform(values, new Function<String, String>() {

        @Override
        public String apply(String text) {
            return index.getSnippet(field, text, highlighter);
        }
    });
}