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.apache.beam.runners.core.ProcessFnRunner.java

private static <T> BoundedWindow getUnderlyingWindow(KeyedWorkItem<String, T> kwi) {
    if (Iterables.isEmpty(kwi.elementsIterable())) {
        // ProcessFn sets only a single timer.
        TimerData timer = Iterables.getOnlyElement(kwi.timersIterable());
        return ((WindowNamespace) timer.getNamespace()).getWindow();
    } else {//from w  w  w  .  j  ava  2s .  c  o m
        // KWI must have a single element in elementsIterable, because it follows a GBK by a
        // uniquely generated key.
        // Additionally, windows must be exploded before GBKIntoKeyedWorkItems, so there's also
        // only a single window.
        WindowedValue<T> value = Iterables.getOnlyElement(kwi.elementsIterable());
        return Iterables.getOnlyElement(value.getWindows());
    }
}

From source file:org.eclipse.xtend.maven.AbstractXtend2CompilerMojo.java

protected void compile(XtendBatchCompiler xtend2BatchCompiler, String classPath, List<String> sourceDirectories,
        String outputPath) throws MojoExecutionException {
    Iterable<String> filtered = filter(sourceDirectories, FILE_EXISTS);
    if (Iterables.isEmpty(filtered)) {
        getLog().info("skip compiling sources because the configured directory '"
                + Iterables.toString(sourceDirectories) + "' does not exists.");
        return;//  w  ww.j  av a 2s.  co  m
    }
    getLog().debug("Set temp directory: " + getTempDirectory());
    xtend2BatchCompiler.setTempDirectory(getTempDirectory());
    getLog().debug("Set DeleteTempDirectory: " + false);
    xtend2BatchCompiler.setDeleteTempDirectory(false);
    getLog().debug("Set classpath: " + classPath);
    xtend2BatchCompiler.setClassPath(classPath);
    getLog().debug("Set source path: " + concat(File.pathSeparator, newArrayList(filtered)));
    xtend2BatchCompiler.setSourcePath(concat(File.pathSeparator, newArrayList(filtered)));
    getLog().debug("Set output path: " + outputPath);
    xtend2BatchCompiler.setOutputPath(outputPath);
    getLog().debug("Set encoding: " + encoding);
    xtend2BatchCompiler.setFileEncoding(encoding);
    if (!xtend2BatchCompiler.compile()) {
        throw new MojoExecutionException("Error compiling xtend sources in '"
                + concat(File.pathSeparator, newArrayList(filtered)) + "'.");
    }
}

From source file:org.lttng.scope.lttng.ust.core.analysis.debuginfo.internal.FileOffsetMapper.java

/**
 * Generate the callsite from a given binary file and address offset.
 *
 * Due to function inlining, it is possible for one offset to actually have
 * multiple call sites. We will return the most precise one (inner-most) we
 * have available.//from ww w.  j  a  v a2  s .  c  om
 *
 * @param file
 *            The binary file to look at
 * @param buildId
 *            The expected buildId of the binary file (is not verified at
 *            the moment)
 * @param offset
 *            The memory offset in the file
 * @return The corresponding call site
 */
public static @Nullable TmfCallsite getCallsiteFromOffset(File file, @Nullable String buildId, long offset) {
    Iterable<Addr2lineInfo> output = getAddr2lineInfo(file, buildId, offset);
    if (output == null || Iterables.isEmpty(output)) {
        return null;
    }
    Addr2lineInfo info = Iterables.getLast(output);
    String sourceFile = info.fSourceFileName;
    Long sourceLine = info.fSourceLineNumber;

    if (sourceFile == null) {
        /* Not enough information to provide a callsite */
        return null;
    }
    return new TmfCallsite(sourceFile, sourceLine);
}

From source file:org.eclipse.xtext.ui.editor.model.edit.BatchModification.java

