Example usage for com.google.common.collect Iterables any

List of usage examples for com.google.common.collect Iterables any

Introduction

In this page you can find the example usage for com.google.common.collect Iterables any.

Prototype

public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if any element in iterable satisfies the predicate.

Usage

From source file:com.clarkparsia.pelletserver.client.services.Search.java

/**
 * Create a new Search service//w w  w.jav  a 2  s . co  m
 * @param kb the PelletServer kb
 * @param endpoint the Endpoint of th eKB
 * @param mimetypes the mimetypes supported by the service
 */
public Search(KnowledgeBase kb, Endpoint endpoint, MimeType... mimetypes) {
    super(kb, endpoint, mimetypes);

    checkArgument(Iterables.any(this.mimetypes, PelletServerMimeTypes.getPredicate(MIMETYPE)),
            getName() + " service must support %s", MIMETYPE);
}

From source file:org.gradle.testing.jacoco.tasks.JacocoReportBase.java

public JacocoReportBase() {
    onlyIf(new Spec<Task>() {
        @Override//ww  w .j a va 2  s .co m
        public boolean isSatisfiedBy(Task element) {
            return Iterables.any(getExecutionData(), new Predicate<File>() {
                @Override
                public boolean apply(File file) {
                    return file.exists();
                }
            });
        }
    });
}

From source file:org.apache.gobblin.util.TimeRangeChecker.java

/**
 * Checks if a specified time is on a day that is specified the a given {@link List} of acceptable days, and that the
 * hours + minutes of the specified time fall into a range defined by startTimeStr and endTimeStr.
 *
 * @param days is a {@link List} of days, if the specified {@link DateTime} does not have a day that falls is in this
 * {@link List} then this method will return false.
 * @param startTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of
 * the pattern defined by {@link #HOUR_MINUTE_FORMAT}.
 * @param endTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of
 * the pattern defined by {@link #HOUR_MINUTE_FORMAT}.
 * @param currentTime is a {@link DateTime} for which this method will check if it is in the given {@link List} of
 * days and falls into the time range defined by startTimeStr and endTimeStr.
 *
 * @return true if the given time is in the defined range, false otherwise.
 *///from  w w  w .j av  a  2  s  .c om
public static boolean isTimeInRange(List<String> days, String startTimeStr, String endTimeStr,
        DateTime currentTime) {

    if (!Iterables.any(days, new AreDaysEqual(DAYS_OF_WEEK.get(currentTime.getDayOfWeek())))) {
        return false;
    }

    DateTime startTime = null;
    DateTime endTime = null;

    try {
        startTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(startTimeStr);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                "startTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e);
    }

    try {
        endTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(endTimeStr);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                "endTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e);
    }

    startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(),
            currentTime.getDayOfMonth());
    endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(),
            currentTime.getDayOfMonth());

    Interval interval = new Interval(startTime.getMillis(), endTime.getMillis(), DATE_TIME_ZONE);
    return interval.contains(currentTime.getMillis());
}

From source file:org.splevo.ui.refinementbrowser.action.ApplySelectedRefinementsAction.java

@Override
protected List<Refinement> getRefinementsFromRefinementBrowser() {
    final List<Refinement> selectedRefinements = this.vpmRefinementBrowser.getSelectedRefinementsFromMainView();

    /**/*www.jav  a  2s .  c om*/
     * We have to repair the selected refinements in the following situation:
     * Context: Group A contains Merges M1 and M2
     * Scenario: User selects A and M1
     * 
     * Fixes to apply:
     * - F1: M1 has to be removed from the refinements to apply because it is already contained in A
     * - F2: M2 has to be removed from A as this is the users choice
     * - F3: the variation points of M2 have to be added to A in order to do a correct grouping
     * 
     */

    // F1
    Iterable<Refinement> relevantSelectedRefinements = Iterables.filter(selectedRefinements,
            new Predicate<Refinement>() {
                @Override
                public boolean apply(final Refinement selectedRefinement) {
                    return !Iterables.any(selectedRefinements, new Predicate<Refinement>() {
                        @Override
                        public boolean apply(final Refinement possibleParent) {
                            return possibleParent.getSubRefinements().contains(selectedRefinement);
                        }
                    });
                }
            });

    // F2 and F3
    Iterable<Refinement> fixedRelevantSelectedRefinements = Iterables.transform(relevantSelectedRefinements,
            new Function<Refinement, Refinement>() {
                @Override
                public Refinement apply(Refinement arg0) {
                    for (Iterator<Refinement> iter = arg0.getSubRefinements().iterator(); iter.hasNext();) {
                        Refinement r = iter.next();
                        if (!selectedRefinements.contains(r)) {
                            arg0.getVariationPoints().addAll(r.getVariationPoints());
                            iter.remove();
                        }
                    }
                    return arg0;
                }
            });

    return Lists.newArrayList(fixedRelevantSelectedRefinements);
}

From source file:io.pelle.mango.client.gwt.modules.hierarchical.HierarchicalTreeModel.java

private void refreshParentDataProvider(final IHierarchicalVO hierarchicalVO) {
    for (HierarchicalDataProvider dataProvider : dataProviders.values()) {
        boolean doUpdate = Iterables.any(dataProvider.getItems(),
                new Predicate<DictionaryHierarchicalNodeVO>() {
                    @Override/*from   w  w w .  j  a v a  2 s  . com*/
                    public boolean apply(DictionaryHierarchicalNodeVO hierarchicalNodeVO) {
                        return hierarchicalVO.getParentClassName().equals(hierarchicalNodeVO.getVoClassName())
                                && hierarchicalVO.getParentId().equals(hierarchicalNodeVO.getVoId());
                    }
                });

        if (doUpdate) {
            dataProvider.onRangeChanged(cellList);
        }
    }
}

From source file:org.jclouds.vcloud.director.testng.FormatApiResultsListener.java

private boolean methodInApiGroup(ITestResult res) {
    return Iterables.any(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis));
}

From source file:com.clarkparsia.pelletserver.client.services.Query.java

public Query(KnowledgeBase kb, Endpoint endpoint, MimeType... mimetypes) {
    super(kb, endpoint, mimetypes);

    for (MimeType mimetype : MIMETYPES) {
        checkArgument(Iterables.any(this.mimetypes, PelletServerMimeTypes.getPredicate(mimetype)),
                getName() + " service must support %s", mimetype);
    }/* w w  w  . j  a  v  a  2 s. c o m*/
}

From source file:org.apache.aurora.scheduler.updater.InstanceUpdater.java

private static boolean isPermanentlyKilled(IScheduledTask task) {
    boolean wasKilling = Iterables.any(task.getTaskEvents(),
            Predicates.compose(Predicates.equalTo(KILLING), ITaskEvent::getStatus));
    return task.getStatus() != KILLING && wasKilling;
}

From source file:com.android.tools.profilers.cpu.TopDownNode.java

public boolean inRange(Range range) {
    return Iterables.any(myNodes, node -> node.getStart() < range.getMax() && range.getMin() < node.getEnd());
}

From source file:lodsve.springfox.config.SpringFoxDocket.java

private Predicate<RequestHandler> transform(final Predicate<String> pathSelector) {
    return new Predicate<RequestHandler>() {
        @Override// ww  w.  j av a2 s . c  o  m
        public boolean apply(RequestHandler input) {
            return Iterables.any(input.getRequestMapping().getPatternsCondition().getPatterns(), pathSelector);
        }
    };
}