Example usage for com.google.common.collect Collections2 transform

List of usage examples for com.google.common.collect Collections2 transform

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 transform.

Prototype

public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function) 

Source Link

Document

Returns a collection that applies function to each element of fromCollection .

Usage

From source file:gt.org.ms.controller.home.handlers.BusquedaNormalHandler.java

@Override
public List<PersonaDto> execute(final BusquedaNormalDto request) {

    List<Persona> s1 = repo.findAll(new Specification<Persona>() {
        @Override// www  . jav a  2 s.  com
        public Predicate toPredicate(Root<Persona> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return CriteriaBuilderPersona.get().withRoot(root).withCB(cb).withCq(cq).withDto(request).build();
        }
    });
    if (!isNull(request.getDireccion()) || !isNull(request.getDepartamento())
            || !isNull(request.getMunicipio())) {
        final Collection<Integer> munisLs = new ArrayList();
        if (!isNull(request.getDepartamento()) && isNull(request.getMunicipio())) {
            munisLs.addAll(Collections2.transform(areaGeograficaRepo.findAll(new Specification() {
                @Override
                public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) {
                    return cb.equal(root.get(AreaGeografica_.codigoPadre), request.getDepartamento());
                }
            }), new Function<AreaGeografica, Integer>() {
                @Override
                public Integer apply(AreaGeografica f) {
                    return f.getId();
                }
            }));
        }
        (s1 = (s1 == null ? new ArrayList<Persona>() : s1)).addAll(Collections2
                .filter(Collections2.transform(lugarRepo.findAll(new Specification<LugarResidencia>() {
                    @Override
                    public Predicate toPredicate(Root<LugarResidencia> root, CriteriaQuery<?> cq,
                            CriteriaBuilder cb) {
                        return CriteriaBuilderLugarResidencia.get().withDto(request).withCB(cb).withCq(cq)
                                .withMunisList(munisLs).withRoot(root).build();
                    }
                }), new Function<LugarResidencia, Persona>() {
                    @Override
                    public Persona apply(LugarResidencia f) {
                        return f.getFkPersona();
                    }
                }), new com.google.common.base.Predicate<Persona>() {
                    @Override
                    public boolean apply(Persona t) {
                        return t.getEstado().equals(Estado.ACTIVO);
                    }
                }));
    }
    return new PersonaDtoConverter().toDTO(s1);
}

From source file:net.shibboleth.idp.consent.audit.impl.CurrentConsentIsApprovedAuditExtractor.java

/** {@inheritDoc} */
@Override//from w  ww  .j  a v  a 2  s  .c o m
@Nullable
public Collection<Boolean> apply(@Nullable final ProfileRequestContext input) {
    final ConsentContext consentContext = consentContextLookupStrategy.apply(input);
    if (consentContext != null && !consentContext.getCurrentConsents().isEmpty()) {
        return Collections2.transform(consentContext.getCurrentConsents().values(),
                new Function<Consent, Boolean>() {
                    public Boolean apply(final Consent input) {
                        return input.isApproved();
                    }
                });
    } else {
        return Collections.emptyList();
    }
}

From source file:com.ning.billing.util.svcapi.tag.DefaultTagInternalApi.java

@Override
public List<Tag> getTags(final UUID objectId, final ObjectType objectType,
        final InternalTenantContext context) {
    return ImmutableList.<Tag>copyOf(Collections2.transform(
            tagDao.getTagsForObject(objectId, objectType, context), new Function<TagModelDao, Tag>() {
                @Override//from www  . j a  v a  2  s  .  co  m
                public Tag apply(final TagModelDao input) {
                    return TagModelDaoHelper.isControlTag(input.getTagDefinitionId())
                            ? new DefaultControlTag(ControlTagType.getTypeFromId(input.getTagDefinitionId()),
                                    objectType, objectId, input.getCreatedDate())
                            : new DescriptiveTag(input.getTagDefinitionId(), objectType, objectId,
                                    input.getCreatedDate());
                }
            }));
}

From source file:info.archinnov.achilles.statement.cache.CacheManager.java

public PreparedStatement getCacheForFieldsUpdate(Session session,
        Cache<StatementCacheKey, PreparedStatement> dynamicPSCache, CQLPersistenceContext context,
        List<PropertyMeta> pms) {
    Class<?> entityClass = context.getEntityClass();
    EntityMeta entityMeta = context.getEntityMeta();
    Set<String> fields = new HashSet<String>(Collections2.transform(pms, propertyExtractor));
    StatementCacheKey cacheKey = new StatementCacheKey(CacheType.UPDATE_FIELDS, entityMeta.getTableName(),
            fields, entityClass);//from   ww  w . j a  v  a2 s  .c  om
    PreparedStatement ps = dynamicPSCache.getIfPresent(cacheKey);
    if (ps == null) {
        ps = generator.prepareUpdateFields(session, entityMeta, pms);
        dynamicPSCache.put(cacheKey, ps);
    }
    return ps;
}

From source file:org.vootoo.client.netty.util.ProtobufUtil.java

public static Collection<ContentStream> toSolrContentStreams(SolrProtocol.SolrRequest request) {
    return Collections2.transform(request.getContentStreamList(),
            new Function<SolrProtocol.ContentStream, ContentStream>() {
                @Override//w w w  . ja v a  2 s  .com
                public ContentStream apply(SolrProtocol.ContentStream input) {
                    return new ProtobufContentStream(input);
                }
            });
}

