List of usage examples for com.google.common.base Functions compose
public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f)
From source file:org.apache.brooklyn.core.sensor.windows.WinRmCommandSensor.java
@Override public void apply(final EntityLocal entity) { super.apply(entity); if (LOG.isDebugEnabled()) { LOG.debug("Adding WinRM sensor {} to {}", name, entity); }//w w w . j a v a 2 s. c o m final Boolean suppressDuplicates = EntityInitializers.resolve(params, SUPPRESS_DUPLICATES); final Duration logWarningGraceTimeOnStartup = EntityInitializers.resolve(params, LOG_WARNING_GRACE_TIME_ON_STARTUP); final Duration logWarningGraceTime = EntityInitializers.resolve(params, LOG_WARNING_GRACE_TIME); Supplier<Map<String, String>> envSupplier = new Supplier<Map<String, String>>() { @SuppressWarnings("serial") @Override public Map<String, String> get() { Map<String, String> env = MutableMap.copyOf(entity.getConfig(SENSOR_ENVIRONMENT)); // Add the shell environment entries from our configuration if (sensorEnv != null) env.putAll(sensorEnv); // Try to resolve the configuration in the env Map try { env = Tasks.resolveDeepValueExactly(env, new TypeToken<Map<String, String>>() { }, ((EntityInternal) entity).getExecutionContext()); } catch (InterruptedException | ExecutionException e) { Exceptions.propagateIfFatal(e); } // Convert the environment into strings with the serializer ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer( ((EntityInternal) entity).getManagementContext()); return serializer.serialize(env); } }; Supplier<String> commandSupplier = new Supplier<String>() { @Override public String get() { return makeCommandExecutingInDirectory(command, executionDir, entity); } }; CommandPollConfig<T> pollConfig = new CommandPollConfig<T>(sensor).period(period).env(envSupplier) .command(commandSupplier).suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .checkSuccess(SshValueFunctions.exitStatusEquals(0)) .onFailureOrException(Functions.constant((T) null)) .onSuccess(Functions.compose(new Function<String, T>() { @Override public T apply(String input) { return TypeCoercions.coerce(Strings.trimEnd(input), (Class<T>) sensor.getType()); } }, SshValueFunctions.stdout())).logWarningGraceTimeOnStartup(logWarningGraceTimeOnStartup) .logWarningGraceTime(logWarningGraceTime); CmdFeed feed = CmdFeed.builder().entity(entity).onlyIfServiceUp().poll(pollConfig).build(); entity.addFeed(feed); }
From source file:net.shibboleth.idp.saml.saml2.profile.impl.PopulateEncryptionParameters.java
/** Constructor. */ public PopulateEncryptionParameters() { requestLookupStrategy = Functions.compose(new MessageLookup<>(AuthnRequest.class), new InboundMessageContextLookup()); relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class); // Create context by default. encryptionContextLookupStrategy = Functions.compose(new ChildContextLookup<>(EncryptionContext.class, true), new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class)); // Default: outbound msg context -> SAMLPeerEntityContext peerContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class), new OutboundMessageContextLookup()); }
From source file:org.apache.abdera2.common.misc.MapRed.java
public static <K1, V1, K2, V2, K3, V3> Function<Iterable<Pair<K1, V1>>, Iterable<Pair<K3, Iterable<V3>>>> compose( MapperFunction<K1, V1, K2, V2> mapper, ReducerFunction<K2, V2, K3, V3> reducer) { return Functions.compose(reducer, mapper); }
From source file:net.shibboleth.idp.saml.impl.profile.PopulateBindingAndEndpointContexts.java
/** Constructor. */ public PopulateBindingAndEndpointContexts() { endpointType = AssertionConsumerService.DEFAULT_ELEMENT_NAME; bindingDescriptors = Collections.emptyList(); relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class); // Default: outbound msg context -> SAMLPeerEntityContext -> SAMLMetadataContext metadataContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLMetadataContext.class), Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class), new OutboundMessageContextLookup())); // Default: outbound msg context -> SAMLBindingContext bindingContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLBindingContext.class, true), new OutboundMessageContextLookup()); // Default: outbound msg context -> SAMLPeerEntityContext -> SAMLEndpointContext endpointContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLEndpointContext.class, true), Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class, true), new OutboundMessageContextLookup())); }
From source file:org.apache.abdera2.common.misc.MapRed.java
public static <K1, V1, K2, V2, K3, V3> Function<Iterable<Pair<K1, V1>>, Iterable<Pair<K3, Iterable<V3>>>> compose( MapperFunction<K1, V1, K2, V2> mapper, ReducerFunction<K2, V2, K2, V2> combiner, ReducerFunction<K2, V2, K3, V3> reducer) { return Functions.compose(reducer, Functions.compose(combiner, mapper)); }
From source file:com.github.fhirschmann.clozegen.lib.util.UIMAUtils.java
/** * Returns the covered text of the list of {@link Annotation}s produced * by {@link UIMAUtils#getAdjacentAnnotations(Class, List, int, int)}. * {@code null} will be replaced with "NULL" by {@link EscapeNullFunction}. * * @param <T> the annotation type//from www. j a v a 2 s. c o m * @param clazz the class of the annotation type * @param annotationList the list of annotation * @param offset the offset of the element in {@code annotationList} * @param num the number of neighbors to receive * @return a list of neighbors (covered text) */ public static <T extends Annotation> List<String> getAdjacentTokens(final Class<T> clazz, final List<Annotation> annotationList, final int offset, final int num) { final List<T> adjacent = getAdjacentAnnotations(clazz, annotationList, offset, num); final List<String> tokens = Lists.newArrayList(Collections2.transform(adjacent, Functions.compose(new EscapeNullFunction(), new CoveredTextFunction()))); return tokens; }
From source file:com.android.builder.internal.packaging.IncrementalPackager.java
/** * Updates files in the archive.// w ww. ja v a 2s .c o m * * @param updates the updates to perform * @throws IOException failed to update the archive */ private void updateFiles(@NonNull Set<PackagedFileUpdate> updates) throws IOException { Preconditions.checkNotNull(mApkCreator, "mApkCreator == null"); Iterable<String> deletedPaths = Iterables .transform( Iterables .filter(updates, Predicates.compose(Predicates.equalTo(FileStatus.REMOVED), PackagedFileUpdate.EXTRACT_STATUS)), PackagedFileUpdate.EXTRACT_NAME); for (String deletedPath : deletedPaths) { mApkCreator.deleteFile(deletedPath); } Predicate<PackagedFileUpdate> isNewOrChanged = Predicates.compose( Predicates.or(Predicates.equalTo(FileStatus.NEW), Predicates.equalTo(FileStatus.CHANGED)), PackagedFileUpdate.EXTRACT_STATUS); Function<PackagedFileUpdate, File> extractBaseFile = Functions.compose(RelativeFile.EXTRACT_BASE, PackagedFileUpdate.EXTRACT_SOURCE); Iterable<PackagedFileUpdate> newOrChangedNonArchiveFiles = Iterables.filter(updates, Predicates.and(isNewOrChanged, Predicates.compose(Files.isDirectory(), extractBaseFile))); for (PackagedFileUpdate rf : newOrChangedNonArchiveFiles) { mApkCreator.writeFile(rf.getSource().getFile(), rf.getName()); } Iterable<PackagedFileUpdate> newOrChangedArchiveFiles = Iterables.filter(updates, Predicates.and(isNewOrChanged, Predicates.compose(Files.isFile(), extractBaseFile))); Iterable<File> archives = Iterables.transform(newOrChangedArchiveFiles, extractBaseFile); Set<String> names = Sets .newHashSet(Iterables.transform(newOrChangedArchiveFiles, PackagedFileUpdate.EXTRACT_NAME)); /* * Build the name map. The name of the file in the filesystem (or zip file) may not * match the name we want to package it as. See PackagedFileUpdate for more information. */ Map<String, String> pathNameMap = Maps.newHashMap(); for (PackagedFileUpdate archiveUpdate : newOrChangedArchiveFiles) { pathNameMap.put(archiveUpdate.getSource().getOsIndependentRelativePath(), archiveUpdate.getName()); } for (File arch : Sets.newHashSet(archives)) { mApkCreator.writeZip(arch, pathNameMap::get, name -> !names.contains(name)); } }
From source file:org.opensaml.saml.saml2.profile.impl.AddNameIDToSubjects.java
/** Constructor. * //from w w w.ja v a2s .c om * @throws ComponentInitializationException if an error occurs initializing default predicate. */ public AddNameIDToSubjects() throws ComponentInitializationException { subjectBuilder = (SAMLObjectBuilder<Subject>) XMLObjectProviderRegistrySupport.getBuilderFactory() .<Subject>getBuilderOrThrow(Subject.DEFAULT_ELEMENT_NAME); nameIdBuilder = (SAMLObjectBuilder<NameID>) XMLObjectProviderRegistrySupport.getBuilderFactory() .<NameID>getBuilderOrThrow(NameID.DEFAULT_ELEMENT_NAME); overwriteExisting = true; requestLookupStrategy = Functions.compose(new MessageLookup<>(AuthnRequest.class), new InboundMessageContextLookup()); assertionsLookupStrategy = new AssertionStrategy(); // Default strategy is a 16-byte secure random source. idGeneratorLookupStrategy = new Function<ProfileRequestContext, IdentifierGenerationStrategy>() { public IdentifierGenerationStrategy apply(ProfileRequestContext input) { return new SecureRandomIdentifierGenerationStrategy(); } }; // Default predicate pulls SPNameQualifier from NameIDPolicy and does a direct match // against issuer. Handles simple cases, overridden for complex ones. nameIDPolicyPredicate = new DefaultNameIDPolicyPredicate(); ((DefaultNameIDPolicyPredicate) nameIDPolicyPredicate) .setRequesterIdLookupStrategy(new RequesterIdFromIssuerFunction()); ((DefaultNameIDPolicyPredicate) nameIDPolicyPredicate) .setObjectLookupStrategy(new NameIDPolicyLookupFunction()); ((DefaultNameIDPolicyPredicate) nameIDPolicyPredicate).initialize(); formatLookupStrategy = new MetadataNameIdentifierFormatStrategy(); formats = Collections.emptyList(); }
From source file:com.github.rinde.rinsim.scenario.ScenarioIO.java
/** * Allows to adapt the default reader ({@link #reader()}) by converting all * read scenarios. {@link ScenarioConverters} contains functions that can be * used for this./*w ww . j av a 2 s .c om*/ * @param converter A converter that transforms a scenario. * @return A new reader function. */ public static Function<Path, Scenario> readerAdapter(Function<Scenario, Scenario> converter) { return Functions.compose(converter, reader()); }
From source file:org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule.java
/** * only add the overhead of looking up ips when we have enabled the auto-allocate functionality *//*from w w w . j a va2 s . com*/ @Provides @Singleton public Function<RunningInstance, NodeMetadata> bindNodeConverter(RunningInstanceToNodeMetadata baseConverter, AddElasticIpsToNodemetadata addElasticIpsToNodemetadata, @Named(EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS) boolean autoAllocateElasticIps) { if (!autoAllocateElasticIps) return baseConverter; return Functions.compose(addElasticIpsToNodemetadata, baseConverter); }