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

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

Introduction

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

Prototype



@CheckReturnValue
public static <E> Collection<E> filter(Collection<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of unfiltered that satisfy a predicate.

Usage

From source file:org.ow2.play.governance.platform.user.service.rest.PatternService.java

@Override
public Response patterns() {
    User user = getUser();//from  ww w  .j  a  va  2 s.  c  om
    List<Resource> resources = user.resources;
    Collection<Resource> filtered = Collections2.filter(resources, new Predicate<Resource>() {
        @Override
        public boolean apply(Resource input) {
            return input.name.equals(Constants.PATTERN_RESOURCE_NAME);
        }
    });

    Collection<Pattern> patterns = Collections2.transform(filtered, new Function<Resource, Pattern>() {
        @Override
        public Pattern apply(Resource patternResource) {
            try {
                org.ow2.play.governance.api.bean.Pattern pattern = patternRegistry
                        .get(PatternHelper.getPatternIDFromBaseURI(patternResource.uri));
                Pattern out = new Pattern();
                out.data = pattern.content;
                out.id = pattern.id;
                out.resourceUrl = getResourceURI(out);
                out.date = patternResource.date;

                return out;
            } catch (GovernanceExeption e) {
                // ...
                return new Pattern();
            }
        }
    });

    return ok(patterns.toArray(new Pattern[patterns.size()]));
}

From source file:org.opensaml.xmlsec.criterion.EncryptionConfigurationCriterion.java

/**
 * Constructor.//from www .  j  a va2 s.c o m
 *
 * @param configurations varargs array of configuration instances
 */
public EncryptionConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty EncryptionConfiguration... configurations) {
    Constraint.isNotNull(configurations, "List of configurations cannot be null");
    configs = new ArrayList<>(Collections2.filter(Arrays.asList(configurations), Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");
}

From source file:org.opensaml.xmlsec.criterion.DecryptionConfigurationCriterion.java

/**
 * Constructor./*from w w w.  jav  a 2  s .  c  o m*/
 *
 * @param configurations varargs array of configuration instances
 */
public DecryptionConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty DecryptionConfiguration... configurations) {
    Constraint.isNotNull(configurations, "List of configurations cannot be null");
    configs = new ArrayList<>(Collections2.filter(Arrays.asList(configurations), Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");
}

From source file:org.watterssoft.appsupport.landing.service.LandingService.java

public LandingDTO getLandingPageForUser(String username, Date fromDate) {
    List<UserApplication> userApplications = applicationService.getAllUserApplications(username);
    long openTicketsForApplications = 0, inprogressTicketsForApplication = 0, closedTicketsForApplications = 0;
    for (UserApplication userApplication : userApplications) {
        Long id = getAplicationId(userApplication);
        openTicketsForApplications += ticketService.getNumberOfTicketsforApplicationByState(id,
                TicketState.NEW);/*from ww  w  .j  a va2s. c o m*/
        inprogressTicketsForApplication += ticketService.getNumberOfTicketsforApplicationByState(id,
                TicketState.INPROGRESS);
        closedTicketsForApplications += ticketService.getNumberOfTicketsforApplicationByState(id,
                TicketState.CLOSED);
    }
    List<ListTicketDTO> allRecentTickets = ticketService.getTicketsCreatedAfterDate(fromDate);
    Collection<ListTicketDTO> openTicketList = Collections2.filter(allRecentTickets,
            TICKET_STATE_PREDICATE_OPEN);
    Collection<ListTicketDTO> inProgressList = Collections2.filter(allRecentTickets,
            TICKET_STATE_PREDICATE_CLOSED);
    return new LandingDTO(openTicketsForApplications, inprogressTicketsForApplication,
            closedTicketsForApplications, allRecentTickets, new ArrayList<ListTicketDTO>(openTicketList),
            new ArrayList<ListTicketDTO>(inProgressList));

}

From source file:org.opensaml.security.x509.tls.ClientTLSValidationConfigurationCriterion.java

/**
 * Constructor.//  w ww. java2 s  . c  o  m
 *
 * @param configurations varargs array of configuration instances
 */
public ClientTLSValidationConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty ClientTLSValidationConfiguration... configurations) {
    Constraint.isNotNull(configurations, "List of configurations cannot be null");
    configs = new ArrayList<>(Collections2.filter(Arrays.asList(configurations), Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");
}

From source file:com.clarkparsia.empire.config.io.impl.PropertiesConfigReader.java

/**
 * @inheritDoc//from w  w  w  . j  av  a  2s.  c  o  m
 */
public EmpireConfiguration read(Reader theReader) throws IOException {
    Properties aProps = new EnhancedProperties();

    try {
        aProps.load(theReader);
    } catch (Exception e) {
        throw new IOException(e);
    }

    int aIndex = 0;

    Map<String, String> aGeneralConfig = new HashMap<String, String>();
    Map<String, Map<String, String>> aUnitConfig = new HashMap<String, Map<String, String>>();

    while (aProps.containsKey(aIndex + "." + KEY_NAME)) {
        String aPrefix = aIndex + ".";
        Map<String, String> aUnit = new HashMap<String, String>();

        for (Object aOrigKey : Collections2.filter(aProps.keySet(), new PrefixPredicate(aPrefix))) {
            String aKey = aOrigKey.toString();

            aKey = aKey.substring(aPrefix.length());

            aUnit.put(aKey, aProps.getProperty(aOrigKey.toString()));
        }

        aUnitConfig.put(aProps.getProperty(aIndex + "." + KEY_NAME), aUnit);

        aIndex++;
    }

    for (Object aOrigKey : Collections2.filter(aProps.keySet(), new UnitFilterPredicate())) {
        aGeneralConfig.put(aOrigKey.toString(), aProps.getProperty(aOrigKey.toString()));
    }

    EmpireConfiguration aConfig = new EmpireConfiguration(aGeneralConfig, aUnitConfig);

    if (aGeneralConfig.containsKey(KEY_ANNOTATION_PROVIDER)) {
        try {
            @SuppressWarnings("unchecked")
            Class<EmpireAnnotationProvider> aClass = (Class<EmpireAnnotationProvider>) BeanReflectUtil
                    .loadClass(aGeneralConfig.get(KEY_ANNOTATION_PROVIDER));

            aConfig.setAnnotationProvider(aClass);
        } catch (ClassNotFoundException e) {
            LOGGER.warn("Annotation provider implementation '{}' cannot be found, please check your classpath.",
                    aGeneralConfig.get(KEY_ANNOTATION_PROVIDER));
        } catch (ClassCastException e) {
            LOGGER.warn(
                    "Specified annotation provider implementation '{}' is not a valid EmpireAnnotationProvider.",
                    aGeneralConfig.get(KEY_ANNOTATION_PROVIDER));
        }
    }

    return aConfig;
}

From source file:ru.crazyproger.plugins.webtoper.nls.codeinsight.NlsCompletionContributor.java

public NlsCompletionContributor() {
    extend(CompletionType.BASIC, psiElement(NlsNameImpl.class), new CompletionProvider<CompletionParameters>() {
        @Override/*from   ww w .j  ava  2  s  .com*/
        protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context,
                @NotNull CompletionResultSet result) {
            Project project = parameters.getPosition().getContainingFile().getProject();
            Collection<NlsFileImpl> files = getNlsFiles(project);
            if (files.isEmpty())
                return;
            final NlsFileImpl currentFile = (NlsFileImpl) parameters.getOriginalFile();
            final Collection<NlsFileImpl> includedFiles = currentFile.getIncludedFiles();
            Collection<NlsFileImpl> filtered = Collections2.filter(files, new Predicate<NlsFileImpl>() {
                @Override
                public boolean apply(@Nullable NlsFileImpl nlsFile) {
                    assert nlsFile != null;
                    return !nlsFile.equals(currentFile) && !includedFiles.contains(nlsFile);
                }
            });

            Collection<LookupElement> lookupElements = Collections2.transform(filtered,
                    new NlsFile2LookupElementFunction());

            result.addAllElements(lookupElements);
        }
    });
}

From source file:org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java

@SuppressWarnings("unchecked")
protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(final Class<S> type) {
    return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type)));
}

