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:com.google.devtools.build.lib.skyframe.ArtifactFunction.java

private static TreeArtifactValue createTreeArtifactValueFromActionTemplate(SpawnActionTemplate actionTemplate,
        Artifact treeArtifact, Environment env) throws ArtifactFunctionException, InterruptedException {
    // Request the list of expanded actions from the ActionTemplate.
    ActionTemplateExpansionValue expansionValue = (ActionTemplateExpansionValue) env
            .getValue(ActionTemplateExpansionValue.key(actionTemplate));

    // The expanded actions are not yet available.
    if (env.valuesMissing()) {
        return null;
    }//from w  ww  . ja  va2 s  .  c o  m

    // Execute the expanded actions in parallel.
    Iterable<SkyKey> expandedActionExecutionKeys = ActionExecutionValue
            .keys(expansionValue.getExpandedActions());
    Map<SkyKey, SkyValue> expandedActionValueMap = env.getValues(expandedActionExecutionKeys);

    // The execution values of the expanded actions are not yet all available.
    if (env.valuesMissing()) {
        return null;
    }

    // Aggregate the ArtifactValues for individual TreeFileArtifacts into a TreeArtifactValue for
    // the parent TreeArtifact.
    ImmutableMap.Builder<TreeFileArtifact, FileArtifactValue> map = ImmutableMap.builder();
    for (Map.Entry<SkyKey, SkyValue> entry : expandedActionValueMap.entrySet()) {
        SkyKey expandedActionExecutionKey = entry.getKey();
        ActionExecutionValue actionExecutionValue = (ActionExecutionValue) entry.getValue();
        Action expandedAction = (Action) expandedActionExecutionKey.argument();

        Iterable<TreeFileArtifact> treeFileArtifacts = findActionOutputsWithMatchingParent(expandedAction,
                treeArtifact);

        Preconditions.checkState(!Iterables.isEmpty(treeFileArtifacts),
                "Action %s does not output TreeFileArtifact under %s", expandedAction, treeArtifact);

        for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
            FileArtifactValue value = createSimpleFileArtifactValue(treeFileArtifact, expandedAction,
                    actionExecutionValue, env);
            map.put(treeFileArtifact, value);
        }
    }

    // Return the aggregated TreeArtifactValue.
    return TreeArtifactValue.create(map.build());
}

From source file:org.polarsys.reqcycle.ocl.utils.OCLUtilities.java

/**
 * Gets operations that could be used to match uml elements to a data type. These operations must have a specific name and signature (no parameter, return boolean).
 *///  w  ww  .  j a va 2s .  c o m
public static Iterable<DefOperationCS> getMatchingOperations(final IRequirementType type,
        BaseResource resource) {
    Collection<DefOperationCS> operations = getOperations(resource);
    if (operations == null || Iterables.isEmpty(operations)) {
        return Collections.emptyList();
    }
    return Iterables.filter(operations, new Predicate<DefOperationCS>() {

        @Override
        public boolean apply(DefOperationCS arg0) {
            TypedRefCS operationReturnType = arg0.getOwnedType();
            if (!arg0.getParameters().isEmpty()) {
                return false;
            }
            if (operationReturnType instanceof PrimitiveTypeRefCS) {
                String returnType = ((PrimitiveTypeRefCS) operationReturnType).getName();
                if (!"Boolean".equals(returnType)) { //$NON-NLS-1$
                    return false;
                }
            }
            return arg0.getName().replaceAll("\\s", "").equalsIgnoreCase(getOperationRequiredName(type));
        }
    });
}

From source file:com.sk89q.guavabackport.collect.Range.java

public boolean containsAll(final Iterable<? extends C> values) {
    if (Iterables.isEmpty((Iterable) values)) {
        return true;
    }//w  ww.  j av a2s .c  o  m
    if (values instanceof SortedSet) {
        final SortedSet<? extends C> set = cast(values);
        final Comparator<?> comparator = set.comparator();
        if (Ordering.natural().equals(comparator) || comparator == null) {
            return this.contains((C) set.first()) && this.contains((C) set.last());
        }
    }
    for (final C value : values) {
        if (!this.contains(value)) {
            return false;
        }
    }
    return true;
}

From source file:org.opendaylight.openflowplugin.applications.frsync.util.ReconcileUtil.java

/**
 * @param nodeId             target node
 * @param installedGroupsArg groups resent on device
 * @param pendingGroups      groups configured for device
 * @param gatherUpdates      check content of pending item if present on device (and create update task eventually)
 * @return list of safe synchronization steps
 *//* w  ww.j  a  v  a 2  s .  c  o m*/
