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:edu.byu.nlp.data.docs.DocPipes.java
public static Function<String, Iterable<String>> McCallumAndNigamTokenizer() { return Functions.compose(new RegexpTokenizer("[a-zA-Z]+"), new Downcase()); }
From source file:com.urswolfer.intellij.plugin.gerrit.ui.GerritSelectRevisionInfoColumn.java
private List<String> getRevisions(ChangeInfo changeInfo) { Set<Map.Entry<String, RevisionInfo>> revisions = ImmutableSortedSet .copyOf(RevisionInfos.MAP_ENTRY_COMPARATOR, changeInfo.revisions.entrySet()); return Lists.newArrayList(Iterables.transform(revisions, Functions.compose(getRevisionLabelFunction(changeInfo), MAP_ENTRY_TO_PAIR))); }
From source file:com.eucalyptus.auth.euare.UserPrincipalImpl.java
public UserPrincipalImpl(final UserEntity user) throws AuthException { final List<GroupEntity> groups = user.getGroups(); final AccountEntity account = groups.get(0).getAccount(); final List<PolicyVersion> policies = Lists.newArrayList(); if (user.isEnabled()) { if (DatabaseAuthUtils.isAccountAdmin(user.getName())) { policies.add(PolicyVersions.getAdministratorPolicy()); } else {//from w ww. java 2 s .c o m for (final GroupEntity group : groups) { if (group.isUserGroup()) { Iterables.addAll(policies, Iterables.transform(group.getPolicies(), Functions.compose( PolicyVersions.policyVersion(PolicyScope.User, new EuareResourceName(account.getAccountNumber(), PolicySpec.IAM_RESOURCE_USER, user.getPath(), user.getName()).toString()), PolicyTransform.INSTANCE))); } } for (final GroupEntity group : groups) { if (!group.isUserGroup()) { Iterables.addAll(policies, Iterables.transform(group.getPolicies(), Functions.compose( PolicyVersions.policyVersion(PolicyScope.Group, new EuareResourceName(account.getAccountNumber(), PolicySpec.IAM_RESOURCE_GROUP, group.getPath(), group.getName()).toString()), PolicyTransform.INSTANCE))); } } } UserEntity admin; try { admin = DatabaseAuthUtils.getUniqueUser(User.ACCOUNT_ADMIN, account.getName()); } catch (Exception e) { throw new AuthException(e); } if (admin != null) { for (final GroupEntity group : admin.getGroups()) { if (group.isUserGroup()) { Iterables .addAll(policies, Iterables.transform(group.getPolicies(), Functions.compose( PolicyVersions.policyVersion(PolicyScope.Account, account.getAccountNumber()), PolicyTransform.INSTANCE))); } } } } this.name = user.getName(); this.path = user.getPath(); this.userId = user.getUserId(); this.authenticatedId = user.getUserId(); this.canonicalId = account.getCanonicalId(); this.token = user.getToken(); this.accountAlias = account.getName(); this.accountNumber = account.getAccountNumber(); this.enabled = user.isEnabled(); this.accountAdmin = DatabaseAuthUtils.isAccountAdmin(user.getName()); this.systemAdmin = com.eucalyptus.auth.Accounts.isSystemAccount(account.getName()); this.systemUser = systemAdmin; this.password = user.getPassword(); this.passwordExpires = password == null ? null : Objects.firstNonNull(user.getPasswordExpires(), Long.MAX_VALUE); this.keys = ImmutableList.copyOf( Iterables.filter(Iterables.transform(user.getKeys(), ekeyWrapper(this)), AccessKeys.isActive())); this.certificates = ImmutableList .copyOf(Iterables.filter(Iterables.transform(user.getCertificates(), ecertWrapper(this)), propertyPredicate(true, active()))); this.principalPolicies = ImmutableList.copyOf(policies); this.ptag = null; }
From source file:net.derquinse.common.meta.MetaProperty.java
/** * Returns the composition of this property function with another that tranform the value. * @param g the second function to apply * @return The composition of this funcion and {@code g} *///w w w. j av a2 s . c om public final <V> Function<C, V> compose(Function<T, V> g) { return Functions.compose(g, this); }
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( Mapper<K1, V1, K2, V2> mapper, Reducer<K2, V2, K2, V2> combiner, Reducer<K2, V2, K3, V3> reducer, Comparator<K2> comparator, Comparator<K3> comparator2) { return Functions.compose(asFunction(reducer, comparator2), Functions.compose(asFunction(combiner, comparator), asFunction(mapper, comparator))); }
From source file:org.apache.isis.viewer.wicket.ui.components.entity.header.EntityHeaderPanel.java
@SuppressWarnings("deprecation") private static Filter<ObjectAction> memberOrderNameNotAssociation(final ObjectSpecification adapterSpec) { final List<ObjectAssociation> associations = adapterSpec.getAssociations(Contributed.INCLUDED); final List<String> associationNames = Lists.transform(associations, Functions.compose(StringFunctions.toLowerCase(), ObjectAssociation.Functions.toName())); final List<String> associationIds = Lists.transform(associations, Functions.compose(StringFunctions.toLowerCase(), ObjectAssociation.Functions.toId())); return new Filter<ObjectAction>() { @Override//from w ww .j av a 2s. c o m public boolean accept(ObjectAction t) { final MemberOrderFacet memberOrderFacet = t.getFacet(MemberOrderFacet.class); if (memberOrderFacet == null || Strings.isNullOrEmpty(memberOrderFacet.name())) { return true; } String memberOrderName = StringFunctions.toLowerCase().apply(memberOrderFacet.name()); return !associationNames.contains(memberOrderName) && !associationIds.contains(memberOrderName); } }; }
From source file:net.shibboleth.idp.saml.impl.profile.saml2.AddAttributeStatementToAssertion.java
/** Constructor. */ public AddAttributeStatementToAssertion() { statementInOwnAssertion = false;/*ww w . jav a 2 s . co m*/ ignoringUnencodableAttributes = true; attributeContextLookupStrategy = Functions.compose(new ChildContextLookup<>(AttributeContext.class), new ChildContextLookup<ProfileRequestContext, RelyingPartyContext>(RelyingPartyContext.class)); responseLookupStrategy = Functions.compose(new MessageLookup<>(Response.class), new OutboundMessageContextLookup()); idGeneratorLookupStrategy = new IdentifierGenerationStrategyLookupFunction(); issuerLookupStrategy = new ResponderIdLookupFunction(); }
From source file:net.shibboleth.idp.saml.impl.profile.saml1.AddAuthenticationStatementToAssertion.java
/** Constructor. */ public AddAuthenticationStatementToAssertion() { statementInOwnAssertion = false;/*from w w w . j a v a 2 s. c om*/ responseLookupStrategy = Functions.compose(new MessageLookup<>(Response.class), new OutboundMessageContextLookup()); idGeneratorLookupStrategy = new IdentifierGenerationStrategyLookupFunction(); issuerLookupStrategy = new ResponderIdLookupFunction(); methodLookupStrategy = new DefaultPrincipalDeterminationStrategy<>(AuthenticationMethodPrincipal.class, new AuthenticationMethodPrincipal(AuthenticationStatement.UNSPECIFIED_AUTHN_METHOD)); }
From source file:de.dfki.kiara.Util.java
public static ClassAndConverters getSerializationTypeAndCreateConverters(java.lang.reflect.Type type) { if (type == null) { throw new NullPointerException("type"); }/*from w ww . j ava2 s.c o m*/ boolean isFuture = futureTok.isAssignableFrom(type); if (!(type instanceof ParameterizedType) || !isFuture) { return new ClassAndConverters(TypeToken.of(type), new Function<Object, Object>() { @Override public Object apply(Object input) { return Futures.immediateFuture(input); } }, null); } TypeToken<?> typeToken = TypeToken.of(type); if (typeToken != null) { ClassAndConverters conv; synchronized (convCache) { conv = convCache.get(typeToken); } if (conv != null) { return conv; } } java.lang.reflect.Type paramType = ((ParameterizedType) type).getActualTypeArguments()[0]; boolean isListenableFuture = listenableFutureTok.isAssignableFrom(type); Function<Object, Object> paramConverter = null; Function<Object, Object> serializationToParamConverter = null; if (!isListenableFuture) { // rule ListenableFuture<X> -> Future<X> paramConverter = new ConvertFutureToListenableFuture(); } if (isFuture) { // rule X -> ListenableFuture<X> serializationToParamConverter = new ConvertTypeToListenableFuture(); } while (isFuture) { isFuture = futureTok.isAssignableFrom(paramType); if (isFuture) { paramType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; isListenableFuture = listenableFutureTok.isAssignableFrom(paramType); if (!isListenableFuture) { Function<Object, Object> tmp = getFutureToListenableFutureConverter(); if (paramConverter == null) { paramConverter = tmp; } else { paramConverter = Functions.compose(tmp, paramConverter); } } Function<Object, Object> tmp = new ConvertTypeToListenableFuture(); if (serializationToParamConverter == null) { serializationToParamConverter = tmp; } else { serializationToParamConverter = Functions.compose(tmp, serializationToParamConverter); } } } ClassAndConverters conv = new ClassAndConverters(TypeToken.of(paramType), paramConverter == null ? Functions.<Object>identity() : paramConverter, serializationToParamConverter); if (typeToken != null) { synchronized (convCache) { convCache.put(typeToken, conv); } } return conv; }
From source file:com.nesscomputing.hbase.spill.SpillController.java
private void spill(final List<Callable<Put>> elements) { final String fileName = String.format("%s-%s-%05d", spillName, spillingId, spillingCount.getAndIncrement()); final File spillFile = new File(spillingSrcDir, fileName + ".temp"); OutputStream os = null;// w w w . j a v a 2 s . com try { os = new FileOutputStream(spillFile); BinaryConverter.writeInt(os, 1); // File format version 1 BinaryConverter.writeInt(os, elements.size()); // Number of elements in this file. BinaryConverter.writeLong(os, System.currentTimeMillis()); // Timestamp in millis final List<byte[]> data = Lists.transform(elements, Functions.compose(BinaryConverter.PUT_WRITE_FUNCTION, HBaseWriter.CALLABLE_FUNCTION)); for (byte[] d : data) { os.write(d); } os.flush(); Closeables.closeQuietly(os); if (!spillFile.renameTo(new File(spillingSrcDir, fileName + ".spilled"))) { LOG.warn("Could not rename spillfile %s!", spillFile.getAbsolutePath()); } spillsOk.incrementAndGet(); } catch (IOException ioe) { LOG.warnDebug(ioe, "Could not spill %d elements to %s.temp, losing them!", elements.size(), fileName); spillsLost.addAndGet(elements.size()); if (!spillFile.delete()) { LOG.warn("Could not delete bad spillfile %s", spillFile.getAbsolutePath()); } spillsFailed.incrementAndGet(); } finally { Closeables.closeQuietly(os); } }