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:io.sarl.maven.docs.generator.SARLDocGenerate.java

@Override
protected void compile(XtendBatchCompiler xtend2BatchCompiler, String classPath, List<String> sourceDirectories,
        String outputPath) throws MojoExecutionException {
    configureWorkspace(sourceDirectories, outputPath);
    this.resourceSetProvider.get().eAdapters().clear();
    xtend2BatchCompiler.setResourceSetProvider(this.resourceSetProvider);
    MavenProjectAdapter.install(this.resourceSetProvider.get(), this.project);
    Iterable<String> filtered = Iterables.filter(sourceDirectories, FILE_EXISTS);
    if (Iterables.isEmpty(filtered)) {
        getLog().info("skip compiling sources because the configured directory '" //$NON-NLS-1$
                + Iterables.toString(sourceDirectories) + "' does not exists."); //$NON-NLS-1$
        return;/*from   w  w w. jav a2 s.com*/
    }
    getLog().debug("Set temp directory: " + getTempDirectory()); //$NON-NLS-1$
    xtend2BatchCompiler.setTempDirectory(getTempDirectory());
    getLog().debug("Set DeleteTempDirectory: " + false); //$NON-NLS-1$
    xtend2BatchCompiler.setDeleteTempDirectory(false);
    getLog().debug("Set classpath: " + classPath); //$NON-NLS-1$
    xtend2BatchCompiler.setClassPath(classPath);
    getLog().debug("Set source path: " + Strings.concat(File.pathSeparator, Lists.newArrayList(filtered))); //$NON-NLS-1$
    xtend2BatchCompiler.setSourcePath(Strings.concat(File.pathSeparator, Lists.newArrayList(filtered)));
    getLog().debug("Set output path: " + outputPath); //$NON-NLS-1$
    xtend2BatchCompiler.setOutputPath(outputPath);
    getLog().debug("Set encoding: " + this.encoding); //$NON-NLS-1$
    xtend2BatchCompiler.setFileEncoding(this.encoding);
    getLog().debug("Set writeTraceFiles: " + this.writeTraceFiles); //$NON-NLS-1$
    xtend2BatchCompiler.setWriteTraceFiles(this.writeTraceFiles);
    if (!xtend2BatchCompiler.compile()) {
        throw new MojoExecutionException("Error compiling xtend sources in '" //$NON-NLS-1$
                + Strings.concat(File.pathSeparator, Lists.newArrayList(filtered)) + "'."); //$NON-NLS-1$
    }
}

From source file:com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.java

/**
 * Removes entries in {@code valuesToInject} whose values are equal to the present values in the
 * graph./*from  w  ww  .j av  a2 s.  co  m*/
 */
private void pruneInjectedValues(Map<SkyKey, SkyValue> valuesToInject) {
    for (Iterator<Entry<SkyKey, SkyValue>> it = valuesToInject.entrySet().iterator(); it.hasNext();) {
        Entry<SkyKey, SkyValue> entry = it.next();
        SkyKey key = entry.getKey();
        SkyValue newValue = entry.getValue();
        NodeEntry prevEntry = graph.get(null, Reason.OTHER, key);
        if (prevEntry != null && prevEntry.isDone()) {
            try {
                Iterable<SkyKey> directDeps = prevEntry.getDirectDeps();
                Preconditions.checkState(Iterables.isEmpty(directDeps), "existing entry for %s has deps: %s",
                        key, directDeps);
                if (newValue.equals(prevEntry.getValue()) && !valuesToDirty.contains(key)
                        && !valuesToDelete.contains(key)) {
                    it.remove();
                }
            } catch (InterruptedException e) {
                throw new IllegalStateException("InMemoryGraph does not throw: " + entry + ", " + prevEntry, e);
            }
        }
    }
}

From source file:org.apache.beam.runners.direct.EvaluationContext.java

private Iterable<? extends CommittedBundle<?>> commitBundles(Iterable<? extends UncommittedBundle<?>> bundles) {
    ImmutableList.Builder<CommittedBundle<?>> completed = ImmutableList.builder();
    for (UncommittedBundle<?> inProgress : bundles) {
        AppliedPTransform<?, ?, ?> producing = graph.getProducer(inProgress.getPCollection());
        TransformWatermarks watermarks = watermarkManager.getWatermarks(producing);
        CommittedBundle<?> committed = inProgress.commit(watermarks.getSynchronizedProcessingOutputTime());
        // Empty bundles don't impact watermarks and shouldn't trigger downstream execution, so
        // filter them out
        if (!Iterables.isEmpty(committed.getElements())) {
            completed.add(committed);/*w  w w .  ja  v  a  2  s  .  c  o  m*/
        }
    }
    return completed.build();
}

