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.killbill.billing.plugin.analytics.utils.BusinessInvoiceUtils.java

public static boolean isInvoiceAdjustmentItem(final InvoiceItem invoiceItem,
        final Collection<InvoiceItem> otherInvoiceItemsOnAllInvoices) {
    final Collection<InvoiceItem> otherInvoiceItems = Collections2.filter(otherInvoiceItemsOnAllInvoices,
            new Predicate<InvoiceItem>() {
                @Override//from w  w  w  .  ja v  a 2  s  .c  o m
                public boolean apply(final InvoiceItem input) {
                    return input.getInvoiceId().equals(invoiceItem.getInvoiceId());
                }
            });

    // Either REFUND_ADJ
    return InvoiceItemType.REFUND_ADJ.equals(invoiceItem.getInvoiceItemType()) ||
    // Or invoice level credit, i.e. credit adj, but NOT on its on own invoice
    // Note: the negative credit adj items (internal generation of account level credits) doesn't figure in analytics
            (InvoiceItemType.CREDIT_ADJ.equals(invoiceItem.getInvoiceItemType())
                    && !(otherInvoiceItems.size() == 1
                            && InvoiceItemType.CBA_ADJ
                                    .equals(otherInvoiceItems.iterator().next().getInvoiceItemType())
                            && otherInvoiceItems.iterator().next().getInvoiceId()
                                    .equals(invoiceItem.getInvoiceId())
                            && otherInvoiceItems.iterator().next().getAmount()
                                    .compareTo(invoiceItem.getAmount().negate()) == 0));
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.util.ResourceDiagnosticFeedback.java

@Override
public void clearMarkers(Resource resource, final String markerType) {
    if (resource != null) {
        EList<Diagnostic> errors = resource.getErrors();
        Collection<Diagnostic> filter = Collections2.filter(errors, new Predicate<Diagnostic>() {

            @Override/*ww  w  . j  a  v  a  2s .  c  o  m*/
            public boolean apply(Diagnostic input) {
                return input instanceof EObjectDiagnosticImpl
                        && markerType.contentEquals(((EObjectDiagnosticImpl) input).getCode());
            }
        });
        errors.removeAll(filter);
    }
}

From source file:org.jetbrains.jet.lang.resolve.scopes.FilteringScope.java

@NotNull
@Override/*from w  ww  . j  a  va 2s. c o  m*/
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
    return Collections2.filter(super.getFunctions(name), predicate);
}

From source file:com.jayway.demo.library.domain.internal.BookRepositoryInMemory.java

@Override
public Collection<Book> getLoansForCustomer(final Integer customerId) {
    return Collections2.filter(allBooks.values(), new Predicate<Book>() {
        @Override/*  w  w  w .  j  a va  2s.  c om*/
        public boolean apply(Book book) {
            if (!book.isBorrowed()) {
                return false;
            }
            return book.getBorrowedBy().getId().equals(customerId);
        }
    });
}

From source file:org.basepom.mojo.duplicatefinder.classpath.ClasspathCacheElement.java

void putClasses(final Multimap<String, File> classMap, final Predicate<String> excludePredicate) {
    for (final String className : Collections2.filter(classes, Predicates.not(excludePredicate))) {
        classMap.put(className, element);
    }/*from   w  w w.j av  a2 s  .c o m*/
}

From source file:org.gradle.internal.cleanup.DefaultBuildOutputDeleter.java

@Override
public void delete(final Iterable<File> outputs) {
    Collection<? extends File> roots = Collections2.filter(FileUtils.calculateRoots(outputs),
            new Predicate<File>() {
                @Override//from ww w .ja v a2  s.c  o m
                public boolean apply(File file) {
                    return file.exists();
                }
            });

    if (!roots.isEmpty()) {
        logger.info(STALE_OUTPUT_MESSAGE);
        for (File output : roots) {
            deleteOutput(output);
        }
    }
}

From source file:org.ow2.play.governance.resources.TopicHelper.java

public static final String getTopicName(MetaResource mr) {
    if (mr == null) {
        return null;
    }// w w w  .j  av  a 2 s .  c o  m
    String result = null;

    Collection<Metadata> filter = Collections2.filter(mr.getMetadata(), new Predicate<Metadata>() {
        public boolean apply(Metadata metadata) {
            return metadata != null && Constants.QNAME_LOACALPART_URL.equals(metadata.getName());
        };
    });

    if (filter != null && filter.size() > 0) {
        logger.fine("Getting TopicName from metadata");
        List<Metadata> l = new ArrayList<Metadata>(filter);
        if (l.get(0) != null && l.get(0).getData() != null && l.get(0).getData().size() > 0) {
            result = l.get(0).getData().get(0).getValue();
        }
    }

    if (result == null) {
        logger.fine("Getting TopicName from metadata URL value");
        // get from Meta resource resource name...
        result = mr.getResource().getUrl().substring(mr.getResource().getUrl().lastIndexOf('/') + 1);
    }

    return result;
}

From source file:es.upm.dit.xsdinferencer.merge.mergerimpl.attribute.SameAttributeComparator.java

/**
 * @see AttributeListComparator#compare(List, List)
 */// w ww.  j  av  a 2 s .  co m
@Override
public boolean compare(List<SchemaAttribute> attrList1, List<SchemaAttribute> attrList2) {
    Set<SchemaAttribute> required1 = new HashSet<SchemaAttribute>(
            Collections2.filter(attrList1, SchemaAttributePredicates.isRequired()));
    Set<SchemaAttribute> required2 = new HashSet<SchemaAttribute>(
            Collections2.filter(attrList2, SchemaAttributePredicates.isRequired()));
    return required1.equals(required2);
}

From source file:net.oneandone.maven.plugins.cycles.graph.FeedbackArcSet.java

/**
 * @param graph a directed graph/*from ww  w. j  a v  a  2s.co m*/
 * @param evaluator a vertex evaluator
 * @param <V> vertex type
 * @param <E> edge type
 * @return approximation of a feedback arc set, i.e., a set of edges that, if removed,
 * breaks a strong component; the algorithm will try to pick minimum weight edges 
 */
public static <V, E> Collection<E> feedbackArcs(DirectedGraph<V, E> graph,
        VertexEvaluator<V, DirectedGraph<V, E>> evaluator) {
    return ImmutableList.copyOf(
            Collections2.filter(graph.getEdges(), isBackwardEdge(vertexOrdering(graph, evaluator), graph)));
}

From source file:org.onosproject.cli.net.Meters.java

@Override
protected void execute() {
    MeterService service = get(MeterService.class);

    Collection<Meter> meters = service.getAllMeters();
    if (uri != null) {
        DeviceId deviceId = DeviceId.deviceId(uri);
        Collection<Meter> devMeters = Collections2.filter(meters, m -> m.deviceId().equals(deviceId));
        printMeters(devMeters);//from w ww .ja va 2s  . co  m
    } else {
        printMeters(meters);
    }
}