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.caleydo.view.domino.api.model.typed.MultiTypedList.java

@Override
public List<TypedID> asInhomogenous() {
    if (ids instanceof Single)
        return new SingleTypedIDList(((Single) ids).data);
    ImmutableList.Builder<TypedID> b = ImmutableList.builder();
    for (int i = 0; i < depth(); ++i) {
        IDType idType = idTypes[i];/*from w  ww. ja  v a2s.  c  o  m*/
        // select just the slice and map to typed id
        b.addAll(Collections2.transform(ids, Functions.compose(TypedID.toTypedId(idType), slice(i))));
    }
    return b.build();
}

From source file:org.obiba.opal.rest.client.magma.RestValueTableWriter.java

@Override
public VariableWriter writeVariables() {
    return new VariableWriter() {

        private final List<Variable> variables = Lists.newArrayList();

        @Override//w ww  .j a  va 2s .  com
        public void close() {
            URI variablesResource = restValueTable.newReference("variables");
            Iterable<VariableDto> variableDtos = Iterables.transform(variables,
                    Functions.compose(new Function<VariableDto.Builder, VariableDto>() {

                        @Override
                        public VariableDto apply(Builder input) {
                            return input.build();
                        }
                    }, Dtos.asDtoFunc(null)));

            try {
                checkResponse(restValueTable.getOpalClient().post(variablesResource, variableDtos));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            restValueTable.refresh();
        }

        @Override
        public void writeVariable(@NotNull Variable variable) {
            variables.add(variable);
        }

        @Override
        public void removeVariable(@NotNull Variable variable) {
            //To change body of implemented methods use File | Settings | File Templates.
        }

    };
}

From source file:demo.temperature.DeviceEntityImpl.java

@Override
public void init() {
    super.init();

    Function<HttpToolResponse, String> f = HttpValueFunctions.stringContentsFunction();
    Function<String, Double> g = new Function<String, Double>() {
        @Nullable//  w w w  .ja v  a  2 s.  co  m
        @Override
        public Double apply(String input) {
            if (input == null)
                return null;
            try {
                return Double.parseDouble(input);
            } catch (NumberFormatException e) {
                return null;
            }
        }
    };
    Function<HttpToolResponse, Double> composed = Functions.compose(g, f);

    host = checkNotNull(getConfig(HOST), "Config key 'host' is required");
    port = checkNotNull(getConfig(PORT), "Config key 'port' is required");

    feed = HttpFeed.builder().entity(this).period(Duration.ONE_SECOND)
            .baseUri(String.format("http://%s:%s/temperature", host, port))
            .poll(new HttpPollConfig<>(TEMPERATURE).onSuccess(composed)).build();

    final Effector onEffector = checkNotNull(getEffector("relay1On"), "relay1On");
    final Effector offEffector = checkNotNull(getEffector("relay1Off"), "relay1Off");
}

From source file:com.twitter.common.net.UrlResolverUtil.java

UrlResolverUtil(Map<String, String> hostToUserAgent) {
    this(Functions.compose(Functions.forMap(checkNotBlank(hostToUserAgent), DEFAULT_USER_AGENT),
            new Function<URL, String>() {
                @Override/*  w w  w.  j a v a 2 s. c om*/
                public String apply(URL url) {
                    return url.getHost();
                }
            }));
}

From source file:org.caleydo.view.domino.api.model.typed.MultiTypedSet.java

@Override
public Set<TypedID> asInhomogenous() {
    if (ids instanceof Single)
        return new SingleTypedIDSet(((Single) ids).set);
    ImmutableSet.Builder<TypedID> b = ImmutableSet.builder();
    for (int i = 0; i < depth(); ++i) {
        IDType idType = idTypes[i];/*from   w w  w.java2s.  c  o m*/
        // select just the slice and map to typed id
        b.addAll(Collections2.transform(ids, Functions.compose(TypedID.toTypedId(idType), slice(i))));
    }
    return b.build();
}

From source file:org.trancecode.xml.catalog.Catalogs.java

public static Function<CatalogQuery, URI> setBaseUri(final URI baseUri,
        @Nullable final Function<CatalogQuery, URI> catalog) {
    if (baseUri == null) {
        return catalog;
    }/*  ww w.  j av a 2s . c o  m*/

    return Functions.compose(UriFunctions.resolveUri(baseUri), catalog);
}

From source file:com.eviware.loadui.ui.fx.views.project.ProjectCanvasView.java

@Override
protected ObservableList<? extends CanvasObjectView> createCanvasObjects() {
    ObservableList<ScenarioView> scenarios = transform(
            fx(ofCollection(getCanvas(), ProjectItem.SCENES, SceneItem.class, getCanvas().getChildren())),
            Functions.compose(new InitializeCanvasObjectView<ScenarioView>(),
                    new Function<SceneItem, ScenarioView>() {
                        @Override
                        public ScenarioView apply(SceneItem input) {
                            return new ScenarioView(input);
                        }//from ww w.  j  a  v a 2 s  . c  om
                    }));

    return ObservableLists.concat(super.createCanvasObjects(), scenarios);
}

From source file:com.persinity.ndt.dbagent.relational.impl.CdcUmountFunctor.java

@Override
public Function<RelDb, RelDb> apply(final String tableName) {
    final String clogTrigSql = ddlSql.dropTrigger(appSchemaInfo.getClogTriggerName(tableName));
    final RelFunc clogTrigFunc = new RelFunc(clogTrigSql);

    final String trlogTrigSql = ddlSql.dropTrigger(appSchemaInfo.getTrlogTriggerName(tableName));
    final RelFunc trlogTrigFunc = new RelFunc(trlogTrigSql);

    final Function<RelDb, RelDb> logFunc = new LoggingRepeaterFunc<>(log, "Cdc umount at table \"{}\"",
            tableName);//from www  . j  a v  a  2s .c om

    final Function<RelDb, RelDb> dropTrigsFunc = Functions
            .compose(Functions.compose(trlogTrigFunc, clogTrigFunc), logFunc);
    return dropTrigsFunc;
}

From source file:net.shibboleth.idp.profile.audit.impl.AttributesAuditExtractor.java

/** Constructor. */
public AttributesAuditExtractor() {
    // Defaults to ProfileRequestContext -> RelyingPartyContext -> AttributeContext.
    attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class),
            new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class));
}

From source file:net.shibboleth.idp.profile.logic.AbstractAttributePredicate.java

/** Constructor. */
public AbstractAttributePredicate() {
    attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class),
            new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class));
    useUnfilteredAttributes = true;//w w w. ja va 2  s.c om
}