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:ratpack.util.internal.Environment.java

@SafeVarargs
@SuppressWarnings("varargs")
protected static <T> T get(T defaultValue, Predicate<? super T> accept, Supplier<T>... suppliers) {
    return Iterables.find(Iterables.transform(Arrays.asList(suppliers), Supplier::get), accept::test,
            defaultValue);/*  w  ww  .  j ava 2 s.c  om*/
}

From source file:org.apache.brooklyn.rest.transform.EffectorTransformer.java

public static EffectorSummary effectorSummary(final Entity entity, Effector<?> effector) {
    String applicationUri = "/v1/applications/" + entity.getApplicationId();
    String entityUri = applicationUri + "/entities/" + entity.getId();
    return new EffectorSummary(effector.getName(), effector.getReturnTypeName(),
            ImmutableSet.copyOf(Iterables.transform(effector.getParameters(),
                    new Function<ParameterType<?>, EffectorSummary.ParameterSummary<?>>() {
                        @Override
                        public EffectorSummary.ParameterSummary<?> apply(
                                @Nullable ParameterType<?> parameterType) {
                            return parameterSummary(entity, parameterType);
                        }/*from w w  w  .j av a2 s  .c om*/
                    })),
            effector.getDescription(),
            ImmutableMap.of("self", URI.create(entityUri + "/effectors/" + effector.getName()), "entity",
                    URI.create(entityUri), "application", URI.create(applicationUri)));
}

From source file:org.incode.module.commchannel.dom.impl.type.CommunicationChannelType.java

private static String enumTitle(final Enum<?> anEnum) {
    if (anEnum == null) {
        return null;
    }/*from  w w w.  ja  v a  2 s.co  m*/
    return Joiner.on(" ")
            .join(Iterables.transform(Splitter.on("_").split(anEnum.toString()), LOWER_CASE_THEN_CAPITALIZE));
}

From source file:com.twitter.aurora.scheduler.filter.AttributeFilter.java

/**
 * Tests whether a constraint is satisfied by attributes.
 *
 * @param attributes Host attributes.//from  w  w  w.j a va2 s  . c om
 * @param constraint Constraint to match.
 * @return {@code true} if the attribute satisfies the constraint, {@code false} otherwise.
 */
static boolean matches(Set<Attribute> attributes, IValueConstraint constraint) {
    Set<String> allAttributes = ImmutableSet
            .copyOf(Iterables.concat(Iterables.transform(attributes, GET_VALUES)));
    boolean match = Iterables.any(constraint.getValues(), Predicates.in(allAttributes));
    return constraint.isNegated() ^ match;
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.coll.CollectionData.java

public static <OV extends JsonOverlay<?>> CollectionData<OV> of(JsonNode json, final JsonOverlay<?> parent,
        final JsonOverlayFactory<OV> factory) {
    if (json.isArray()) {
        return new CollectionData<OV>(Iterables.transform(JsonOverlay.iterable(json.elements()),
                new Function<JsonNode, Entry<String, OV>>() {
                    @Override/*www .j a  v  a 2 s.  c  o m*/
                    public Entry<String, OV> apply(JsonNode element) {
                        return new SimpleEntry<>(null, factory.create(null, element, parent));
                    }
                }));
    } else if (json.isObject()) {
        return new CollectionData<OV>(Iterables.transform(JsonOverlay.iterable(json.fields()),
                new Function<Entry<String, JsonNode>, Entry<String, OV>>() {

                    @Override
                    public Entry<String, OV> apply(Entry<String, JsonNode> field) {
                        return new SimpleEntry<>(field.getKey(),
                                factory.create(field.getKey(), field.getValue(), parent));
                    }
                }));
    } else { // missing or incompatible json
        return new CollectionData<OV>(Collections.<Entry<String, OV>>emptyList());
    }
}

From source file:msi.gaml.expressions.IExpressionCompiler.java

public static Iterable<? extends OperatorProto> getAllOperators() {
    return Iterables.concat(Iterables.transform(OPERATORS.values(), (each) -> each.values()));
}

From source file:com.synflow.models.ir.transform.UniqueNameComputer.java

public UniqueNameComputer(List<Var> variables) {
    this(Iterables.transform(variables, new Function<Var, String>() {
        public String apply(Var variable) {
            return variable.getName();
        }/*from  www  .j av a2  s  .  co  m*/
    }));
}

From source file:com.metamx.druid.guava.GuavaUtils.java

public static InputSupplier<BufferedReader> joinFiles(final List<File> files) {

    return new InputSupplier<BufferedReader>() {
        @Override/*w w w. j  ava  2  s  . c o m*/
        public BufferedReader getInput() throws IOException {
            return new BufferedReader(CharStreams
                    .join(Iterables.transform(files, new Function<File, InputSupplier<InputStreamReader>>() {
                        @Override
                        public InputSupplier<InputStreamReader> apply(final File input) {
                            return new InputSupplier<InputStreamReader>() {
                                @Override
                                public InputStreamReader getInput() throws IOException {
                                    InputStream baseStream = new FileInputStream(input);
                                    if (input.getName().endsWith(".gz")) {
                                        baseStream = new GZIPInputStream(baseStream);
                                    }

                                    return new InputStreamReader(baseStream, Charsets.UTF_8);
                                }
                            };
                        }
                    })).getInput());
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.MethodDispatcher.java

private String toKey(String methodName, List<TypeWidget> argumentTypes) {
    StringBuilder out = new StringBuilder();
    out.append(methodName).append('(');
    Joiner.on(",").appendTo(out, Iterables.transform(argumentTypes, new Function<TypeWidget, String>() {
        @Override//from   w w w  .  ja  v  a 2s  . c o m
        public String apply(TypeWidget input) {
            return input.getJVMType().getDescriptor();
        }
    }));
    out.append(')');
    return out.toString();
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.LeafSetNodeBaseSerializer.java

@Override
public final Iterable<E> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) {
    return Iterables.concat(Iterables.transform(node.getValue(), input -> {
        final Iterable<E> serializedChild = getLeafSetEntryNodeSerializer().serialize(schema, input);
        final int size = Iterables.size(serializedChild);
        Preconditions.checkState(size == 1,
                "Unexpected count of elements for leaf-list entry serialized from: %s, should be 1, was: %s",
                input, size);/*from w  w w  . j  a v  a 2 s. c  o  m*/
        return serializedChild;
    }));
}