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

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

Introduction

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

Prototype

public static <T> boolean any(Iterator<T> iterator, Predicate<? super T> predicate) 

Source Link

Document

Returns true if one or more elements returned by iterator satisfy the given predicate.

Usage

From source file:gg.uhc.uhc.modules.recipes.NotchApplesModule.java

@Override
protected void onEnable() {
    final boolean recipeExists = Iterators.any(Bukkit.recipeIterator(), IS_NOTCH_APPLE_RECIPE);
    if (!recipeExists)
        Bukkit.addRecipe(NOTCH_APPLE_RECIPE);
}

From source file:org.cryptomator.frontend.webdav.servlet.WebDavServlet.java

@Override
protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) {
    IfHeader ifHeader = new IfHeader(request);
    if (ifHeader.hasValue() && Iterators.all(ifHeader.getAllTokens(), Predicates.equalTo(NO_LOCK))) {
        // https://tools.ietf.org/html/rfc4918#section-10.4.8:
        // "DAV:no-lock" is known to never represent a current lock token.
        return false;
    } else if (ifHeader.hasValue() && Iterators.any(ifHeader.getAllNotTokens(), Predicates.equalTo(NO_LOCK))) {
        // by applying "Not" to a state token that is known not to be current, the Condition always evaluates to true.
        return true;
    } else {/*from   ww  w. j a  v  a  2 s . c o m*/
        return request.matchesIfHeader(resource);
    }
}

From source file:com.demigodsrpg.stoa.util.WorldGuardUtil.java

/**
 * Check that a ProtectedRegion exists at a Location.
 *
 * @param name     The name of the region.
 * @param location The location being checked.
 * @return The region does exist at the provided location.
 *///from   w ww.  j  av a  2s  . com
public static boolean checkForRegion(final String name, Location location) {
    return Iterators.any(WorldGuardPlugin.inst().getRegionManager(location.getWorld())
            .getApplicableRegions(location).iterator(), new Predicate<ProtectedRegion>() {
                @Override
                public boolean apply(ProtectedRegion region) {
                    return region.getId().toLowerCase().contains(name);
                }
            });
}

From source file:org.openengsb.connector.wicketacl.internal.WicketAclServiceImpl.java

private boolean hasAccess(String user, final UIAction actionData) {
    Collection<WicketPermission> filtered;
    try {/*from w  w  w.java2  s .c o m*/
        filtered = getWicketPermissions(user);
    } catch (UserNotFoundException e) {
        LOGGER.warn("user not found", e);
        return false;
    }

    Collection<String> relevantComponentNames = getRelevantComponentNames(actionData);
    for (final String a : relevantComponentNames) {
        boolean allowed = Iterators.any(filtered.iterator(), new Predicate<WicketPermission>() {
            @Override
            public boolean apply(WicketPermission input) {
                if (ObjectUtils.notEqual(a, input.getComponentName())) {
                    return false;
                }
                if (actionData.getAction() == null) {
                    return true;
                }
                if (input.getAction() == null || input.getAction().equals("ENABLE")) {
                    return true;
                }
                return input.getAction().equals(actionData.getAction());
            }
        });
        if (allowed) {
            return true;
        }
    }
    return false;
}

From source file:com.demigodsrpg.norsedemigods.util.WorldGuardUtil.java

/**
 * Check for a flag at a given location.
 *
 * @param flag     The flag being checked.
 * @param location The location being checked.
 * @return The flag does exist at the provided location.
 */// w  w  w .ja  v  a  2  s  .c o  m
public static boolean checkForFlag(final Flag flag, Location location) {
    return Iterators.any(WorldGuardPlugin.inst().getRegionManager(location.getWorld())
            .getApplicableRegions(location).iterator(), region -> {
                try {
                    return region.getFlags().containsKey(flag);
                } catch (Exception ignored) {
                }
                return false;
            });
}

