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:com.eucalyptus.auth.policy.key.Keys.java

public static Map<String, Key> getKeyInstances(final EvaluationConstraint constraint) {
    return Maps.transformValues(
            Maps.filterValues(KEY_MAP,/*from www  .jav  a  2s  .  c  o m*/
                    CollectionUtils.propertyContainsPredicate(constraint, Functions
                            .compose(PolicyKeyToEvaluationConstraints.INSTANCE, KeyClassToPolicyKey.INSTANCE))),
            KeyClassToKeyInstance.INSTANCE);
}

From source file:net.shibboleth.idp.profile.impl.FilterAttributes.java

/**
 * Constructor./*from w w w  .  j  a  v  a 2s.  c  om*/
 * 
 * @param filterService engine used to filter attributes
 */
public FilterAttributes(@Nonnull final ReloadableService<AttributeFilter> filterService) {
    attributeFilterService = Constraint.isNotNull(filterService, "Service cannot be null");

    issuerLookupStrategy = new ResponderIdLookupFunction();
    recipientLookupStrategy = new RelyingPartyIdLookupFunction();

    attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class),
            new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class));

    principalNameLookupStrategy = Functions.compose(new SubjectContextPrincipalLookupFunction(),
            new ChildContextLookup<ProfileRequestContext, SubjectContext>(SubjectContext.class));

    authnContextLookupStrategy = new ChildContextLookup<>(AuthenticationContext.class);

    // Default: inbound msg context -> SAMLPeerEntityContext -> SAMLMetadataContext
    metadataContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLMetadataContext.class),
            Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class),
                    new InboundMessageContextLookup()));

    // This is always set to navigate to the root context and then apply the previous function.
    metadataFromFilterLookupStrategy = Functions
            .compose(new Function<ProfileRequestContext, SAMLMetadataContext>() {
                @Override
                public SAMLMetadataContext apply(ProfileRequestContext input) {
                    return metadataContextLookupStrategy.apply(input);
                }
            }, new RootContextLookup<AttributeFilterContext, ProfileRequestContext>());

    // Defaults to ProfileRequestContext -> RelyingPartyContext -> AttributeFilterContext.
    filterContextCreationStrategy = Functions.compose(
            new ChildContextLookup<>(AttributeFilterContext.class, true),
            new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class));

    maskFailures = true;
}

From source file:com.persinity.ndt.etlmodule.relational.migrate.PreMigrateRelTransferFunc.java