public static List<ItemSyncBox<Group>> resolveAndDivideGroupDiffs(final NodeId nodeId,
        final Map<Long, Group> installedGroupsArg, final Collection<Group> pendingGroups,
        final boolean gatherUpdates) {
    final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
    final List<ItemSyncBox<Group>> plan = new ArrayList<>();

    while (!Iterables.isEmpty(pendingGroups)) {
        final ItemSyncBox<Group> stepPlan = new ItemSyncBox<>();
        final Iterator<Group> iterator = pendingGroups.iterator();
        final Map<Long, Group> installIncrement = new HashMap<>();

        while (iterator.hasNext()) {
            final Group group = iterator.next();

            final Group existingGroup = installedGroups.get(group.getGroupId().getValue());
            if (existingGroup != null) {
                if (!gatherUpdates) {
                    iterator.remove();
                } else {
                    // check buckets and eventually update
                    if (group.equals(existingGroup)) {
                        iterator.remove();
                    } else {
                        if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                            iterator.remove();
                            LOG.trace("Group {} on device {} differs - planned for update", group.getGroupId(),
                                    nodeId);
                            stepPlan.getItemsToUpdate()
                                    .add(new ItemSyncBox.ItemUpdateTuple<>(existingGroup, group));
                        }
                    }
                }
            } else if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                iterator.remove();
                installIncrement.put(group.getGroupId().getValue(), group);
                stepPlan.getItemsToPush().add(group);
            }
        }

        if (!stepPlan.isEmpty()) {
            // atomic update of installed flows in order to keep plan portions clean of local group dependencies
            installedGroups.putAll(installIncrement);
            plan.add(stepPlan);
        } else if (!pendingGroups.isEmpty()) {
            LOG.warn("Failed to resolve and divide groups into preconditions-match based ordered plan: {}, "
                    + "resolving stuck at level {}", nodeId.getValue(), plan.size());
            throw new IllegalStateException("Failed to resolve and divide groups when matching preconditions");
        }
    }

    return plan;
}

From source file:com.clarkparsia.empire.ds.DataSourceUtil.java

/**
 * Return the type of the resource in the data source.
 * @param theSource the data source/*from ww w  .j av a  2 s.co m*/
 * @param theConcept the concept whose type to lookup
 * @return the rdf:type of the concept, or null if there is an error or one cannot be found.
 */
public static org.openrdf.model.Resource getType(DataSource theSource, Resource theConcept) {
    Iterable<org.openrdf.model.Resource> aTypes = getTypes(theSource, theConcept);
    if (aTypes == null || Iterables.isEmpty(aTypes)) {
        return null;
    } else {
        return Iterables.getFirst(aTypes, null);
    }
}

From source file:com.b2international.snowowl.snomed.reasoner.server.classification.EquivalentConceptMerger.java

private void removeOrDeactivate(Collection<Concept> conceptsToRemove) {
    if (!Iterables.isEmpty(conceptsToRemove)) {
        final SnomedInactivationPlan plan = new SnomedInactivationPlan(this.editingContext);
        for (final Concept concept : conceptsToRemove) {
            if (concept.isReleased()) {
                this.editingContext.inactivateConcepts(plan, new NullProgressMonitor(), concept.cdoID());
            } else {
                this.editingContext.delete(concept, false);
            }// w  w  w .  j av  a2 s.c om
        }
        plan.performInactivation(InactivationReason.RETIRED, null);
    }
}

From source file:com.google.devtools.build.lib.rules.cpp.WriteBuildInfoHeaderAction.java

private boolean isUnconditional() {
    // Because of special handling in the MetadataHandler, changed volatile build
    // information does not trigger relinking of all libraries that have
    // linkstamps. But we do want to regenerate the header in case libraries are
    // relinked because of other reasons.
    // Without inputs the contents of the header do not change, so there is no
    // point in executing the action again in that case.
    return writeVolatileInfo && !Iterables.isEmpty(getInputs());
}

From source file:net.joala.bdd.aop.JUnitAopStepsLogger.java

/**
 * <p>//  w w  w  .ja v a 2 s . c  o  m
 * Describe the step arguments (most likely references) if they are describable. Ignore them if
 * they are not self describable.
 * </p>
 *
 * @param stepDescription description to add description of arguments to
 * @param args            arguments to describe
 */
private void describeArguments(@Nonnull final Description stepDescription, @Nonnull final Object[] args) {
    final List<Object> argsList = Arrays.asList(args);
    final Iterable<Object> descArgs = Iterables.filter(argsList, new IsSelfDescribing());
    final boolean hasDescribableArgs = !Iterables.isEmpty(descArgs);
    if (hasDescribableArgs) {
        stepDescription.appendText(" (");
        final Iterable<String> transformed = Iterables.transform(descArgs, new DescribeArgument());
        stepDescription.appendText(Joiner.on(',').join(transformed));
        stepDescription.appendText(")");
    }
}

From source file:com.google.api.server.spi.config.model.ApiConfig.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    } else if (o instanceof ApiConfig) {
        ApiConfig config = (ApiConfig) o;
        return Iterables.isEmpty(getConfigurationInconsistencies(config))
                && apiClassConfig.equals(config.apiClassConfig);
    } else {//from w ww.  ja  v  a  2s  . c  om
        return false;
    }
}

From source file:com.anathema_roguelike.characters.Character.java

public boolean hasAbility(Class<? extends Ability> ability) {
    return !Iterables.isEmpty(getAbilities(ability));
}