From source file:com.romeikat.datamessie.core.base.ui.component.DocumentProcessingStateChoiceProvider.java

@Override
public Collection<DocumentProcessingState> toChoices(final Collection<String> ids) {
    final Map<Integer, DocumentProcessingState> states = getStates();
    final Function<String, DocumentProcessingState> toChoicesFunction = new Function<String, DocumentProcessingState>() {

        @Override//from   w ww. jav  a  2  s .c om
        public DocumentProcessingState apply(final String id) {
            return states.get(Integer.parseInt(id));
        }

    };
    final Collection<DocumentProcessingState> choices = Collections2.transform(ids, toChoicesFunction);
    return choices;
}

From source file:org.killbill.billing.invoice.api.invoice.DefaultInvoicePaymentApi.java

@Override
public List<InvoicePayment> getInvoicePaymentsByAccount(final UUID accountId, final TenantContext context) {
    return ImmutableList
            .<InvoicePayment>copyOf(Collections2.transform(
                    dao.getInvoicePaymentsByAccount(internalCallContextFactory
                            .createInternalTenantContext(accountId, ObjectType.ACCOUNT, context)),
                    new Function<InvoicePaymentModelDao, InvoicePayment>() {
                        @Override
                        public InvoicePayment apply(final InvoicePaymentModelDao input) {
                            return new DefaultInvoicePayment(input);
                        }/*www  .  ja va  2 s  .c  om*/
                    }));
}

From source file:uk.ac.ebi.atlas.solr.query.conditions.DifferentialConditionsSearchService.java

public Collection<IndexedAssayGroup> findContrasts(String queryString) {

    try {/*from   w ww.j  a  va 2  s  .  c  om*/

        StopWatch stopWatch = new StopWatch(getClass().getSimpleName());
        stopWatch.start();

        QueryResponse queryResponse = differentialConditionsSolrServer.query(queryBuilder.build(queryString),
                SolrRequest.METHOD.POST);
        List<DifferentialCondition> beans = queryResponse.getBeans(DifferentialCondition.class);

        stopWatch.stop();
        LOGGER.info(String.format("<findContrasts: %s> %s results, took %s seconds", queryString, beans.size(),
                stopWatch.getTotalTimeSeconds()));

        return Collections2.transform(beans, new Function<DifferentialCondition, IndexedAssayGroup>() {
            @Override
            public IndexedAssayGroup apply(DifferentialCondition conditionProperty) {
                return new IndexedAssayGroup(conditionProperty.getExperimentAccession(),
                        conditionProperty.getContrastId());
            }
        });
    } catch (SolrServerException e) {
        throw new IllegalStateException("Conditions index query failed!", e);
    }
}

From source file:org.polarsys.reqcycle.traceability.builder.impl.ProxyResolutionBuilderCallbackWrapper.java

@Override
public void newUpwardRelation(final Object traceabilityObject, final Object resource, final Object source,
        final List<? extends Object> targets, final TType label) {
    final Object newSource = this.proxyResolverFunction.apply(source);
    final List<Object> newTargets = new LinkedList<Object>(
            Collections2.transform(targets, this.proxyResolverFunction));
    this.callBack.newUpwardRelation(traceabilityObject, resource, newSource, newTargets, label);
}

From source file:org.opendaylight.netconf.cli.reader.impl.ContainerReader.java

@Override
public List<NormalizedNode<?, ?>> readWithContext(final ContainerSchemaNode containerNode)
        throws IOException, ReadingException {
    console.formatLn("Submit child nodes for container: %s, %s", containerNode.getQName().getLocalName(),
            Collections2.transform(containerNode.getChildNodes(), new Function<DataSchemaNode, String>() {
                @Override/*from   w ww . j a va 2  s  .c  o m*/
                public String apply(final DataSchemaNode input) {
                    return input.getQName().getLocalName();
                }
            }));
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder = ImmutableContainerNodeBuilder
            .create();
    builder.withNodeIdentifier(new NodeIdentifier(containerNode.getQName()));

    final ArrayList<NormalizedNode<?, ?>> nodesToAdd = new ArrayList<>();
    final SeparatedNodes separatedNodes = SeparatedNodes.separateNodes(containerNode, getReadConfigNode());
    for (final DataSchemaNode childNode : sortChildren(separatedNodes.getMandatoryNotKey())) {
        final List<NormalizedNode<?, ?>> redNodes = argumentHandlerRegistry
                .getGenericReader(getSchemaContext(), getReadConfigNode()).read(childNode);
        if (redNodes.isEmpty()) {
            console.formatLn("No data specified for mandatory element %s.",
                    childNode.getQName().getLocalName());
            return Collections.emptyList();
        } else {
            nodesToAdd.addAll(redNodes);
        }
    }

    for (final DataSchemaNode childNode : sortChildren(separatedNodes.getOthers())) {
        nodesToAdd.addAll(argumentHandlerRegistry.getGenericReader(getSchemaContext(), getReadConfigNode())
                .read(childNode));
    }
    return Collections.<NormalizedNode<?, ?>>singletonList(builder.withValue((ArrayList) nodesToAdd).build());
}