From source file:org.opennms.features.topology.plugins.ncs.NCSEdgeStatusProvider.java

@Override
public Map<EdgeRef, Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges,
        Criteria[] criteria) {/*from  w  w  w .j  a  v  a  2  s. com*/
    List<EdgeRef> ncsEdges = new ArrayList<EdgeRef>(Collections2.filter(edges, new Predicate<EdgeRef>() {
        @Override
        public boolean apply(EdgeRef edgeRef) {
            return edgeRef.getNamespace().equals("ncs");
        }
    }));

    Set<String> alarms = getNCSImpactedAlarms();

    Map<EdgeRef, Status> statusMap = new HashMap<EdgeRef, Status>();
    for (EdgeRef edge : ncsEdges) {
        NCSEdgeProvider.NCSEdge e = (NCSEdgeProvider.NCSEdge) edge;
        e.setStatus("up");
        statusMap.put(edge, new NCSLinkStatus("up"));
        if (alarms.contains(e.getSourceElementName()) || alarms.contains(e.getTargetElementName())) {
            statusMap.put(edge, new NCSLinkStatus("down"));
            e.setStatus("down");
        }
    }

    return statusMap;
}

From source file:org.onos.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java

@SuppressWarnings("unchecked")
protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(Class<S> type) {
    return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type)));
}