Example usage for com.google.common.base Functions compose

List of usage examples for com.google.common.base Functions compose

Introduction

In this page you can find the example usage for com.google.common.base Functions compose.

Prototype

public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f) 

Source Link

Document

Returns the composition of two functions.

Usage

From source file:org.apache.abdera2.examples.simple.Parse.java

public static void main(String[] args) throws Exception {

    Parser parser = Abdera.getInstance().getParser();

    InputStream in = Parse.class.getResourceAsStream("/simple.xml");
    Document<Feed> doc = parser.parse(in);
    Feed feed = doc.getRoot();/*w  w  w  .  java 2 s  .  co m*/

    System.out.println(feed.getTitle());
    System.out.println(feed.getTitleType());
    System.out.println(feed.getAlternateLink().getResolvedHref());
    System.out.println(feed.getUpdated());
    System.out.println(feed.getAuthor().getName());
    System.out.println(feed.getId());

    Entry entry = feed.getEntries().get(0);

    System.out.println(entry.getTitle());
    System.out.println(entry.getTitleType());
    System.out.println(entry.getAlternateLink().getHref()); // relative URI
    System.out.println(entry.getAlternateLink().getResolvedHref()); // absolute URI resolved against Base URI
    System.out.println(entry.getId());
    System.out.println(entry.getUpdated());
    System.out.println(entry.getSummary());
    System.out.println(entry.getSummaryType());

    // Selectors can be used to filter out unwanted entries
    List<Entry> entries = feed.getEntries(Selectors.updated(DateTimes.afterNow()));
    System.out.println(entries);

    // We can also use the Guava (com.google.common.*) Function interface
    in = Parse.class.getResourceAsStream("/simple.xml");
    Function<InputStream, Document<Feed>> pf = Parsers.forInputStream();
    doc = pf.apply(in);

    // Which means we can chain things together in interesting ways...
    in = Parse.class.getResourceAsStream("/simple.xml");
    pf = Parsers.forInputStream();
    WriterFunction wf = Writers.forOutputStream("activity", System.out);
    Function<InputStream, Void> f = Functions.compose(wf, pf);
    f.apply(in);
}

From source file:org.nickelproject.util.functions.FunctionUtil.java

public static <F, T> Function<ExternalReference<F>, ExternalReference<T>> externalize(
        final Function<F, T> function) {
    return Functions.compose(new PutExternal<T>(), Functions.compose(function, new GetExternal<F>()));
}

From source file:com.github.mike10004.demo.infinitescroll.ItemServlet.java

static Function<String, String> newParamMapFunction(HttpServletRequest request) {
    return Functions.compose(new Function<String[], String>() {
        @Override/*  ww w. j av a2s. c  o m*/
        public String apply(String[] input) {
            return input != null && input.length > 0 ? input[0] : null;
        }
    }, Functions.forMap(request.getParameterMap(), null));
}

From source file:edu.umn.msi.tropix.webgui.server.resource.MappedResourceAccesorFunctionUtils.java

static Function<String, ResourceAccessor> create(final Function<String, String> idFunction,
        final Function<String, ResourceAccessor> resourceAccessorFunction) {
    return Functions.compose(resourceAccessorFunction, idFunction);
}

From source file:brooklyn.util.guava.Functionals.java

/** applies f1 to the input, then the result of that is passed to f2 (note opposite semantics to {@link Functions#compose(Function, Function)} */
public static <A, B, C> Function<A, C> chain(final Function<A, ? extends B> f1, final Function<B, C> f2) {
    return Functions.compose(f2, f1);
}

From source file:com.qcadoo.commons.functional.Optionals.java

public static <F, T> Function<F, Optional<T>> lift(final Function<F, T> f) {
    Function<T, Optional<T>> lift = lift();
    return Functions.compose(lift, f);
}

From source file:com.eucalyptus.ws.protocol.RequestLoggingFilters.java

public static void register(final RequestLoggingFilter requestLoggingFilter) {
    RequestLoggingFilter current;//w  w  w.java  2s . co m
    RequestLoggingFilter chained;
    do {
        current = filter.get();
        chained = forFunction(Functions.compose(requestLoggingFilter, current));
    } while (!filter.compareAndSet(current, chained));
}

From source file:org.trancecode.io.UriFunctions.java

public static Function<String, URI> resolveString(final URI baseUri) {
    return Functions.compose(resolveUri(baseUri), createUri());
}

From source file:com.google.cloud.bigtable.hbase.adapters.DefaultReadHooks.java

public void composePreSendHook(Function<ReadRowsRequest, ReadRowsRequest> newHook) {
    preSendHook = Functions.compose(newHook, preSendHook);
}

From source file:org.nickelproject.util.reducers.ReducerUtil.java

public static Collector<Double, Double> average() {
    final Reducer<Pair<Integer, Double>> reducer = new PairReducer<Integer, Double>(new IntegerSumReducer(),
            new DoubleSumReducer());
    final Function<Pair<Double, Double>, Pair<Integer, Double>> function = PairFunction
            .of(FunctionUtil.<Double, Integer>constant(1), Functions.<Double>identity());
    final Function<Pair<Integer, Double>, Double> divide = new Function<Pair<Integer, Double>, Double>() {
        @Override//  w w w. ja v  a2  s . c  o m
        public Double apply(@Nonnull final Pair<Integer, Double> from) {
            return from.getB() / from.getA();
        }
    };
    return Collector.create(Functions.compose(function, new ToPairFunction<Double>()), reducer, divide);
}