From source file:org.eclipse.viatra.addon.validation.runtime.annotation.ConstraintAnnotationValidator.java

private List<Variable> computeVariableListFromListValue(IIssueCallback validator, final Pattern pattern,
        ValueReference listValue, String issueCode) {
    List<Variable> variables = Lists.newArrayList();
    Iterable<VariableReference> variableReferenceList = transformVariableReferenceList(listValue);
    Iterable<StringValue> stringValueList = transformStringList(listValue);

    if (!Iterables.isEmpty(variableReferenceList) && !Iterables.isEmpty(stringValueList)) {
        validator.error("Must not mix string and variable values!", listValue, null, issueCode);
    }/*from  ww w .  jav  a  2 s  . c  o  m*/

    for (StringValue key : stringValueList) {
        Optional<Variable> parameterByName = PatternLanguageHelper.getParameterByName(pattern, key.getValue());
        if (parameterByName.isPresent()) {
            variables.add(parameterByName.get());
            validator.warning("Deprecated: remove quotes to use variable reference instead!", key, null,
                    issueCode);
        } else {
            validator.error(key.getValue() + " is not a pattern parameter!", key, null, issueCode);
        }
    }
    for (VariableReference key : variableReferenceList) {
        if (key.getVariable() != null) {
            variables.add(key.getVariable());
        }
    }
    return variables;
}

From source file:com.google.devtools.build.lib.rules.python.PyCommon.java

/**
 * Returns a mutable List of the source Artifacts.
 *///from   w  ww .ja v a 2s. com
public List<Artifact> validateSrcs() {
    List<Artifact> sourceFiles = new ArrayList<>();
    // TODO(bazel-team): Need to get the transitive deps closure, not just the
    //                 sources of the rule.
    for (TransitiveInfoCollection src : ruleContext.getPrerequisitesIf("srcs", Mode.TARGET,
            FileProvider.class)) {
        // Make sure that none of the sources contain hyphens.
        if (Util.containsHyphen(src.getLabel().getPackageFragment())) {
            ruleContext.attributeError("srcs",
                    src.getLabel() + ": paths to Python packages may not contain '-'");
        }
        Iterable<Artifact> pySrcs = FileType.filter(src.getProvider(FileProvider.class).getFilesToBuild(),
                PyRuleClasses.PYTHON_SOURCE);
        Iterables.addAll(sourceFiles, pySrcs);
        if (Iterables.isEmpty(pySrcs)) {
            ruleContext.attributeWarning("srcs",
                    "rule '" + src.getLabel() + "' does not produce any Python source files");
        }
    }

    LanguageDependentFragment.Checker.depsSupportsLanguage(ruleContext, PyRuleClasses.LANGUAGE);
    return convertedFiles != null ? ImmutableList.copyOf(convertedFiles.values()) : sourceFiles;
}

From source file:com.google.devtools.j2objc.gen.TypeDeclarationGenerator.java

/**
 * Prints the list of instance variables in a type.
 *//*from  ww w . ja  v a  2s.com*/
protected void printInstanceVariables() {
    Iterable<VariableDeclarationFragment> fields = getInstanceFields();
    if (Iterables.isEmpty(fields)) {
        newline();
        return;
    }
    // Need direct access to fields possibly from inner classes that are
    // promoted to top level classes, so must make all visible fields public.
    println(" {");
    println(" @public");
    indent();
    FieldDeclaration lastDeclaration = null;
    boolean needsAsterisk = false;
    for (VariableDeclarationFragment fragment : fields) {
        IVariableBinding varBinding = fragment.getVariableBinding();
        FieldDeclaration declaration = (FieldDeclaration) fragment.getParent();
        if (declaration != lastDeclaration) {
            if (lastDeclaration != null) {
                println(";");
            }
            lastDeclaration = declaration;
            JavadocGenerator.printDocComment(getBuilder(), declaration.getJavadoc());
            printIndent();
            if (BindingUtil.isWeakReference(varBinding) && !BindingUtil.isVolatile(varBinding)) {
                // We must add this even without -use-arc because the header may be
                // included by a file compiled with ARC.
                print("__unsafe_unretained ");
            }
            String objcType = getDeclarationType(varBinding);
            needsAsterisk = objcType.endsWith("*");
            if (needsAsterisk) {
                // Strip pointer from type, as it will be added when appending fragment.
                // This is necessary to create "Foo *one, *two;" declarations.
                objcType = objcType.substring(0, objcType.length() - 2);
            }
            print(objcType);
            print(' ');
        } else {
            print(", ");
        }
        if (needsAsterisk) {
            print('*');
        }
        print(nameTable.getVariableShortName(varBinding));
    }
    println(";");
    unindent();
    println("}");
}

