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.commercehub.bamboo.plugins.grailswrapper.GrailsWrapperTask.java
@NotNull private Iterable<List<String>> parseCommands(@NotNull TaskContext taskContext) { ConfigurationMap configurationMap = taskContext.getConfigurationMap(); String rawCommands = configurationMap.get(GrailsWrapperTaskConfigurator.COMMANDS); String rawCommonOpts = configurationMap.get(GrailsWrapperTaskConfigurator.COMMON_OPTIONS); String commonOpts = Utils.ensureEndsWith(Strings.nullToEmpty(rawCommonOpts), " "); Splitter splitter = Splitter.onPattern("[\r\n]").trimResults().omitEmptyStrings(); Iterable<String> splitCommands = splitter.split(rawCommands); Function<String, String> commonOptsFunction = new StringPrependFunction(commonOpts); Function<String, List<String>> tokenizeFunction = CommandlineStringUtils.tokeniseCommandlineFunction(); return Iterables.transform(splitCommands, Functions.compose(tokenizeFunction, commonOptsFunction)); }
From source file:de.flapdoodle.guava.Transformations.java
public static <S, D> Function<S, Collection<? extends D>> asCollection(Function<S, D> transformation) { return Functions.compose(new ValueToCollection<D>(), transformation); }
From source file:com.isotrol.impe3.api.DevicesInPortal.java
/** * Excludes one device from the collection. * @param deviceId Device id to exclude. * @return The filtered collection./*from w ww . ja va 2 s . c o m*/ */ public final DevicesInPortal excludeDeviceId(UUID deviceId) { checkNotNull(deviceId, "Null devices not allowed"); if (!containsDeviceId(deviceId)) { return this; } if (size() == 1) { return EMPTY; } return new Filter(this, Predicates.compose(not(equalTo(deviceId)), Functions.compose(Device.ID, DeviceInPortal.DEVICE))); }
From source file:com.palantir.atlasdb.sweep.BackgroundSweeper.java
private Optional<SweepProgressRowResult> chooseNextTableToSweep(Transaction t) { Set<String> allTables = Sets.difference(kvs.getAllTableNames(), AtlasDbConstants.hiddenTables); SweepPriorityTable priorityTable = tableFactory.getSweepPriorityTable(t); List<SweepPriorityRowResult> results = priorityTable.getAllRowsUnordered().immutableCopy(); Set<String> unsweptTables = Sets.difference(allTables, ImmutableSet.copyOf(Iterables.transform(results, Functions .compose(SweepPriorityRow.getFullTableNameFun(), SweepPriorityRowResult.getRowNameFun())))); Optional<String> optTableName = getTableToSweep(unsweptTables, results); if (!optTableName.isPresent()) { return Optional.absent(); }/*from w ww. j a v a 2s . c om*/ String tableName = optTableName.get(); RowResult<byte[]> rawResult = RowResult.<byte[]>create(SweepProgressRow.of(0).persistToBytes(), ImmutableSortedMap.<byte[], byte[]>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(SweepProgressTable.SweepProgressNamedColumn.FULL_TABLE_NAME.getShortName(), SweepProgressTable.FullTableName.of(tableName).persistValue()) .build()); // We zero out the write count when we start sweeping a table, then reduce // it when we finish sweeping to account for new writes made during sweep that // were likely swept along the way. priorityTable.putWriteCount(SweepPriorityRow.of(tableName), 0L); log.info("Now starting to sweep {}.", tableName); return Optional.of(SweepProgressRowResult.of(rawResult)); }
From source file:net.automatalib.util.ts.copy.TSCopy.java
/** * Copies a {@link UniversalAutomaton} to a {@link MutableAutomaton} with possibly heterogeneous input alphabets and state and transition * properties./* w ww .j a v a 2 s. c om*/ * * @param method the traversal method to use * @param in the input transition system * @param limit the traversal limit, a value less than 0 means no limit * @param inputs the inputs to consider * @param out the output automaton * @param inputsMapping the transformation for input symbols * @param spTransform the transformation for state properties * @param tpTransform the transformation for transition properties * @param stateFilter the filter predicate for states * @param transFilter the filter predicate for transitions * @return a mapping from old to new states */ public static <S1, I1, T1, SP1, TP1, S2, I2, T2, SP2, TP2> Mapping<S1, S2> copy(TSTraversalMethod method, UniversalTransitionSystem<S1, ? super I1, T1, ? extends SP1, ? extends TP1> in, int limit, Collection<? extends I1> inputs, MutableAutomaton<S2, I2, T2, ? super SP2, ? super TP2> out, Function<? super I1, ? extends I2> inputsMapping, Function<? super SP1, ? extends SP2> spTransform, Function<? super TP1, ? extends TP2> tpTransform, Predicate<? super S1> stateFilter, TransitionPredicate<? super S1, ? super I1, ? super T1> transFilter) { Function<? super S1, ? extends SP2> spMapping = (spTransform == null) ? null : Functions.compose(spTransform, TS.stateProperties(in)); Function<? super T1, ? extends TP2> tpMapping = (tpTransform == null) ? null : Functions.compose(tpTransform, TS.transitionProperties(in)); return rawCopy(method, in, limit, inputs, out, inputsMapping, spMapping, tpMapping, stateFilter, transFilter); }
From source file:net.shibboleth.idp.saml.profile.impl.PopulateBindingAndEndpointContexts.java
/** Constructor. */ public PopulateBindingAndEndpointContexts() { 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 -> SAMLArtifactContext artifactContextLookupStrategy = Functions.compose(new ChildContextLookup<>(SAMLArtifactContext.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())); artifactImpliesSecureChannel = true; }
From source file:org.eclipse.emf.compare.match.update.Updater.java
/** * Reorders the elements in oldValues so that their relative order matches the one of their equivalent in * newValues./*from w w w .j ava 2 s. c o m*/ * <p> * We do this simply by sorting the oldValues list according to the index of the corresponding element in * the newValues list. */ private void reorderMatchingElements(EList<EObject> oldValues, EList<EObject> newValues, BiMap<EObject, EObject> matches) { Map<EObject, Integer> targetIndices = Maps.newHashMapWithExpectedSize(newValues.size()); for (int i = 0; i < newValues.size(); i++) { targetIndices.put(newValues.get(i), i); } Function<EObject, Integer> matchingElementIndex = Functions.compose(Functions.forMap(targetIndices), Functions.forMap(matches)); ECollections.sort(oldValues, Ordering.natural().onResultOf(matchingElementIndex)); }
From source file:org.jclouds.joyent.cloudapi.v6_5.domain.Dataset.java
/** * Contains a grouping of various minimum requirements for provisioning a machine with this * dataset. For example 'password' indicates that a password must be provided. * //from w w w.ja v a 2s .c om * <h4>Note</h4> * * requirements can contain arbitrarily complex values. If the value has structure, you should * use {@link #getRequirementsAsJsonLiterals} */ public Map<String, String> getRequirements() { return Maps.transformValues(requirements, Functions.compose(Functions.toStringFunction(), unquoteString)); }
From source file:org.apache.aurora.scheduler.async.preemptor.PendingTaskProcessor.java
private List<TaskGroupKey> fetchIdlePendingGroups(StoreProvider store) { Multiset<TaskGroupKey> taskGroupCounts = HashMultiset .create(FluentIterable.from(store.getTaskStore().fetchTasks(Query.statusScoped(PENDING))) .filter(Predicates.and(isIdleTask, Predicates.not(hasCachedSlot))) .transform(Functions.compose(ASSIGNED_TO_GROUP_KEY, SCHEDULED_TO_ASSIGNED))); return getPreemptionSequence(taskGroupCounts); }
From source file:com.eucalyptus.simpleworkflow.ActivityTask.java
public Pair<String, Date> calculateNextTimeout() { final Iterable<Pair<String, Optional<Long>>> taggedTimeouts = Iterables.filter(Lists.newArrayList( Pair.ropair("SCHEDULE_TO_CLOSE", toTimeout(getCreationTimestamp(), getScheduleToCloseTimeout())), Pair.ropair("SCHEDULE_TO_START", toTimeout(getCreationTimestamp(), getScheduleToStartTimeout())), getState() == State.Active ? Pair.ropair("START_TO_CLOSE", toTimeout(getStartedTimestamp(), getStartToCloseTimeout())) : null,// w w w.j a v a2 s .c om getState() == State.Active ? Pair.ropair("HEARTBEAT", toTimeout(getLastUpdateTimestamp(), getHeartbeatTimeout())) : null), Predicates.notNull()); final Function<Pair<String, Optional<Long>>, Long> timeExtractor = Functions .compose(CollectionUtils.<Long>optionalOrNull(), Pair.<String, Optional<Long>>right()); final Long timeout = CollectionUtils.reduce( CollectionUtils.fluent(taggedTimeouts).transform(timeExtractor).filter(Predicates.notNull()), Long.MAX_VALUE, CollectionUtils.lmin()); final String tag = Iterables .tryFind(taggedTimeouts, CollectionUtils.propertyPredicate(timeout, timeExtractor)) .transform(Pair.<String, Optional<Long>>left()).or("SCHEDULE_TO_CLOSE"); return timeout == Long.MAX_VALUE ? null : Pair.pair(tag, new Date(timeout)); }