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

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

Introduction

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

Prototype

@CheckReturnValue
public final <T> FluentIterable<T> transform(Function<? super E, T> function) 

Source Link

Document

Returns a fluent iterable that applies function to each element of this fluent iterable.

Usage

From source file:aeon.compiler.generators.Names.java

/**
 * Transforms Iterable of {@link aeon.compiler.context.SqliteField} into an Iterable of escaped field names.
 *
 * @param fields Iterable of SqliteField to be escaped
 * @return Iterable of escaped names//from  w ww  .  j  a v a 2  s.co m
 */
public static Iterable<String> escapedNames(@NotNull final FluentIterable<SqliteField> fields) {
    checkNotNull(fields);
    return fields.transform(new Function<SqliteField, String>() {
        @Override
        public String apply(final SqliteField input) {
            return input.getName().asEscapedName();
        }
    });
}

From source file:see.exceptions.SeeRuntimeException.java

/**
 * Extract see stacktrace from a throwable
 * @param throwable target throwable/*from  w  w  w.j  a va 2 s . c om*/
 * @return extracted trace
 */
private static List<TraceElement> getTrace(Throwable throwable) {
    List<Throwable> causalChain = getCausalChain(throwable);
    FluentIterable<PropagatedException> stack = from(causalChain).filter(PropagatedException.class);
    FluentIterable<Node<?>> nodes = stack.transform(new Function<PropagatedException, Node<?>>() {
        @Override
        public Node<?> apply(PropagatedException input) {
            return input.getFailedNode();
        }
    });
    FluentIterable<TraceElement> trace = nodes.filter(Tracing.class)
            .transform(new Function<Tracing, TraceElement>() {
                @Nullable
                @Override
                public TraceElement apply(Tracing input) {
                    Option<TraceElement> position = input.position();
                    if (position.isDefined())
                        return position.get();
                    else
                        return null;
                }
            }).filter(notNull());
    return trace.toList().reverse();
}

From source file:org.jclouds.dynect.v3.functions.ExtractLastPathComponent.java

public FluentIterable<String> apply(FluentIterable<String> in) {
    return in.transform(ExtractNameInPath.INSTANCE);
}

From source file:com.squareup.javapoet.Types.java

private static TypeVariable<?> get(javax.lang.model.type.TypeVariable mirror) {
    String name = mirror.asElement().getSimpleName().toString();

    TypeMirror upperBound = mirror.getUpperBound();
    FluentIterable<TypeMirror> bounds = FluentIterable.from(ImmutableList.of(upperBound));
    // Try to detect intersection types for Java 7 (Java 8+ has a new TypeKind for that)
    // Unfortunately, we can't put this logic into Types.get() as this heuristic only really works
    // in the context of a TypeVariable's upper bound.
    if (upperBound.getKind() == TypeKind.DECLARED) {
        TypeElement bound = (TypeElement) ((DeclaredType) upperBound).asElement();
        if (bound.getNestingKind() == NestingKind.ANONYMOUS) {
            // This is (likely) an intersection type.
            bounds = FluentIterable.from(ImmutableList.of(bound.getSuperclass())).append(bound.getInterfaces());
        }//w ww . j a  v  a2s.co m
    }
    Type[] types = bounds.transform(FOR_TYPE_MIRROR)
            .filter(Predicates.not(Predicates.<Type>equalTo(ClassName.OBJECT))).toArray(Type.class);
    return typeVariable(name, types);
}

From source file:eu.numberfour.n4js.ui.navigator.internal.ResourceNode.java

@Override
public Object[] getChildren() {
    if (file.isDirectory()) {
        final FluentIterable<File> subFiles = from(Arrays.asList(file.listFiles()));
        return subFiles.transform(f -> new ResourceNode(this, f)).toArray(ResourceNode.class);
    }//  w  w w. j  a  va 2  s. c  om
    return EMPTY_ARRAY;
}

From source file:com.google.devtools.build.lib.rules.android.LibraryRGeneratorActionBuilder.java