public void apply(Iterable<IBatchableModification> modifications, IProgressMonitor monitor) {
    if (Iterables.isEmpty(modifications)) {
        return;/*from   w  ww  .  ja va2 s . c  om*/
    }
    try {
        new WorkspaceModifyOperation() {
            @Override
            protected void execute(IProgressMonitor monitor)
                    throws CoreException, InvocationTargetException, InterruptedException {
                applyInWorkspace(modifications, monitor);
            }
        }.run(monitor);
    } catch (InvocationTargetException | InterruptedException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.jpmml.evaluator.TargetUtil.java

/**
 * Evaluates the {@link Targets} element for {@link MiningFunctionType#CLASSIFICATION classification} models.
 *///from w w  w. jav  a2s  .c  om
static public Map<FieldName, ? extends ClassificationMap<?>> evaluateClassification(
        Map<FieldName, ? extends ClassificationMap<?>> predictions, ModelEvaluationContext context) {
    ModelEvaluator<?> modelEvaluator = context.getModelEvaluator();

    Targets targets = modelEvaluator.getTargets();
    if (targets == null || Iterables.isEmpty(targets)) {
        return predictions;
    }

    Map<FieldName, ClassificationMap<?>> result = Maps.newLinkedHashMap();

    Collection<? extends Map.Entry<FieldName, ? extends ClassificationMap<?>>> entries = predictions.entrySet();
    for (Map.Entry<FieldName, ? extends ClassificationMap<?>> entry : entries) {
        FieldName key = entry.getKey();
        ClassificationMap<?> value = entry.getValue();

        Target target = modelEvaluator.getTarget(key);
        if (target != null) {

            if (value == null) {
                value = getPriorProbabilities(target);
            }
        }

        result.put(key, value);
    }

    return result;
}

From source file:org.apache.aurora.scheduler.filter.ConstraintFilter.java

/**
 * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this
 * filter was created with.//ww  w.j a va 2  s . c  om
 *
 * @param constraint Scheduling filter to check.
 * @return A veto if the constraint is not satisfied based on the existing state of the job.
 */
Optional<Veto> getVeto(IConstraint constraint) {
    Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes,
            new NameFilter(constraint.getName()));
    Optional<IAttribute> attribute;
    if (Iterables.isEmpty(sameNameAttributes)) {
        attribute = Optional.absent();
    } else {
        Set<String> attributeValues = ImmutableSet
                .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES)));
        attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues)));
    }

    ITaskConstraint taskConstraint = constraint.getConstraint();
    switch (taskConstraint.getSetField()) {
    case VALUE:
        boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.<String>of()),
                taskConstraint.getValue());
        return matches ? Optional.<Veto>absent() : Optional.of(mismatchVeto(constraint.getName()));

    case LIMIT:
        if (!attribute.isPresent()) {
            return Optional.of(mismatchVeto(constraint.getName()));
        }

        boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(),
                cachedjobState);
        return satisfied ? Optional.<Veto>absent() : Optional.of(limitVeto(constraint.getName()));

    default:
        throw new SchedulerException(
                "Failed to recognize the constraint type: " + taskConstraint.getSetField());
    }
}

From source file:ezbake.data.graph.blueprints.visibility.VisibilityFilterElement.java

@Override
public Set<String> getPropertyKeys() {
    if (!hasAnyPermission(Permission.READ)) {
        return Collections.emptySet();
    }//from  ww  w . j a va 2  s .c om

    Set<String> allKeys = element.getPropertyKeys();
    Set<String> filteredKeys = new HashSet<>();
    for (String k : allKeys) {
        if (isVisibilityKey(k)) {
            filteredKeys.add(k);
        } else {
            Iterable<Map<String, Object>> values = context.getPropertyFilter().filter(element.getProperty(k),
                    Permission.READ);
            if (!Iterables.isEmpty(values)) {
                filteredKeys.add(k);
            }
        }
    }

    return filteredKeys;
}

From source file:com.google.gerrit.pgm.init.InitIndex.java

private boolean isEmptySite() {
    try (DirectoryStream<Path> files = Files.newDirectoryStream(site.resolve(gerrit.get("basePath")))) {
        return Iterables.isEmpty(files);
    } catch (IOException e) {
        return true;
    }//  www .  ja  v  a  2s .  c om
}

From source file:org.yakindu.sct.generator.core.execution.AbstractGeneratorEntryExecutor.java

protected boolean valid(GeneratorEntry entry) {
    if (skipValidation) {
        logger.log("Validation skipped...");
        return true;
    }/*from w  ww .j ava 2 s.c o m*/
    List<Issue> issues = validator.validate(entry.getElementRef().eResource(), CheckMode.ALL, null);
    Iterable<Issue> errors = Iterables.filter(issues, new Predicate<Issue>() {
        @Override
        public boolean apply(Issue input) {
            return input.getSeverity() == Severity.ERROR;
        }
    });
    if (!Iterables.isEmpty(errors)) {
        logger.log("The referenced model(" + ((NamedElement) entry.getElementRef()).getName()
                + ") contains errors and could not be generated:");
        for (Issue issue : errors) {
            logger.log(issue.getMessage());
        }
        return false;
    }
    return true;
}

From source file:org.eclipse.sirius.ui.tools.internal.actions.export.AbstractExportRepresentationsAction.java

/**
 * Collect the diagrams to export, get the corresponding sessionn compute
 * the export path and then show the path and file format dialog to the user
 * before exporting export the diagrams.
 *///from  w  ww.j a  v  a  2s . c om
@Override
public void run() {
    Collection<DRepresentation> collectedRepresentations = getDRepresentationToExport();
    Iterable<DRepresentation> dRepresentationsToExport = Iterables.filter(collectedRepresentations,
            Predicates.notNull());
    if (!Iterables.isEmpty(dRepresentationsToExport)) {
        DRepresentation firstDRepresentationToExport = dRepresentationsToExport.iterator().next();
        Session session = getSession(firstDRepresentationToExport);
        if (session != null) {
            IPath exportPath = getExportPath(firstDRepresentationToExport, session);

            if (exportPath != null) {
                exportRepresentation(exportPath, dRepresentationsToExport, session);
            }
        }
    }
}