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.technophobia.substeps.report.TreeJsonBuilder.java

private JsonObject buildTree() {
    List<RootNode> rootNodes = reportData.getRootNodes();

    JsonObject tree = new JsonObject();

    boolean rootNodeInError = Iterables.any(rootNodes, NODE_HAS_ERROR);

    addChildren(tree, rootNodeInError, rootNodes);

    JsonObject data = new JsonObject();
    tree.add("data", data);
    data.addProperty("title", "Substeps tests");

    JsonObject attr = new JsonObject();
    data.add("attr", attr);
    attr.addProperty("id", "0");

    String icon = rootNodeInError ? resultToImageMap.get(ExecutionResult.FAILED)
            : resultToImageMap.get(ExecutionResult.PASSED);
    data.addProperty("icon", icon);

    if (rootNodeInError) {

        data.addProperty("state", "open");
    }//from  w w  w.java 2 s .  c  o  m
    return tree;
}

From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java

/**
 * Check if this {@link DDiagramElement} is directly hidden.
 * // ww  w .  j  a  v a 2  s .c o  m
 * @return true if the given element is hidden.
 */
public boolean isHidden() {
    return Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(HideFilter.class));
}

From source file:org.decisiondeck.jlp.LpVariable.java

/**
 * Builds a variable of the given category and with the provided references.
 * // ww w  .j  a  v a 2 s. c o  m
 * @param category
 *            not <code>null</code>.
 * @param references
 *            not <code>null</code>, no <code>null</code> reference inside. May be empty.
 */
public LpVariable(T category, Object... references) {
    Preconditions.checkNotNull(category);
    Preconditions.checkNotNull(references);
    final List<Object> asList = Arrays.asList(references);
    final boolean hasNull = Iterables.any(asList, Predicates.isNull());
    if (hasNull) {
        throw new NullPointerException("Given references contain a null reference.");
    }
    m_category = category;
    m_refs = Collections.unmodifiableList(asList);
}

From source file:com.thinkbiganalytics.spark.datavalidator.functions.CleanseAndValidateRow.java

public CleanseAndValidateRow(@Nonnull final FieldPolicy[] policies, @Nonnull final StructField[] fields) {
    this.policies = policies;
    hasProcessingDttm = Iterables.any(Arrays.asList(fields), new Predicate<StructField>() {
        @Override//ww w .  j a  v  a2 s .c o m
        public boolean apply(@Nullable StructField input) {
            return input != null && input.name().equals(PROCESSING_DTTM_COL);
        }
    });

    dataTypes = resolveDataTypes(fields);
    schema = getSchema(fields);
}

From source file:org.apache.kylin.rest.util.AdHocUtil.java

public static String restoreComputedColumnToExpr(String beforeSql, String project) {
    MetadataManager metadataManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
    Map<String, CCInfo> ccInfoMap = metadataManager.getCcInfoMap();
    final ProjectInstance projectInstance = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv())
            .getProject(project);/* ww  w .j  av  a 2s .c o  m*/

    Iterable<CCInfo> projectCCInfo = Iterables.filter(ccInfoMap.values(), new Predicate<CCInfo>() {
        @Override
        public boolean apply(@Nullable CCInfo ccInfo) {
            return Iterables.any(ccInfo.getDataModelDescs(), new Predicate<DataModelDesc>() {
                @Override
                public boolean apply(@Nullable DataModelDesc model) {
                    return projectInstance.containsModel(model.getName());
                }
            });
        }
    });

    String afterSql = beforeSql;
    for (CCInfo ccInfo : projectCCInfo) {
        afterSql = restoreComputedColumnToExpr(afterSql, ccInfo);
    }

    if (!StringUtils.equals(beforeSql, afterSql)) {
        logger.info("computed column in sql is expanded before sending to adhoc engine: " + afterSql);
    }
    return afterSql;
}

From source file:org.jclouds.openstack.nova.v1_1.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.java

@Override
public Optional<Object> apply(ClassMethodArgsAndReturnVal input) {
    Optional<org.jclouds.openstack.services.Extension> ext = Optional
            .fromNullable(input.getClazz().getAnnotation(org.jclouds.openstack.services.Extension.class));
    if (ext.isPresent()) {
        checkState(input.getArgs() != null && input.getArgs().length == 1, "expecting an arg %s", input);
        URI namespace = URI.create(ext.get().namespace());
        if (Iterables.any(
                extensions.getUnchecked(checkNotNull(input.getArgs()[0], "arg[0] in %s", input).toString()),
                ExtensionPredicates.namespaceOrAliasEquals(namespace, aliases.get(namespace))))
            return Optional.of(input.getReturnVal());
    }//from w w w .ja v  a2s .co m
    return Optional.absent();
}

From source file:org.grouplens.lenskit.data.dao.EventCollectionDAO.java

