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

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

Introduction

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

Prototype

@CheckReturnValue
public static <F, T> List<T> transform(List<F> fromList, Function<? super F, ? extends T> function) 

Source Link

Document

Returns a list that applies function to each element of fromList .

Usage

From source file:de.tuberlin.uebb.jdae.hlmsl.specials.ConstantLinear.java

@Override
public GlobalEquation bind(Map<Unknown, GlobalVariable> ctxt) {
    return new LinearGlobalEquation(timeCoefficient, constant, coefficients,
            Lists.transform(variables, Functions.forMap(ctxt)));
}

From source file:org.opendaylight.bgpcep.pcep.topology.provider.OperationResults.java

public static OperationResults createUnsent(final PCEPErrors error) {
    final List<Errors> e = error != null ? Collections.singletonList(getErrorFor(error))
            : Collections.<Errors>emptyList();
    return new OperationResults(FailureType.Unsent, Lists.transform(e, CONVERT_ERRORS));
}

From source file:org.jboss.pressgang.ccms.util.WebElementUtil.java

public static List<TableRow> getTableRows(WebDriver driver, final WebElement table) {
    return waitForTenSeconds(driver).until(new Function<WebDriver, List<TableRow>>() {
        @Override// w w  w .ja  va2 s  .c  o  m
        public List<TableRow> apply(WebDriver webDriver) {

            List<WebElement> rows = table.findElements(By.xpath(".//tbody[1]/tr"));
            return ImmutableList.copyOf(Lists.transform(rows, WebElementTableRowFunction.FUNCTION));
        }
    });
}

From source file:com.feedzai.commons.sql.abstraction.engine.impl.MySqlTranslator.java

@Override
public String translate(AlterColumn ac) {
    final DbColumn column = ac.getColumn();
    final Expression table = ac.getTable();
    final Name name = new Name(column.getName());

    inject(table, name);/*from w  ww .  j ava 2 s  .c o  m*/

    StringBuilder sb = new StringBuilder("ALTER TABLE ").append(table.translate()).append(" MODIFY ")
            .append(name.translate()).append(" ").append(translate(column)).append(" ");

    List<Object> trans = Lists.transform(column.getColumnConstraints(),
            new com.google.common.base.Function<DbColumnConstraint, Object>() {
                @Override
                public Object apply(DbColumnConstraint input) {
                    return input.translate();
                }
            });

    sb.append(Joiner.on(" ").join(trans));

    return sb.toString();
}

From source file:org.asoem.greyfish.utils.concurrent.RecursiveActions.java

/**
 * Creates a {@code RecursiveAction} which applies a function {@code f} to all elements in the given {@code list}.
 * If the size of the list exceeds the given {@code size}, then the list will be split into partitions of that
 * {@code size} and {@code f} will be applied on them in parallel.
 *
 * @param list the elements on which the function will be applied
 * @param f    the function to apply/*w  w  w  .ja  v  a  2s .  com*/
 * @param size the desired size of each sublist (the last may be smaller)
 * @return a {@code RecursiveAction} which should be executed with a {@link ForkJoinPool}
 */
public static <T> RecursiveAction foreach(final List<T> list, final Function<? super T, Void> f,
        final int size) {
    checkNotNull(list);
    checkNotNull(f);

    if (list.isEmpty()) {
        return NULL_ACTION;
    } else {
        return new RecursiveAction() {
            @Override
            protected void compute() {
                checkState(inForkJoinPool(),
                        "This action is executed from outside of an ForkJoinPool which is forbidden");

                if (list.size() < size) {
                    applyFunction(list);
                } else {
                    invokeAll(partitionAndFork(list));
                }
            }

            private List<RecursiveAction> partitionAndFork(final List<T> list) {
                // copyOf is prevents deadlock!
                return ImmutableList.copyOf(
                        Lists.transform(Lists.partition(list, size), new Function<List<T>, RecursiveAction>() {
                            @Nullable
                            @Override
                            public RecursiveAction apply(@Nullable final List<T> input) {
                                return new RecursiveAction() {
                                    @Override
                                    protected void compute() {
                                        applyFunction(input);
                                    }
                                };
                            }
                        }));
            }

            private void applyFunction(final Iterable<T> elements) {
                for (final T element : elements) {
                    f.apply(element);
                }
            }
        };
    }
}

From source file:com.blacklocus.jres.response.search.JresSearchReply.java

/**
 * Shortcut to {@link Hit#getSourceAsType(TypeReference)}
 *///from  www  . j  a  v a  2 s. c  om