From source file:com.palantir.atlasdb.keyvalue.partition.BasicPartitionMap.java

@Override
public Map<KeyValueService, NavigableSet<byte[]>> getServicesForRowsRead(String tableName,
        Iterable<byte[]> rows) {
    Map<KeyValueService, NavigableSet<byte[]>> result = Maps.newHashMap();
    for (byte[] row : rows) {
        Set<KeyValueService> services = getServicesHavingRow(row);
        for (KeyValueService kvs : services) {
            if (!result.containsKey(kvs)) {
                result.put(kvs, Sets.<byte[]>newTreeSet(UnsignedBytes.lexicographicalComparator()));
            }/*from  w  ww .ja  v  a  2  s .  c  om*/
            assert !result.get(kvs).contains(row);
            result.get(kvs).add(row);
        }
    }
    if (!Iterables.isEmpty(rows)) {
        assert result.keySet().size() >= quorumParameters.getReplicationFactor();
    }
    return result;
}

From source file:com.google.devtools.build.lib.rules.objc.BinaryLinkingTargetFactory.java

private void assertLibraryOrSources(ObjcProvider objcProvider, RuleContext ruleContext)
        throws RuleErrorException {
    if (Iterables.isEmpty(objcProvider.get(LIBRARY)) // Includes sources from this target.
            && Iterables.isEmpty(objcProvider.get(IMPORTED_LIBRARY))) {
        ruleContext.throwWithRuleError(REQUIRES_AT_LEAST_ONE_LIBRARY_OR_SOURCE_FILE);
    }//  www . ja  v a2s.c o  m
}

From source file:com.palantir.atlasdb.keyvalue.jdbc.JdbcKeyValueService.java

private Map<Cell, Value> getRowsAllColumns(final String tableName, final Iterable<byte[]> rows,
        final long timestamp) {
    if (Iterables.isEmpty(rows)) {
        return ImmutableMap.of();
    }//from   w  ww .  java2s. co  m
    return run(new Function<DSLContext, Map<Cell, Value>>() {
        @Override
        public Map<Cell, Value> apply(DSLContext ctx) {
            Select<? extends Record> query = getLatestTimestampQueryAllColumns(ctx, tableName,
                    ImmutableList.copyOf(rows), timestamp);
            Result<? extends Record> records = fetchValues(ctx, tableName, query);
            Map<Cell, Value> results = Maps.newHashMapWithExpectedSize(records.size());
            for (Record record : records) {
                results.put(Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)),
                        Value.create(record.getValue(A_VALUE), record.getValue(A_TIMESTAMP)));
            }
            return results;
        }
    });
}

From source file:ezbake.deployer.utilities.YamlManifestFileReader.java

private void setArtifactInfo(Map<String, Object> ymlManifest, ArtifactInfo artifactInfo,
        ApplicationInfo applicationInfo) {
    Map<String, Object> subMap = (Map<String, Object>) ymlManifest.get(RootManifestKeys.resources.getName());
    if (subMap != null)
        artifactInfo.setResourceRequirements(toRequirements(subMap));
    String value = toString(ymlManifest.get(RootManifestKeys.language.getName()));
    if (value != null)
        artifactInfo.setLanguage(languageFromString(value));
    updateValue(ymlManifest, artifactInfo, ArtifactInfo._Fields.BIN, ArtifactKeys.bin);
    updateValue(ymlManifest, artifactInfo, ArtifactInfo._Fields.PURGEABLE, ArtifactKeys.purgeable,
            Boolean.class, Optional.of(false));
    updateValue(ymlManifest, artifactInfo, ArtifactInfo._Fields.SYSTEM_LOGFILE_DISABLED,
            ArtifactKeys.disableSystemLogfile, Boolean.class, Optional.of(false));

    Iterable<String> iterable = (Iterable<String>) ymlManifest.get(ArtifactKeys.config.getName());
    if (iterable != null && !Iterables.isEmpty(iterable)) {
        artifactInfo.setConfig(Sets.newHashSet(iterable));
    }/*from w w  w  . java2s  .  co  m*/
    setApplicationInfo(ymlManifest, applicationInfo, false);
    Map<String, Object> innerArtifactInfo = (Map<String, Object>) ymlManifest
            .get(RootManifestKeys.artifactInfo.getName());
    if (innerArtifactInfo != null)
        setArtifactInfo(innerArtifactInfo, artifactInfo, applicationInfo);
}