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

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

Introduction

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

Prototype

public static boolean isEmpty(Iterable<?> iterable) 

Source Link

Document

Determines if the given iterable contains no elements.

Usage

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

/**
 * {@inheritDoc}/*  www .  j  a  v  a 2 s  . co m*/
 */
public void postRefresh(DDiagram dDiagram) {
    if (currentDiagram != null && currentDiagram.equals(dDiagram) && flags != null) {
        Collection<DDiagramElement> nodeEvents = getEventsToSync((SequenceDDiagram) dDiagram);

        if (nodeEvents.size() != 0) {
            for (DDiagramElement elt : nodeEvents) {
                Iterable<AbsoluteBoundsFilter> flag = Iterables.filter(elt.getGraphicalFilters(),
                        AbsoluteBoundsFilter.class);
                EObject semanticTarget = elt.getTarget();
                if (semanticTarget != null && Iterables.isEmpty(flag) && flags.containsKey(semanticTarget)) {
                    AbsoluteBoundsFilter prevFlag = flags.get(semanticTarget);

                    AbsoluteBoundsFilter newFlag = DiagramFactory.eINSTANCE.createAbsoluteBoundsFilter();
                    newFlag.setX(LayoutConstants.EXTERNAL_CHANGE_FLAG.x);
                    newFlag.setY(prevFlag.getY());
                    newFlag.setHeight(prevFlag.getHeight());
                    newFlag.setWidth(prevFlag.getWidth());

                    elt.getGraphicalFilters().add(newFlag);
                }
            }
        }
    }
    if (flags != null) {
        flags.clear();
        flags = null;
    }
    currentDiagram = null;
}

From source file:com.b2international.index.lucene.IndexFieldBase.java

@Override
public final Query toQuery(Iterable<T> values) {
    if (values == null || Iterables.isEmpty(values)) {
        return new MatchNoDocsQuery();
    } else {//from www .  j a  v a 2  s.c o m
        return toSetQuery(values);
    }
}

From source file:com.google.api.server.spi.config.validation.ApiConfigValidator.java

/**
 * Validates all configurations for a single API.  Makes sure the API-level configuration matches
 * for all classes and that the contained configuration is valid and can be turned into a *.api
 * file.  Only checks for swarm-specific validity.  Apiary FE may still dislike a config for its
 * own reasons.//from ww w. j a  v a  2  s . com
 *
 * @throws ApiConfigInvalidException on any invalid API-wide configuration.
 * @throws ApiClassConfigInvalidException on any invalid API class configuration.
 * @throws ApiMethodConfigInvalidException on any invalid API method configuration.
 * @throws ApiParameterConfigInvalidException on any invalid API parameter configuration.
 */
public void validate(Iterable<? extends ApiConfig> apiConfigs) throws ApiConfigInvalidException,
        ApiClassConfigInvalidException, ApiMethodConfigInvalidException, ApiParameterConfigInvalidException {
    if (Iterables.isEmpty(apiConfigs)) {
        return;
    }

    Map<String, ApiMethodConfig> restfulSignatures = Maps.newHashMap();

    Iterator<? extends ApiConfig> i = apiConfigs.iterator();
    ApiConfig first = i.next();
    validate(first, restfulSignatures);

    while (i.hasNext()) {
        ApiConfig config = i.next();
        Iterable<ApiConfigInconsistency<Object>> inconsistencies = config
                .getConfigurationInconsistencies(first);
        if (!Iterables.isEmpty(inconsistencies)) {
            throw new InconsistentApiConfigurationException(config, first, inconsistencies);
        }
        validate(config, restfulSignatures);
    }
}

From source file:com.google.devtools.build.lib.rules.android.DataBinding.java

/**
 * Should data binding support be enabled for this rule?
 *
 * <p>This is true if either the rule or any of its transitive dependencies declares data binding
 * support in its attributes./*  w ww.  ja  v a2 s  .  co  m*/
 *
 * <p>Data binding incurs additional resource processing and compilation work as well as
 * additional compile/runtime dependencies. But rules with data binding disabled will fail if
 * any data binding expressions appear in their layout resources.
 */
public static boolean isEnabled(RuleContext ruleContext) {
    if (ruleContext.attributes().has("enable_data_binding", Type.BOOLEAN)
            && ruleContext.attributes().get("enable_data_binding", Type.BOOLEAN)) {
        return true;
    } else {
        return !Iterables.isEmpty(ruleContext.getPrerequisites("deps", RuleConfiguredTarget.Mode.TARGET,
                UsesDataBindingProvider.class));
    }
}

From source file:org.apache.aurora.common.zookeeper.CandidateImpl.java

@Override
public Supplier<Boolean> offerLeadership(final Leader leader)
        throws JoinException, WatchException, InterruptedException {

    final Membership membership = group.join(IP_ADDRESS_DATA_SUPPLIER, leader::onDefeated);

    final AtomicBoolean elected = new AtomicBoolean(false);
    final AtomicBoolean abdicated = new AtomicBoolean(false);
    group.watch(memberIds -> {/*w  w  w . j a  v a  2s.  c om*/
        boolean noCandidates = Iterables.isEmpty(memberIds);
        String memberId = membership.getMemberId();

        if (noCandidates) {
            LOG.warn("All candidates have temporarily left the group: " + group);
        } else if (!Iterables.contains(memberIds, memberId)) {
            LOG.error("Current member ID {} is not a candidate for leader, current voting: {}", memberId,
                    memberIds);
        } else {
            boolean electedLeader = memberId.equals(getLeader(memberIds));
            boolean previouslyElected = elected.getAndSet(electedLeader);

            if (!previouslyElected && electedLeader) {
                LOG.info("Candidate {} is now leader of group: {}", membership.getMemberPath(), memberIds);

                leader.onElected(() -> {
                    membership.cancel();
                    abdicated.set(true);
                });
            } else if (!electedLeader) {
                if (previouslyElected) {
                    leader.onDefeated();
                }
                LOG.info("Candidate {} waiting for the next leader election, current voting: {}",
                        membership.getMemberPath(), memberIds);
            }
        }
    });

    return () -> !abdicated.get() && elected.get();
}