public ResourceContainer build(RuleContext ruleContext) {
    AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);

    CustomCommandLine.Builder builder = new CustomCommandLine.Builder();
    NestedSetBuilder<Artifact> inputs = NestedSetBuilder.naiveLinkOrder();
    FilesToRunProvider executable = ruleContext.getExecutablePrerequisite("$android_resources_busybox",
            Mode.HOST);/*from ww w.  java2 s.  c  o  m*/
    inputs.addAll(executable.getRunfilesSupport().getRunfilesArtifactsWithoutMiddlemen());

    builder.add("--tool").add("GENERATE_LIBRARY_R").add("--");

    if (!Strings.isNullOrEmpty(javaPackage)) {
        builder.add("--packageForR").add(javaPackage);
    }

    FluentIterable<ResourceContainer> symbolProviders = FluentIterable.from(deps).append(resourceContainer);

    builder.addJoinStrings("--symbols", ruleContext.getConfiguration().getHostPathSeparator(),
            symbolProviders.transform(TO_SYMBOL_PATH));
    inputs.addTransitive(
            NestedSetBuilder.wrap(Order.NAIVE_LINK_ORDER, symbolProviders.transform(TO_SYMBOL_ARTIFACT)));

    builder.addExecPath("--classJarOutput", rJavaClassJar);

    builder.addExecPath("--androidJar", sdk.getAndroidJar());
    inputs.add(sdk.getAndroidJar());

    // Create the spawn action.
    SpawnAction.Builder spawnActionBuilder = new SpawnAction.Builder();
    ruleContext.registerAction(spawnActionBuilder.addTransitiveInputs(inputs.build())
            .addOutputs(ImmutableList.<Artifact>of(rJavaClassJar)).useParameterFile(ParameterFileType.UNQUOTED)
            .setCommandLine(builder.build()).setExecutable(executable)
            .setProgressMessage("Generating Library R Classes: " + ruleContext.getLabel())
            .setMnemonic("LibraryRClassGenerator").build(ruleContext));
    return resourceContainer.toBuilder().setJavaClassJar(rJavaClassJar).build();
}

From source file:com.spectralogic.ds3client.helpers.Ds3ClientHelpersImpl.java

public Iterable<Ds3Object> addPrefixToDs3ObjectsList(final Iterable<Ds3Object> objectsList,
        final String prefix) {
    final FluentIterable<Ds3Object> objectIterable = FluentIterable.from(objectsList);

    return objectIterable.transform(new Function<Ds3Object, Ds3Object>() {
        @Nullable/*from   www.  ja  v a 2 s  . c  o  m*/
        @Override
        public Ds3Object apply(@Nullable final Ds3Object object) {
            return new Ds3Object(prefix + object.getName(), object.getSize());
        }
    });
}

From source file:com.spectralogic.ds3client.helpers.Ds3ClientHelpersImpl.java

public Iterable<Ds3Object> removePrefixFromDs3ObjectsList(final Iterable<Ds3Object> objectsList,
        final String prefix) {
    final FluentIterable<Ds3Object> objectIterable = FluentIterable.from(objectsList);

    return objectIterable.transform(new Function<Ds3Object, Ds3Object>() {
        @Nullable/*ww  w. ja  va2s.c om*/
        @Override
        public Ds3Object apply(@Nullable final Ds3Object object) {
            return new Ds3Object(stripLeadingPath(object.getName(), prefix), object.getSize());
        }
    });
}

From source file:de.zalando.hackweek.bpm.engine.impl.cassandra.db.handler.SelectProcessInstanceByQueryCriteriaHandler.java

@Override
public List<?> selectList(final Session session, final Object parameter) {
    ProcessInstanceQueryImpl query = (ProcessInstanceQueryImpl) parameter;

    final String processInstanceId = query.getProcessInstanceId();
    final QueryBuilder queryBuilder = QueryBuilder.query(QUERY).parameter("proc_inst_id", processInstanceId);
    FluentIterable<Row> rows = from(queryBuilder.execute(session));

    if (query.getOnlyProcessInstances()) {
        rows = rows.filter(new Predicate<Row>() {
            @Override//from  ww w .j  a  v a 2s .c o  m
            public boolean apply(final Row row) {
                return row.isNull("parent_id");
            }
        });
    }

    return rows.transform(ExecutionMapping.INSTANCE).toList();
}

From source file:org.sosy_lab.cpachecker.util.cwriter.CExpressionInvariantExporter.java

/**
 * @return Mapping from line numbers to states associated with the given line.
 *///from   w  w  w  .  ja  v a  2s  .  c  om
private Map<Integer, BooleanFormula> getInvariantsForFile(ReachedSet pReachedSet, String filename) {

    // One formula per reported state.
    Multimap<Integer, BooleanFormula> byState = HashMultimap.create();

    for (AbstractState state : pReachedSet) {

        CFANode loc = AbstractStates.extractLocation(state);
        if (loc != null && loc.getNumEnteringEdges() > 0) {
            CFAEdge edge = loc.getEnteringEdge(0);
            FileLocation location = edge.getFileLocation();
            FluentIterable<FormulaReportingState> reporting = AbstractStates.asIterable(state)
                    .filter(FormulaReportingState.class);

            if (location.getFileName().equals(filename) && !reporting.isEmpty()) {
                BooleanFormula reported = bfmgr
                        .and(reporting.transform(s -> s.getFormulaApproximation(fmgr)).toList());
                byState.put(location.getStartingLineInOrigin(), reported);
            }
        }
    }
    return Maps.transformValues(byState.asMap(), invariants -> bfmgr.or(invariants));
}