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:org.eclipse.sirius.table.business.internal.migration.description.InitializeCreationToolElementsToSelectExpressionParticipant.java

@Override
protected void postLoad(Group group, Version loadedVersion) {
    if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) {
        EList<Viewpoint> ownedViewpoints = group.getOwnedViewpoints();
        for (Viewpoint viewpoint : ownedViewpoints) {
            boolean atLeastOneChange = false;
            for (TableDescription tableDescription : Iterables.filter(viewpoint.getOwnedRepresentations(),
                    TableDescription.class)) {
                Iterator<CreateTool> creationTools = Iterators.filter(tableDescription.eAllContents(),
                        CreateTool.class);
                while (creationTools.hasNext()) {
                    CreateTool tool = creationTools.next();
                    if (StringUtil.isEmpty(tool.getElementsToSelect())) {
                        tool.setElementsToSelect(ELEMENTS_TO_SELECT_EXPRESSION);
                        atLeastOneChange = true;
                    }//from   ww  w. ja  v a  2 s . c  o  m
                }
            }

            if (atLeastOneChange) {
                // Add the Java Extension to use the service:
                if (!Iterables.any(viewpoint.getOwnedJavaExtensions(), new Predicate<JavaExtension>() {
                    @Override
                    public boolean apply(JavaExtension input) {
                        return JAVA_EXTENSION_QUALIFIED_NAME.equals(input.getQualifiedClassName());
                    }
                })) {
                    JavaExtension javaExtension = DescriptionFactory.eINSTANCE.createJavaExtension();
                    javaExtension.setQualifiedClassName(JAVA_EXTENSION_QUALIFIED_NAME);
                    viewpoint.getOwnedJavaExtensions().add(javaExtension);
                }
            }
        }
    }
}

From source file:org.sonar.server.permission.PermissionFinder.java

/**
 * As the anyone group does not exists in db, it's not returned when it has not the permission.
 * We have to manually add it at the begin of the list, if it matched the search text
 *///from  w ww  .ja v  a  2  s .  c  o m
private static void addAnyoneGroup(List<GroupWithPermissionDto> groups, PermissionQuery query) {
    boolean hasAnyoneGroup = Iterables.any(groups, IsAnyoneGroup.INSTANCE);
    if (!hasAnyoneGroup && !GlobalPermissions.SYSTEM_ADMIN.equals(query.permission())
            && (query.search() == null || containsIgnoreCase(DefaultGroups.ANYONE, query.search()))) {
        groups.add(0, new GroupWithPermissionDto().setName(DefaultGroups.ANYONE));
    }
}

From source file:io.druid.indexing.common.actions.TaskActionToolbox.java

public boolean taskLockCoversSegments(final Task task, final Set<DataSegment> segments) {
    // Verify that each of these segments falls under some lock

    // NOTE: It is possible for our lock to be revoked (if the task has failed and given up its locks) after we check
    // NOTE: it and before we perform the segment insert, but, that should be OK since the worst that happens is we
    // NOTE: insert some segments from the task but not others.

    final List<TaskLock> taskLocks = getTaskLockbox().findLocksForTask(task);
    for (final DataSegment segment : segments) {
        final boolean ok = Iterables.any(taskLocks, new Predicate<TaskLock>() {
            @Override//from ww w .  j  a v a2  s  .  c  o m
            public boolean apply(TaskLock taskLock) {
                return taskLock.getDataSource().equals(segment.getDataSource())
                        && taskLock.getInterval().contains(segment.getInterval())
                        && taskLock.getVersion().compareTo(segment.getVersion()) >= 0;
            }
        });

        if (!ok) {
            return false;
        }
    }

    return true;
}

From source file:org.eclipse.sirius.ui.tools.internal.views.common.action.ExtractRepresentationAction.java

/**
 * Test if the selection is valid./*from  w  w w . j a  v a 2 s . co  m*/
 * 
 * @return true if the selection is valid
 */
private boolean isValidSelection() {
    boolean anyInvalidExtract = Iterables.any(representations, new Predicate<DRepresentation>() {
        @Override
        public boolean apply(DRepresentation input) {
            EObject container = input.eContainer();
            if (container instanceof DView) {
                IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault()
                        .getPermissionAuthority(container);
                if (permissionAuthority != null && !permissionAuthority.canDeleteInstance(input)) {
                    return true;
                }
            }
            return false;
        }
    });
    return !anyInvalidExtract;
}

From source file:org.eclipse.sirius.diagram.sequence.ui.business.internal.refresh.VisibilityEventHandler.java

