public void testComposeOfFunctionsIsAssociative() { Map<Float, String> m = ImmutableMap.of(4.0f, "A", 3.0f, "B", 2.0f, "C", 1.0f, "D"); Function<? super Integer, Boolean> h = Functions.constant(Boolean.TRUE); Function<? super String, Integer> g = new HashCodeFunction(); Function<Float, String> f = Functions.forMap(m, "F"); Function<Float, Boolean> c1 = Functions.compose(Functions.compose(h, g), f); Function<Float, Boolean> c2 = Functions.compose(h, Functions.compose(g, f)); // Might be nice (eventually) to have: // assertEquals(c1, c2); // But for now, settle for this: assertEquals(c1.hashCode(), c2.hashCode()); assertEquals(c1.apply(1.0f), c2.apply(1.0f)); assertEquals(c1.apply(5.0f), c2.apply(5.0f)); }
public void testCompositionWildcard() { Map<String, Integer> mapJapaneseToInteger = Maps.newHashMap(); Function<String, Integer> japaneseToInteger = Functions.forMap(mapJapaneseToInteger); Function<Object, String> numberToSpanish = Functions.constant("Yo no se"); Function<String, String> japaneseToSpanish = Functions.compose(numberToSpanish, japaneseToInteger); }
@Override public Ordering<Element> enclosedBy(Element element) { if (element instanceof ElementImpl && Iterables.all(element.getEnclosedElements(), Predicates.instanceOf(ElementImpl.class))) { ElementImpl implementation = (ElementImpl) element; if (implementation._binding instanceof SourceTypeBinding) { SourceTypeBinding sourceBinding = (SourceTypeBinding) implementation._binding; return Ordering.natural().onResultOf( Functions.compose(bindingsToSourceOrder(sourceBinding), this)); } } return DEFAULT_PROVIDER.enclosedBy(element); }
public static final class Literal implements Function<Object, String> { @Override public String apply(Object input) { return StaticEnvironment.processing().getElementUtils().getConstantExpression(input); } public final Function<Object, String> string = new Function<Object, String>() { @Override public String apply(Object input) { return StringLiterals.toLiteral(String.valueOf(input)); } }; public final Function<Number, String> hex = new Function<Number, String>() { @Override public String apply(Number input) { if (input instanceof Long) { return "0x" + Long.toHexString(input.longValue()) + "L"; } if (input instanceof Integer) { return "0x" + Integer.toHexString(input.intValue()); } throw new IllegalArgumentException("unsupported non integer or long " + input); } @Override public String toString() { return Literal.this.toString() + ".hex"; }
public void testComposeOfPredicateAndFunctionIsAssociative() { Map<Float, String> m = ImmutableMap.of(4.0f, "A", 3.0f, "B", 2.0f, "C", 1.0f, "D"); Predicate<? super Integer> h = Predicates.equalTo(42); Function<? super String, Integer> g = new HashCodeFunction(); Function<Float, String> f = Functions.forMap(m, "F"); Predicate<Float> p1 = Predicates.compose(Predicates.compose(h, g), f); Predicate<Float> p2 = Predicates.compose(h, Functions.compose(g, f)); // Might be nice (eventually) to have: // assertEquals(p1, p2); // But for now, settle for this: assertEquals(p1.hashCode(), p2.hashCode()); assertEquals(p1.apply(1.0f), p2.apply(1.0f)); assertEquals(p1.apply(5.0f), p2.apply(5.0f)); }
@GwtIncompatible // SerializableTester public void testComposition_includeReserializabled() { Map<String, Integer> mJapaneseToInteger = Maps.newHashMap(); mJapaneseToInteger.put("Ichi", 1); mJapaneseToInteger.put("Ni", 2); mJapaneseToInteger.put("San", 3); Function<String, Integer> japaneseToInteger = Functions.forMap(mJapaneseToInteger); Map<Integer, String> mIntegerToSpanish = Maps.newHashMap(); mIntegerToSpanish.put(1, "Uno"); mIntegerToSpanish.put(3, "Tres"); mIntegerToSpanish.put(4, "Cuatro"); Function<Integer, String> integerToSpanish = Functions.forMap(mIntegerToSpanish); Function<String, String> japaneseToSpanish = Functions.compose(integerToSpanish, japaneseToInteger); new EqualsTester() .addEqualityGroup( japaneseToSpanish, Functions.compose(integerToSpanish, japaneseToInteger), SerializableTester.reserialize(japaneseToSpanish)) .addEqualityGroup(japaneseToInteger) .addEqualityGroup(integerToSpanish) .addEqualityGroup(Functions.compose(japaneseToInteger, integerToSpanish)) .testEquals(); }
/** * Find a biome that matches the given input name. * * @param biomes a list of biomes * @param name the name to test * @param registry a biome registry * @return a biome or null */ @Nullable public static BaseBiome findBiomeByName(Collection<BaseBiome> biomes, String name, BiomeRegistry registry) { checkNotNull(biomes); checkNotNull(name); checkNotNull(registry); Function<String, ? extends Number> compare = new LevenshteinDistance(name, false, LevenshteinDistance.STANDARD_CHARS); WeightedChoice<BaseBiome> chooser = new WeightedChoice<>(Functions.compose(compare::apply, new BiomeName(registry)), 0); for (BaseBiome biome : biomes) { chooser.consider(biome); } Optional<Choice<BaseBiome>> choice = chooser.getChoice(); if (choice.isPresent() && choice.get().getScore() <= 1) { return choice.get().getValue(); } else { return null; } }
Functions.compose(integerToSpanish, japaneseToInteger); .addEqualityGroup(japaneseToSpanish, Functions.compose(integerToSpanish, japaneseToInteger)) .addEqualityGroup(japaneseToInteger) .addEqualityGroup(integerToSpanish) .addEqualityGroup(Functions.compose(japaneseToInteger, integerToSpanish)) .testEquals();
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); } ); } return postProcessingFn; }
Collection<byte[]> rows = Collections2.transform( Collections2.transform(tableNames, t -> t.getQualifiedName()), Functions.compose(Persistables.persistToBytesFunction(), SweepPriorityRow.fromFullTableNameFun())); Map<Cell, Value> oldWriteCounts = delegate().getRows(SWEEP_PRIORITY_TABLE, rows, SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.WRITE_COUNT), Long.MAX_VALUE);
/** * only add the overhead of looking up ips when we have enabled the auto-allocate functionality */ @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); }
/** * Transform a function that returns a Throwable to one that returns a failed promise. */ private static <A, B> Function<A, Promise<B>> reject(final Function<A, ? extends Throwable> f) { return compose(BlobStoreAttachmentStore.<B>reject(), f); }
private Collection<ApplicationUser> getRecentlyUsedUsers(ApplicationUser user) { Function<String, ApplicationUser> toUser = name -> name == null ? null : userManager.getUserByName(name); Function<UserHistoryItem, ApplicationUser> historyItemToUser = compose(toUser, UserHistoryItem.GET_ENTITY_ID); return Sets.newLinkedHashSet(filter(transform(userHistoryManager.getHistory(UserHistoryItem.USED_USER, user), historyItemToUser), notNull())); }
/** Constructor. */ public AddNotBeforeConditionToAssertions() { responseLookupStrategy = Functions.compose(new MessageLookup<>(SAMLObject.class), new OutboundMessageContextLookup()); }
/** Constructor. */ public EncryptAttributes() { responseLookupStrategy = Functions.compose(new MessageLookup<>(StatusResponseType.class), new OutboundMessageContextLookup()); }
/** Constructor. */ public InitializeRelyingPartyContextFromSAMLPeer() { relyingPartyContextCreationStrategy = Functions.compose( new ChildContextLookup<InOutOperationContext, RelyingPartyContext>(RelyingPartyContext.class, true), new RecursiveTypedParentContextLookup<MessageContext,InOutOperationContext>(InOutOperationContext.class) ); peerEntityContextLookupStrategy = Functions.compose( new ChildContextLookup<InOutOperationContext, SAMLPeerEntityContext>(SAMLPeerEntityContext.class), new RecursiveTypedParentContextLookup<MessageContext,InOutOperationContext>(InOutOperationContext.class) ); }
/** Constructor. */ public SelectRelyingPartyConfiguration() { relyingPartyContextLookupStrategy = Functions.compose( new ChildContextLookup<InOutOperationContext, RelyingPartyContext>(RelyingPartyContext.class), new RecursiveTypedParentContextLookup<MessageContext,InOutOperationContext>(InOutOperationContext.class) ); }
/** * Constructor. * * @param mapper mapper used to consume designators */ public FilterByQueriedAttributeDesignators(@Nonnull final SAML1AttributeDesignatorsMapperService mapper) { mapperService = Constraint.isNotNull(mapper, "MapperService cannot be null"); attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext,RelyingPartyContext>(RelyingPartyContext.class)); requestLookupStrategy = Functions.compose(new MessageLookup(Request.class), new InboundMessageContextLookup()); }
/** Constructor. */ public AddStatusToResponse() { responseLookupStrategy = Functions.compose(new MessageLookup<>(StatusResponseType.class), new OutboundMessageContextLookup()); detailedErrorsCondition = Predicates.alwaysFalse(); defaultStatusCodes = Collections.emptyList(); detailedErrors = false; }
/** Constructor. */ public BaseAddAttributeStatementToAssertion() { statementInOwnAssertion = false; ignoringUnencodableAttributes = true; attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext,RelyingPartyContext>(RelyingPartyContext.class)); idGeneratorLookupStrategy = new IdentifierGenerationStrategyLookupFunction(); issuerLookupStrategy = new ResponderIdLookupFunction(); }