From source file:org.eclipse.emf.compare.ide.ui.internal.actions.filter.DifferenceFilter.java

/**
 * {@inheritDoc}//from   w w w . ja v  a 2  s . c om
 * 
 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object,
 *      java.lang.Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (predicates.isEmpty()) {
        return true;
    }
    boolean result = false;
    final Predicate<? super EObject> predicate = Predicates.or(predicates);

    if (predicates.isEmpty()) {
        result = true;
    } else if (element instanceof DiffNode) {
        final Diff diff = ((DiffNode) element).getTarget();
        result = !predicate.apply(diff);
    } else if (element instanceof MatchNode) {
        final Iterator<Diff> differences = ((MatchNode) element).getTarget().getAllDifferences().iterator();
        result = Iterators.any(differences, not(predicate));
    } else if (element instanceof DifferenceGroup) {
        final Iterator<? extends Diff> differences = ((DifferenceGroup) element).getDifferences().iterator();
        result = Iterators.any(differences, not(predicate));
    } else if (element instanceof Adapter && ((Adapter) element).getTarget() instanceof EObject) {
        /*
         * Same code as the DiffNode case... extracted here as this is aimed at handling the cases not
         * known at the time of writing (and the case of the "MatchResource" elements).
         */
        final EObject target = (EObject) ((Adapter) element).getTarget();
        result = !predicate.apply(target);
    }

    return result;
}

From source file:com.demigodsrpg.stoa.util.WorldGuardUtil.java

/**
 * Check for a flag at a given location.
 *
 * @param flag     The flag being checked.
 * @param location The location being checked.
 * @return The flag does exist at the provided location.
 *//*from  w  w  w  .ja  v a  2  s .  c  om*/
public static boolean checkForFlag(final Flag flag, Location location) {
    return Iterators.any(WorldGuardPlugin.inst().getRegionManager(location.getWorld())
            .getApplicableRegions(location).iterator(), new Predicate<ProtectedRegion>() {
                @Override
                public boolean apply(ProtectedRegion region) {
                    try {
                        return region.getFlags().containsKey(flag);
                    } catch (Exception ignored) {
                    }
                    return false;
                }
            });
}

From source file:org.obiba.opal.web.search.ValueTablesIndexResource.java

private boolean needsUpdate(ValueTable table) {
    if (table.isView()) {
        return needsUpdate(((ValueTableWrapper) table).getInnermostWrappedValueTable());
    } else if (table instanceof JoinTable) {
        return Iterators.any(((JoinTable) table).getTables().listIterator(), new Predicate<ValueTable>() {
            public boolean apply(ValueTable table) {
                return needsUpdate(table);
            }/*from  w  w w. j  a  va 2 s  .com*/
        });
    } else {
        return tables.contains(table.getTableReference());
    }
}

From source file:com.github.jonross.seq4j.Seq.java

/**
 * Wraps {@link Iterators#any(Iterator, Predicate); returns true if any element in the
 * sequence satisfies the given predicate.
 *//*from w  w w.  ja va 2s.c  om*/

boolean any(Predicate<? super T> p) {
    return Iterators.any(this, p);
}

From source file:module.siadap.domain.Siadap.java

protected boolean CheckOnlyOneSiadapForEachYear() {
    final Person evaluated = getEvaluated();
    final Integer year = getYear();
    SiadapYearConfiguration siadapYearConfiguration = SiadapYearConfiguration.getSiadapYearConfiguration(year);
    final Siadap siadap = this;
    return !Iterators.any(siadapYearConfiguration.getSiadaps().iterator(),
            new com.google.common.base.Predicate<Siadap>() {

                @Override//  w ww.  j a va  2s  . c  om
                public boolean apply(Siadap input) {
                    //any siadap for this person already
                    if (input == null || input == siadap) {
                        return false;
                    }
                    if (input.getEvaluated().equals(evaluated) && input.getYear().equals(year)) {
                        return true;
                    }
                    return false;

                }
            });
}