public <T> List<T> getHitsAsType(final TypeReference<T> typeReference) {
    return Lists.transform(getHits().getHits(), new Function<Hit, T>() {
        @Override
        public T apply(Hit hit) {
            return hit.getSourceAsType(typeReference);
        }
    });
}

From source file:org.apache.druid.emitter.graphite.GraphiteEmitterModule.java

@Provides
@ManageLifecycle/*from w  w w.  ja  va 2 s .  co m*/
@Named(EMITTER_TYPE)
public Emitter getEmitter(GraphiteEmitterConfig graphiteEmitterConfig, ObjectMapper mapper,
        final Injector injector) {
    List<Emitter> emitters = ImmutableList
            .copyOf(Lists.transform(graphiteEmitterConfig.getAlertEmitters(), alertEmitterName -> {
                return injector.getInstance(Key.get(Emitter.class, Names.named(alertEmitterName)));
            }));

    List<Emitter> requestLogEmitters = ImmutableList
            .copyOf(Lists.transform(graphiteEmitterConfig.getRequestLogEmitters(), requestLogEmitterName -> {
                return injector.getInstance(Key.get(Emitter.class, Names.named(requestLogEmitterName)));
            }));
    return new GraphiteEmitter(graphiteEmitterConfig, emitters, requestLogEmitters);
}

From source file:com.madgag.agit.filepath.CachingFilePathListMatcher.java

public CachingFilePathListMatcher(final List<FilePath> filePaths) {
    filteredPathsCache = new LruCache<String, List<FilePath>>(32) {
        @Override/*from  w  w w .  j  a  v  a  2 s  .  c  o  m*/
        protected List<FilePath> create(String key) {
            List<FilePath> searchSpace;
            if (key.length() > 1) {
                searchSpace = filteredPathsCache.get(key.substring(0, key.length() - 1));
            } else {
                searchSpace = filePaths;
            }

            return newArrayList(filter(searchSpace, new FilePathMatcher(key)));
        }
    };
    sortedPathsCache = new LruCache<String, List<FilePath>>(16) {
        @Override
        protected List<FilePath> create(String key) {
            Iterable<FilePath> filteredPaths = filteredPathsCache.get(key);

            return Lists.transform(ScoredPath.ORDERING.sortedCopy(transform(filteredPaths, scoreFor(key))),
                    ScoredPath.PATH);
        }
    };
}

From source file:com.feedzai.commons.sql.abstraction.engine.impl.H2Translator.java

@Override
public String translate(AlterColumn ac) {
    final DbColumn column = ac.getColumn();
    final Expression table = ac.getTable();
    final Name name = new Name(column.getName());

    inject(table, name);/* w w w .j av  a2 s .c  om*/

    StringBuilder sb = new StringBuilder("ALTER TABLE ").append(table.translate()).append(" ALTER COLUMN ")
            .append(name.translate()).append(" ").append(translate(column)).append(" ");

    List<Object> trans = Lists.transform(column.getColumnConstraints(),
            new com.google.common.base.Function<DbColumnConstraint, Object>() {
                @Override
                public Object apply(DbColumnConstraint input) {
                    return input.translate();
                }
            });

    sb.append(Joiner.on(" ").join(trans));

    return sb.toString();
}

From source file:org.eclipse.incquery.viewers.runtime.validators.ItemValidator.java

@Override
public void executeAdditionalValidation(Annotation annotation, IIssueCallback validator) {
    // Label validation is handled in parent class
    super.executeAdditionalValidation(annotation, validator);

    ValueReference hierarchyRef = CorePatternLanguageHelper.getFirstAnnotationParameter(annotation,
            "hierarchy");
    if (hierarchyRef instanceof StringValue) {
        String value = ((StringValue) hierarchyRef).getValue();

        final List<String> valueList = Lists.transform(Arrays.asList(HierarchyPolicy.values()),
                new Function<HierarchyPolicy, String>() {

                    @Override//w ww . j a  v a2s .  c o m
                    public String apply(HierarchyPolicy policy) {
                        return policy.name().toLowerCase();
                    }
                });

        if (!valueList.contains(value.toLowerCase())) {
            validator.error(
                    String.format("Invalid hierarchy literal %s. Possible values are %s.", value,
                            Iterables.toString(valueList)),
                    hierarchyRef, PatternLanguagePackage.Literals.STRING_VALUE__VALUE, HIERARCHY_LITERAL_ISSUE);
        }
    }
}