@Override
public <E extends Event> Cursor<E> streamEvents(Class<E> type, SortOrder order) {
    boolean needFilter = Iterables.any(types, Predicates.not(TypeUtils.subtypePredicate(type)));

    Comparator<Event> comp = order.getEventComparator();

    if (!needFilter) {
        if (comp == null) {
            return (Cursor<E>) Cursors.wrap(events);
        } else {//from   w w w. ja  va 2  s.  co  m
            List evts = Lists.newArrayList(events);
            Collections.sort(evts, comp);
            return Cursors.wrap(evts);
        }
    } else {
        if (comp == null) {
            return Cursors.filter(streamEvents(), type);
        } else {
            List<E> filtered = Lists.newArrayList(Iterables.filter(events, type));
            Collections.sort(filtered, comp);
            return Cursors.wrap(filtered);
        }
    }
}

From source file:com.xebialabs.deployit.community.changemgmt.planning.SetChangeTicketReleaseCondition.java

protected static void setChangeTicketCondition(DeltaSpecification spec) {
    DeployedApplication deployedApplication = spec.getDeployedApplication();
    Set<String> releaseConditions = deployedApplication.getEnvironment()
            .getProperty(ENV_RELEASE_CONDITIONS_PROPERTY);
    if ((releaseConditions == null) || releaseConditions.isEmpty()) {
        LOGGER.debug("No release conditions defined for target environment '{}'",
                deployedApplication.getEnvironment());
        return;//from ww  w.  j a  va2s. c o m
    }

    Version deploymentPackage = deployedApplication.getVersion();
    String changeTicketCondition = getChangeTicketCondition();
    checkState(deploymentPackage.hasProperty(changeTicketCondition),
            "No release condition '%s' defined for %s. Define a boolean, hidden property of this name on %s or change the value of property '%s' of %s.",
            changeTicketCondition, DEPLOYMENT_PACKAGE_TYPE, DEPLOYMENT_PACKAGE_TYPE,
            CHANGE_TICKET_CONDITION_NAME_PROPERTY, CHANGE_MANAGER_TYPE);
    // can't use a constant in case the descriptor registry is refreshed
    checkState(
            DescriptorRegistry.getDescriptor(DEPLOYMENT_PACKAGE_TYPE)
                    .getPropertyDescriptor(changeTicketCondition).isHidden(),
            "Release condition '%s' is not defined as 'hidden' on '%s'. Hide it or change the value of property '%s' of %s.",
            changeTicketCondition, DEPLOYMENT_PACKAGE_TYPE, CHANGE_TICKET_CONDITION_NAME_PROPERTY,
            CHANGE_MANAGER_TYPE);
    LOGGER.debug("Calculating value of hidden change ticket release condition '{}'", changeTicketCondition);

    /*
     * Always allow undeployments. Not great, but where would a user put the
     * change ticket number? For initial/upgrade installations, looks for 
     * a creation or modification of a Change Ticket.
     */
    Boolean hasChangeTicket = spec.getOperation().equals(Operation.DESTROY)
            || Boolean.valueOf(Iterables.any(spec.getDeltas(), new Predicate<Delta>() {
                @Override
                public boolean apply(Delta input) {
                    // operation check first to avoid NPEs
                    return ((input.getOperation().equals(Operation.CREATE)
                            || input.getOperation().equals(Operation.MODIFY))
                            && Types.isSubtypeOf(Type.valueOf(ChangeTicket.class),
                                    input.getDeployed().getType()));
                }
            }));
    deploymentPackage.setProperty(changeTicketCondition, hasChangeTicket);
}

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

/**
 * Test if the selection is valid./* www.  j av  a 2s . com*/
 *
 * @return true if the selection is valid
 */
private boolean isValidSelection() {

    boolean anyInvalidMove = Iterables.any(representations, new Predicate<DRepresentation>() {

        @Override
        public boolean apply(DRepresentation input) {
            boolean invalid = false; // false is the default value

            // Step 1: Check source representation container
            EObject container = input.eContainer();
            if (container instanceof DView) {
                IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault()
                        .getPermissionAuthority(container);
                if (permissionAuthority != null && !permissionAuthority.canDeleteInstance(input)) {
                    invalid = true;
                }
            }

            // Step 2: Check target representation container
            if (!invalid) {
                DView targetContainer = DAnalysisSessionHelper
                        .findContainerForAddedRepresentation(targetAnalysis, input);
                if (targetContainer != null) {
                    IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault()
                            .getPermissionAuthority(targetContainer);
                    if (permissionAuthority != null && !permissionAuthority.canCreateIn(targetContainer)) {
                        invalid = true;
                    }
                }
            }

            return invalid;
        }
    });

    return !anyInvalidMove;
}

From source file:com.censoredsoftware.infractions.bukkit.issuer.Issuer.java

/**
 * Set of Infractions contributed to./*from  w ww  .j av  a2s  .  c  om*/
 *
 * @return Infractions.
 */
public Set<Infraction> getContributedInfractions() {
    return Sets.filter(Infractions.allInfractions(), new Predicate<Infraction>() {
        @Override
        public boolean apply(Infraction infraction) {
            return Iterables.any(infraction.getEvidence(), new Predicate<Evidence>() {
                @Override
                public boolean apply(Evidence evidence) {
                    return getId().equals(evidence.getIssuer().getId());
                }
            });
        }
    });
}