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:com.rockhoppertech.music.examples.Guava.java
public static void composed() { MIDITrack track = MIDITrackBuilder.create().noteString("C D E F G").sequential().build(); AddFunction function = new AddFunction(1); Predicate<MIDINote> p = Predicates.compose(Predicates.alwaysTrue(), function); ImmutableList<MIDINote> notes = FluentIterable.from(track).filter(p).toList(); for (MIDINote note : notes) { System.err.println(note); }//from www .ja v a2s . co m track = MIDITrackBuilder.create().noteString("C D E F G").sequential().build(); p = new PitchGreaterThanPredicate(Pitch.E5); notes = FluentIterable.from(track).filter(p).toList(); System.err.println("gt"); for (MIDINote note : notes) { System.err.println(note); } track = MIDITrackBuilder.create().noteString("C D E F G").sequential().build(); PitchFunction pf = new PitchFunction(Operation.ADD, 1); p = Predicates.compose(new PitchGreaterThanPredicate(Pitch.E5), pf); notes = FluentIterable.from(track).filter(p).toList(); System.err.println("gt add"); for (MIDINote note : notes) { System.err.println(note); } Function<Timed, Timed> startAndDur = Functions.compose(new DurationFunction(Operation.SET, Duration.S), new StartTimeFunction(Operation.ADD, 1d)); track = MIDITrackBuilder.create().noteString("C D E F G").sequential().build(); // they are actually MIDINotes ImmutableList<Timed> times = FluentIterable.from(track).transform(startAndDur).toList(); System.err.println("start and dur"); for (Timed note : times) { System.err.println(note); } }
From source file:com.facebook.buck.lua.LuaStandaloneBinary.java
@Override public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) { ImmutableList.Builder<Step> steps = ImmutableList.builder(); buildableContext.recordArtifact(output); // Make sure the parent directory exists. steps.add(new MkdirStep(getProjectFilesystem(), output.getParent())); // Delete any other pex that was there (when switching between pex styles). steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.FORCED, RmStep.Mode.RECURSIVE)); steps.add(new ShellStep(getProjectFilesystem().getRootPath()) { @Override/* ww w. jav a2 s . c o m*/ protected Optional<String> getStdin(ExecutionContext context) { try { return Optional.of(context.getObjectMapper() .writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, getResolver()::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, getResolver()::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, getResolver()::getAbsolutePath))))); } catch (IOException e) { throw new RuntimeException(e); } } @Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { ImmutableList.Builder<String> command = ImmutableList.builder(); command.addAll(builder.getCommandPrefix(getResolver())); command.addAll(builderArgs); command.add("--entry-point", mainModule); command.add("--interpreter"); if (starter.isPresent()) { command.add(getResolver().getAbsolutePath(starter.get()).toString()); } else { command.add(lua.getCommandPrefix(getResolver()).get(0)); } command.add(getProjectFilesystem().resolve(output).toString()); return command.build(); } @Override public String getShortName() { return "lua_package"; } }); return steps.build(); }
From source file:net.shibboleth.idp.saml.nameid.impl.AttributeSourcedSAML2NameIDGenerator.java
/** Constructor. */ public AttributeSourcedSAML2NameIDGenerator() { attributeContextLookupStrategy = Functions.compose( new ChildContextLookup<RelyingPartyContext, AttributeContext>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class)); delimiter = '@'; attributeSourceIds = Collections.emptyList(); setDefaultIdPNameQualifierLookupStrategy(new ResponderIdLookupFunction()); setDefaultSPNameQualifierLookupStrategy(new RelyingPartyIdLookupFunction()); useUnfilteredAttributes = false;//from w w w. jav a2s .c om }
From source file:org.apache.brooklyn.util.collections.CollectionFunctionals.java
public static <K> Function<Map<K, ?>, Integer> mapSize(Integer valueIfNull) { return Functions.compose(CollectionFunctionals.sizeFunction(valueIfNull), CollectionFunctionals.<K>keys()); }
From source file:net.shibboleth.idp.saml.nameid.impl.AttributeSourcedSAML1NameIdentifierGenerator.java
/** Constructor. */ public AttributeSourcedSAML1NameIdentifierGenerator() { attributeContextLookupStrategy = Functions.compose( new ChildContextLookup<RelyingPartyContext, AttributeContext>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class)); delimiter = '@'; attributeSourceIds = Collections.emptyList(); setDefaultIdPNameQualifierLookupStrategy(new ResponderIdLookupFunction()); setDefaultSPNameQualifierLookupStrategy(new RelyingPartyIdLookupFunction()); useUnfilteredAttributes = false;/*from w w w .j a v a 2s.c om*/ }
From source file:net.shibboleth.idp.saml.saml2.profile.impl.ProcessRequestedAuthnContext.java
/** Constructor. */ public ProcessRequestedAuthnContext() { authnRequestLookupStrategy = Functions.compose(new MessageLookup<>(AuthnRequest.class), new InboundMessageContextLookup()); ignoredContexts = Collections.singleton(AuthnContext.UNSPECIFIED_AUTHN_CTX); }
From source file:net.shibboleth.idp.attribute.filter.matcher.impl.ScriptedMatcher.java
/** * Constructor.//from w ww . j a v a 2s . c o m * * @param matchingScript script used to determine matching attribute values */ public ScriptedMatcher(@Nonnull final EvaluableScript matchingScript) { setScript(matchingScript); // Defaults to ProfileRequestContext -> RelyingPartyContext -> AttributeContext. prcLookupStrategy = Functions.compose(new ParentContextLookup<RelyingPartyContext, ProfileRequestContext>(), new ParentContextLookup<AttributeFilterContext, RelyingPartyContext>()); }
From source file:brooklyn.entity.software.ssh.SshCommandSensor.java
@Override public void apply(final EntityLocal entity) { super.apply(entity); if (LOG.isDebugEnabled()) { LOG.debug("Adding SSH sensor {} to {}", name, entity); }/* www . j a va 2 s. co m*/ Supplier<Map<String, String>> envSupplier = new Supplier<Map<String, String>>() { @Override public Map<String, String> get() { return MutableMap.copyOf(Strings.toStringMap(entity.getConfig(SoftwareProcess.SHELL_ENVIRONMENT))); } }; Supplier<String> commandSupplier = new Supplier<String>() { @Override public String get() { String finalCommand = command; String runDir = entity.getAttribute(SoftwareProcess.RUN_DIR); if (runDir != null) { finalCommand = "cd '" + runDir + "' && " + finalCommand; } return finalCommand; } }; SshPollConfig<T> pollConfig = new SshPollConfig<T>(sensor).period(period).env(envSupplier) .command(commandSupplier).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(input, getType(type)); } }, SshValueFunctions.stdout())); SshFeed.builder().entity(entity).onlyIfServiceUp().poll(pollConfig).build(); }
From source file:net.shibboleth.idp.saml.impl.nameid.LegacyNameIdentifierGenerator.java
/** * Constructor.//w ww . jav a 2 s. c o m * * @param clazz encoder class type */ protected LegacyNameIdentifierGenerator(@Nonnull Class<? extends NameIdentifierAttributeEncoder> clazz) { activationCondition = Predicates.alwaysTrue(); encoderType = Constraint.isNotNull(clazz, "Encoder class type cannot be null"); // ProfileRequestContext -> RelyingPartyContext -> AttributeContext attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class)); }
From source file:net.shibboleth.idp.saml.profile.impl.InitializeOutboundMessageContextForError.java
/** Constructor. */ public InitializeOutboundMessageContextForError() { // Default: outbound msg context -> SAMLBindingContext bindingContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLBindingContext.class, true), new OutboundMessageContextLookup()); relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class); }