private void createTrlogEtlFunctions(final int tidsSize) {
    final SchemaInfo srcSchema = getSchemas().src();

    final Set<Col> srcTrlogCols = srcSchema.getTableCols(SchemaInfo.TAB_TRLOG);
    assertArg(!srcTrlogCols.isEmpty(), "Failed to find src trlog entity columns: {}", SchemaInfo.TAB_TRLOG);
    final Set<Col> dstTrlogCols = getSchemas().dst().getTableCols(SchemaInfo.TAB_TRLOG);
    assertArg(!dstTrlogCols.isEmpty(), "Failed to find dst trlog entity columns: {}", SchemaInfo.TAB_TRLOG);

    final PK dstTrlogPk = getSchemas().dst().getTablePk(SchemaInfo.TAB_TRLOG);
    assertArg(dstTrlogPk != null, "Could not find PK for trlog table: {}", SchemaInfo.TAB_TRLOG);

    List<Col> pkCols = new ArrayList<>(dstTrlogPk.getColumns());

    final LinkedHashSet<Col> clogIntCols = new LinkedHashSet<>(srcTrlogCols);
    clogIntCols.retainAll(dstTrlogCols);
    final LinkedList<Col> cols = new LinkedList<>(clogIntCols);

    assertArg(!cols.isEmpty(), "Intersection between src trlogCols: {} and dst trlogCols: {} is empty",
            srcTrlogCols, dstTrlogCols);

    final String extractSql = getSqlStrategy().trlogExtractQuery(SchemaInfo.TAB_TRLOG, cols, tidsSize);
    final String updateSql = getSqlStrategy().updateStatement(SchemaInfo.TAB_TRLOG, cols, pkCols);
    final String insertSql = getSqlStrategy().insertStatement(SchemaInfo.TAB_TRLOG, cols);

    extractF = new ParamQryFunc(cols, extractSql);
    transformF = new TupleFunc() {
        @Override/*from   www  . j av a 2s. c o  m*/
        public Iterator<Map<String, Object>> apply(final Iterator<Map<String, Object>> mapIterator) {
            return new Iterator<Map<String, Object>>() {
                @Override
                public boolean hasNext() {
                    return mapIterator.hasNext();
                }

                @Override
                public Map<String, Object> next() {
                    final Map<String, Object> res = mapIterator.next();
                    final Map<String, Object> resChanged = new HashMap<>();
                    for (String key : res.keySet()) {
                        Object value = res.get(key);
                        if (key.equals(SchemaInfo.COL_STATUS)) {
                            value = SchemaInfo.TrlogStatusType.L.toString();
                        }
                        resChanged.put(key, value);
                    }
                    return resChanged;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    loadF = new ParamDmlLoadFunc(new InsertOnFailureUpdateFunc(insertSql, updateSql, cols, pkCols));

    etFunc = Functions.compose(transformF, extractF);
}

From source file:org.opensaml.saml.saml2.profile.impl.AddSubjectConfirmationToSubjects.java

/** Constructor. */
public AddSubjectConfirmationToSubjects() {
    subjectBuilder = (SAMLObjectBuilder<Subject>) XMLObjectProviderRegistrySupport.getBuilderFactory()
            .<Subject>getBuilderOrThrow(Subject.DEFAULT_ELEMENT_NAME);
    confirmationBuilder = (SAMLObjectBuilder<SubjectConfirmation>) XMLObjectProviderRegistrySupport
            .getBuilderFactory()/*w  w w  .j  a  v a  2s .  com*/
            .<SubjectConfirmation>getBuilderOrThrow(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
    confirmationDataBuilder = (SAMLObjectBuilder<SubjectConfirmationData>) XMLObjectProviderRegistrySupport
            .getBuilderFactory()
            .<SubjectConfirmationData>getBuilderOrThrow(SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
    overwriteExisting = true;
    responseLookupStrategy = Functions.compose(new MessageLookup<>(Response.class),
            new OutboundMessageContextLookup());

    // Default pulls from servlet request.
    addressLookupStrategy = new Function<ProfileRequestContext, String>() {
        public String apply(ProfileRequestContext input) {
            final String address = getHttpServletRequest() != null ? getHttpServletRequest().getRemoteAddr()
                    : null;
            log.debug("{} Setting confirmation data Address to {}", getLogPrefix(),
                    address != null ? address : "(none)");
            return address;
        }
    };

    // Default pulls from inbound message context and a SAMLMessageInfoContext child.
    inResponseToLookupStrategy = new Function<ProfileRequestContext, String>() {
        public String apply(ProfileRequestContext input) {
            if (response != null && response.getInResponseTo() != null) {
                log.debug("{} Setting confirmation data InResponseTo to {}", getLogPrefix(),
                        response.getInResponseTo());
                return response.getInResponseTo();
            }
            log.debug("{} Setting confirmation data InResponseTo to (none)", getLogPrefix());
            return null;
        }
    };

    // Default pulls from SAML endpoint on outbound message context.
    recipientLookupStrategy = new Function<ProfileRequestContext, String>() {
        public String apply(ProfileRequestContext input) {
            if (input.getOutboundMessageContext() != null) {
                try {
                    final URI uri = SAMLBindingSupport.getEndpointURL(input.getOutboundMessageContext());
                    if (uri != null) {
                        final String url = uri.toString();
                        log.debug("{} Setting confirmation data Recipient to {}", getLogPrefix(), url);
                        return url;
                    }
                } catch (BindingException e) {
                    log.debug("{} Error getting response endpoint", getLogPrefix(), e);
                }
            }
            log.debug("{} Setting confirmation data Recipient to (none)", getLogPrefix());
            return null;
        }
    };

    // Default is 5 minutes.
    lifetimeLookupStrategy = new Function<ProfileRequestContext, Long>() {
        public Long apply(ProfileRequestContext input) {
            log.debug("{} Setting confirmation data NotOnOrAfter to 5 minutes from now", getLogPrefix());
            return 5 * 60 * 1000L;
        }
    };
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.contentassist.EMFPatternLanguageProposalProvider.java

@Override
protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName,
        ContentAssistContext contentAssistContext) {
    Function<IEObjectDescription, ICompletionProposal> factory = super.getProposalFactory(ruleName,
            contentAssistContext);/*from w w w  . j a v  a2  s  . c o  m*/
    if (contentAssistContext.getCurrentNode().getSemanticElement() instanceof PatternCall
            && ga.getQualifiedNameRule().getName().equals(ruleName)) {
        factory = Functions.compose(this::configurePatternProposal, factory);
    }

    return factory;
}

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

private <K, V> String mapToDictionaryString(Map<K, V> map, Function<? super K, String> keyConverter,
        Function<? super V, String> valueConverter) {
    if (keyConverter == null) {
        keyConverter = Functions.toStringFunction();
    }/*w w  w . j a  v  a 2s . c  o  m*/
    if (valueConverter == null) {
        valueConverter = Functions.toStringFunction();
    }

    StringBuilder sb = new StringBuilder();
    Iterator<Entry<K, V>> iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<K, V> entry = iter.next();
        sb.append(Functions.compose(ESCAPER, keyConverter).apply(entry.getKey()));
        sb.append(':');
        sb.append(Functions.compose(ESCAPER, valueConverter).apply(entry.getValue()));
        if (iter.hasNext()) {
            sb.append(',');
        }
    }
    return sb.toString();
}

From source file:net.shibboleth.idp.saml.saml2.profile.impl.ProcessLogoutRequest.java

/** Constructor. */
public ProcessLogoutRequest() {
    subjectContextCreationStrategy = new ChildContextLookup<>(SubjectContext.class, true);
    sessionContextCreationStrategy = new ChildContextLookup<>(SessionContext.class, true);
    logoutContextCreationStrategy = new ChildContextLookup<>(LogoutContext.class, true);

    sessionResolverCriteriaStrategy = new Function<ProfileRequestContext, CriteriaSet>() {
        public CriteriaSet apply(ProfileRequestContext input) {
            if (logoutRequest != null && logoutRequest.getIssuer() != null
                    && logoutRequest.getNameID() != null) {
                return new CriteriaSet(new SPSessionCriterion(logoutRequest.getIssuer().getValue(),
                        logoutRequest.getNameID().getValue()));
            } else {
                return new CriteriaSet();
            }//from  w w w  .  j  a  v a 2  s .  co m
        }
    };

    logoutRequestLookupStrategy = Functions.compose(new MessageLookup<>(LogoutRequest.class),
            new InboundMessageContextLookup());
}

From source file:org.apache.abdera2.common.misc.MapRed.java

public static <K1, V1, K2, V2, V3> Function<Iterable<Pair<K1, V1>>, Iterable<Pair<K2, Iterable<V3>>>> compose(
        Mapper<K1, V1, K2, V2> mapper, Reducer<K2, V2, K2, V2> combiner, Reducer<K2, V2, K2, V3> reducer,
        Comparator<K2> comparator) {
    return Functions.compose(asFunction(reducer, comparator),
            Functions.compose(asFunction(combiner, comparator), asFunction(mapper, comparator)));
}

From source file:org.apache.druid.query.groupby.GroupByQuery.java

private Function<Sequence<Row>, Sequence<Row>> makePostProcessingFn() {
    Function<Sequence<Row>, Sequence<Row>> postProcessingFn = limitSpec.build(dimensions, aggregatorSpecs,
            postAggregatorSpecs, getGranularity(), getContextSortByDimsFirst());

    if (havingSpec != null) {
        postProcessingFn = Functions.compose(postProcessingFn, (Sequence<Row> input) -> {
            havingSpec.setRowSignature(GroupByQueryHelper.rowSignatureFor(GroupByQuery.this));
            havingSpec.setAggregators(getAggregatorsMap(aggregatorSpecs));
            return Sequences.filter(input, havingSpec::eval);
        });/*w  w  w.j a va 2  s.  c o  m*/
    }
    return postProcessingFn;
}

From source file:net.shibboleth.idp.saml.impl.profile.saml2.AddAuthnStatementToAssertion.java

/** Constructor. */
public AddAuthnStatementToAssertion() {
    statementInOwnAssertion = false;/* w ww .j  av  a  2s  . c o  m*/

    responseLookupStrategy = Functions.compose(new MessageLookup<>(Response.class),
            new OutboundMessageContextLookup());
    idGeneratorLookupStrategy = new IdentifierGenerationStrategyLookupFunction();
    issuerLookupStrategy = new ResponderIdLookupFunction();
    classRefLookupStrategy = new DefaultPrincipalDeterminationStrategy<>(AuthnContextClassRefPrincipal.class,
            new AuthnContextClassRefPrincipal(AuthnContext.UNSPECIFIED_AUTHN_CTX));
    sessionLifetimeLookupStrategy = new SessionLifetimeLookupFunction();
}