From source file:org.metaborg.intellij.languages.DefaultLanguageManager.java

/**
 * {@inheritDoc}/* w  w w  .  j  av  a 2  s.c  o m*/
 */
@Override
public Collection<ILanguageComponent> discover(final LanguageIdentifier id)
        throws LanguageLoadingFailedException {
    synchronized (this.objectLock) {
        this.logger.debug("Finding language '{}'.", id);
        @Nullable
        final FileObject rootLocation = this.languageSource.find(id);
        if (rootLocation == null) {
            this.logger.error("Could not find language with id '{}'.", id);
            return Collections.emptyList();
        }
        this.logger.debug("Found language '{}' at: {}", id, rootLocation);
        this.logger.debug("Requesting discovery of language '{}' at: {}", id, rootLocation);
        final Iterable<ILanguageDiscoveryRequest> requests;
        try {
            requests = this.discoveryService.request(rootLocation);
            if (Iterables.isEmpty(requests)) {
                this.logger.error("Got no discovery requests for language '{}' at: {}", id, rootLocation);
                return Collections.emptyList();
            }
        } catch (final MetaborgException e) {
            throw new LanguageLoadingFailedException("Could not load language '{}' at: {}", e, id,
                    rootLocation);
        }
        final Collection<ILanguageComponent> components = loadRange(requests);
        this.logger.debug("Discovered components language '{}': {}", id, components);
        return components;
    }
}

From source file:brooklyn.location.waratek.WaratekMachineLocation.java

@Override
public WaratekContainerLocation obtain(Map<?, ?> flags) throws NoMachinesAvailableException {
    Integer maxSize = jvm.getConfig(JavaVirtualMachine.JVC_CLUSTER_MAX_SIZE);
    Integer currentSize = jvm.getAttribute(WaratekAttributes.JVC_COUNT);
    Iterable<Entity> available = jvm.getAvailableJvcs();
    Entity entity = (Entity) flags.get("entity");
    if (LOG.isDebugEnabled()) {
        LOG.debug("JVM {}: {} containers, {} available, max {}",
                new Object[] { jvm.getJvmName(), currentSize, Iterables.size(available), maxSize });
    }/*  ww  w  .jav a  2s  . c om*/

    // also try to satisfy the affinty rules etc.

    // If there are no stopped JVCs then add a new one
    if (Iterables.isEmpty(available)) {
        if (currentSize != null && currentSize >= maxSize) {
            throw new NoMachinesAvailableException(
                    String.format("Limit of %d containers reached at %s", maxSize, jvm.getJvmName()));
        }

        // increase size of JVC cluster
        DynamicCluster cluster = jvm.getJvcCluster();
        Optional<Entity> added = cluster.addInSingleLocation(this, MutableMap.of("entity", entity));
        if (!added.isPresent()) {
            throw new NoMachinesAvailableException(
                    String.format("Failed to create containers reached in %s", jvm.getJvmName()));
        }
        return ((JavaVirtualContainer) added.get()).getDynamicLocation();
    } else {
        WaratekContainerLocation container = ((JavaVirtualContainer) Iterables.getLast(available))
                .getDynamicLocation();
        container.setEntity(entity);
        return container;
    }
}

From source file:com.eucalyptus.loadbalancing.config.LoadBalancingServiceBuilder.java

@SuppressWarnings("unchecked")
private boolean noOtherEnabled(final ServiceConfiguration config) {
    return Iterables.isEmpty(ServiceConfigurations.filter(LoadBalancing.class,
            Predicates.and(ServiceConfigurations.filterHostLocal(), ServiceConfigurations.filterEnabled(),
                    Predicates.not(Predicates.equalTo(config)))));
}

From source file:org.apache.cassandra.cql3.selection.Selection.java

/**
 * Checks if this selection contains static columns.
 * @return <code>true</code> if this selection contains static columns, <code>false</code> otherwise;
 */// ww  w .  j a  v a2s  .c  o m
public boolean containsStaticColumns() {
    if (!cfm.hasStaticColumns())
        return false;

    if (isWildcard())
        return true;

    return !Iterables.isEmpty(Iterables.filter(columns, STATIC_COLUMN_FILTER));
}

From source file:com.groupon.jenkins.dynamic.buildconfiguration.CompositeConfigSection.java

@Override
public Iterable<String> getValidationErrors() {
    Iterable<String> errors = super.getValidationErrors();
    if (Iterables.isEmpty(errors)) {
        List<String> allowedKeys = new ArrayList<String>(subSections.length);
        for (int i = 0; i < subSections.length; i++) {
            allowedKeys.add(subSections[i].getName());
        }/*from  www.  j  a  va 2  s  .c  o  m*/
        errors = Iterables.concat(errors, validateForRedundantKeys(allowedKeys));
        for (int i = 0; i < subSections.length; i++) {
            errors = Iterables.concat(errors, subSections[i].getValidationErrors());
        }

    }
    return errors;
}