private boolean containsVisibilityEvent(ResourceSetChangeEvent event) {
    Predicate<Notification> isVisibilityEvent = new Predicate<Notification>() {
        @Override/*  w  w w  . ja  va 2s . co  m*/
        public boolean apply(Notification input) {
            NotificationQuery nq = new NotificationQuery(input);
            return nq.isViewBecomingInvisibleEvent() || nq.isHideFilterAddEvent();
        }
    };

    Predicate<Notification> isAlwaysVisibleSequenceElement = new Predicate<Notification>() {
        @Override
        public boolean apply(Notification input) {
            Object notifier = input.getNotifier();
            if (notifier instanceof DDiagramElement) {
                DDiagramElement dde = (DDiagramElement) notifier;
                DDiagram parentDiagram = dde.getParentDiagram();
                return parentDiagram instanceof SequenceDDiagram
                        && !(new SequenceDiagramTypeProvider().allowsHideReveal(dde));
            }
            return false;
        }
    };
    return Iterables.any(Iterables.filter(event.getNotifications(), Notification.class),
            Predicates.and(isAlwaysVisibleSequenceElement, isVisibilityEvent));
}

From source file:com.isotrol.impe3.api.FileBundleData.java

/**
 * Constructor./*from w w w .j a va2s .com*/
 * @param id ID if the file.
 * @param name File name.
 * @param downloadable Whether the file is downloadable.
 * @param files Files contained in the bundle.
 */
private FileBundleData(final UUID id, final String name, boolean downloadable, Map<String, FileData> files) {
    super(id, name, MediaType.valueOf("application/zip"), downloadable, FileType.BUNDLE);
    if (Iterables.any(files.keySet(), STARS_WITH)) {
        ImmutableMap.Builder<String, FileData> b = ImmutableMap.builder();
        for (Entry<String, FileData> e : files.entrySet()) {
            b.put(clean(e.getKey()), e.getValue());
        }
        this.files = b.build();
    } else {
        this.files = ImmutableMap.copyOf(files);
    }
}

From source file:org.killbill.billing.payment.dao.MockPaymentDao.java

@Override
public Pagination<PaymentTransactionModelDao> getByTransactionStatusAcrossTenants(
        final Iterable<TransactionStatus> transactionStatuses, DateTime createdBeforeDate,
        DateTime createdAfterDate, Long offset, Long limit) {
    final List<PaymentTransactionModelDao> result = ImmutableList
            .copyOf(Iterables.filter(transactions.values(), new Predicate<PaymentTransactionModelDao>() {
                @Override/* ww w  .  j  a  va2  s .c  om*/
                public boolean apply(final PaymentTransactionModelDao input) {
                    return Iterables.any(transactionStatuses, new Predicate<TransactionStatus>() {
                        @Override
                        public boolean apply(final TransactionStatus transactionStatus) {
                            return input.getTransactionStatus() == transactionStatus;
                        }
                    });
                }
            }));
    return new DefaultPagination<PaymentTransactionModelDao>(new Long(result.size()), result.iterator());
}

From source file:org.jclouds.aliyun.ecs.domain.options.TagOptions.java

private void validateInput(final String input, int maxLength) {
    checkNotNull(input);// w  w  w.j a  v a2  s . com
    checkState(input.length() <= maxLength, String.format("input must be <= %d chars", maxLength));
    checkState(!Iterables.any(FORBIDDEN_PREFIX, new Predicate<String>() {
        @Override
        public boolean apply(String forbiddenPrefix) {
            return input.startsWith(forbiddenPrefix);
        }
    }), input + " cannot starts with any of " + Iterables.toString(FORBIDDEN_PREFIX));
}

From source file:forge.ai.ComputerUtilCombat.java

/**
 * <p>/*w w w.  j a  v a2  s .  c  o m*/
 * canAttackNextTurn.
 * </p>
 * 
 * @param attacker
 *            a {@link forge.game.card.Card} object.
 * @param def
 *            the defending {@link GameEntity}.
 * @return a boolean.
 */
public static boolean canAttackNextTurn(final Card attacker) {
    final Iterable<GameEntity> defenders = CombatUtil.getAllPossibleDefenders(attacker.getController());
    return Iterables.any(defenders, new Predicate<GameEntity>() {
        @Override
        public boolean apply(final GameEntity input) {
            return ComputerUtilCombat.canAttackNextTurn(attacker, input);
        };
    });
}

From source file:com.github.fommil.ff.KeyboardController.java

private boolean directionSelected() {
    return Iterables.any(actions, new Predicate<Action>() {

        @Override/*w  w  w . ja  v a2 s  .  c  o  m*/
        public boolean apply(Action input) {
            switch (input) {
            case UP:
            case DOWN:
            case LEFT:
            case RIGHT:
                return true;
            default:
                return false;
            }
        }
    });
}