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.facebook.presto.sql.ExpressionUtils.java

public static Expression binaryExpression(LogicalBinaryExpression.Type type, Iterable<Expression> expressions) {
    requireNonNull(type, "type is null");
    requireNonNull(expressions, "expressions is null");
    Preconditions.checkArgument(!Iterables.isEmpty(expressions), "expressions is empty");

    // build balanced tree for efficient recursive processing
    Queue<Expression> queue = new ArrayDeque<>(newArrayList(expressions));
    while (queue.size() > 1) {
        queue.add(new LogicalBinaryExpression(type, queue.remove(), queue.remove()));
    }//from   ww  w .j av  a2s .  c  o m
    return queue.remove();
}

From source file:fr.rjoakim.android.jonetouch.dialog.UpdateActionScriptMyDialog.java

private List<String> formatScriptValues() {
    String values = getEditTextValue(R.id.addOrUpdateActionScriptEditText);
    Iterable<String> iterable = Splitter.on(SEPARATOR).split(values);
    if (Iterables.isEmpty(iterable)) {
        return Lists.newArrayList(values.trim());
    } else {//from  ww w. ja v  a 2s .co m
        List<String> scripts = Lists.newArrayList();
        for (String s : iterable) {
            if (!Strings.isNullOrEmpty(s.trim())) {
                scripts.add(s);
            }
        }
        return scripts;
    }
}

From source file:org.nmdp.ngs.align.Alignments.java

/**
 * Return the maximum length in the specified ranges, or <code>-1</code> if ranges is empty.
 *
 * @param ranges ranges, must not be null, must not contain any null ranges, and all ranges must be [closed, open)
 * @return the maximum length in the specified ranges, or <code>-1</code> if ranges is empty
 *///from   w  ww  .  j  a va  2s  .c o m
public static long maximumLength(final Iterable<Range<Long>> ranges) {
    checkNotNull(ranges);
    if (Iterables.isEmpty(ranges)) {
        return -1L;
    }
    return Ordering.natural().max(lengths(ranges)).longValue();
}

From source file:org.gradle.api.reporting.model.internal.ModelNodeRenderer.java

private void maybePrintRules(ModelNode model, StyledTextOutput styledTextoutput) {
    Iterable<ModelRuleDescriptor> executedRules = uniqueExecutedRulesExcludingCreator(model);
    if (!Iterables.isEmpty(executedRules)) {
        printNestedAttributeTitle(styledTextoutput, "Rules:");
        for (ModelRuleDescriptor ruleDescriptor : executedRules) {
            printNestedAttribute(styledTextoutput, " " + ruleDescriptor.toString());
        }//from w  w  w .  jav a  2 s  . c om
    }
}

From source file:org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy.java

/**
 *
 * @param gcBefore//from w w  w.j  a  va2 s.  c om
 * @return
 */
private synchronized List<SSTableReader> getNextBackgroundSSTables(final int gcBefore) {
    if (Iterables.isEmpty(cfs.getSSTables(SSTableSet.LIVE)))
        return Collections.emptyList();

    Set<SSTableReader> uncompacting = ImmutableSet
            .copyOf(filter(cfs.getUncompactingSSTables(), sstables::contains));

    // Find fully expired SSTables. Those will be included no matter what.
    Set<SSTableReader> expired = Collections.emptySet();

    if (System.currentTimeMillis() - lastExpiredCheck > options.expiredSSTableCheckFrequency) {
        logger.debug("TWCS expired check sufficiently far in the past, checking for fully expired SSTables");
        expired = CompactionController.getFullyExpiredSSTables(cfs, uncompacting,
                cfs.getOverlappingLiveSSTables(uncompacting), gcBefore);
        lastExpiredCheck = System.currentTimeMillis();
    } else {
        logger.debug("TWCS skipping check for fully expired SSTables");
    }

    Set<SSTableReader> candidates = Sets.newHashSet(filterSuspectSSTables(uncompacting));

    List<SSTableReader> compactionCandidates = new ArrayList<>(
            getNextNonExpiredSSTables(Sets.difference(candidates, expired), gcBefore));
    if (!expired.isEmpty()) {
        logger.debug("Including expired sstables: {}", expired);
        compactionCandidates.addAll(expired);
    }

    return compactionCandidates;
}

From source file:org.apache.flex.compiler.internal.targets.JSTarget.java

@Override
public IJSApplication build(Collection<ICompilerProblem> problems) {
    buildStarted();//from   www.  ja v a2 s  . co m
    try {
        Iterable<ICompilerProblem> fatalProblems = getFatalProblems();
        if (!Iterables.isEmpty(fatalProblems)) {
            Iterables.addAll(problems, fatalProblems);
            return null;
        }

        Set<ICompilationUnit> compilationUnitSet = new HashSet<ICompilationUnit>();
        Target.RootedCompilationUnits rootedCompilationUnits = getRootedCompilationUnits();
        Iterables.addAll(problems, rootedCompilationUnits.getProblems());

        compilationUnitSet.addAll(rootedCompilationUnits.getUnits());

        buildAndCollectProblems(compilationUnitSet, problems);

        List<ICompilationUnit> reachableCompilationUnits = project
                .getReachableCompilationUnitsInSWFOrder(rootedCompilationUnits.getUnits());

        IJSApplication application = initializeApplication(reachableCompilationUnits);

        //            ISWF swf = initializeSWF(reachableCompilationUnits);
        //
        //            // make main frame for DoABC tags
        //            final SWFFrame mainFrame = new SWFFrame();
        //            swf.addFrame(mainFrame);
        //
        //            // Add definitions.
        //            for (final ICompilationUnit cu : compilationUnitSet)
        //            {
        //                // ignore externals
        //                if (isLinkageExternal(cu, targetSettings))
        //                    continue;
        //
        //                // ignore any resource bundles
        //                if (cu instanceof ResourceBundleCompilationUnit)
        //                    continue;
        //
        //                // Create a DoABC tag per compilation unit.
        //
        //                // Please add this API to SWFTarget. Thx.
        //                // protected Boolean addToFrame(ICompilationUnit cu, SWFFrame mainFrame) throws InterruptedException
        //                // final boolean tagsAdded = cu.getSWFTagsRequest().get().addToFrame(mainFrame);
        //                final boolean tagsAdded = addToFrame(cu, mainFrame);
        //                if (!tagsAdded)
        //                {
        //                    ICompilerProblem problem = new UnableToBuildSWFTagProblem(cu.getAbsoluteFilename());
        //                    problems.add(problem);
        //                }
        //            }
        //
        //            createLinkReport(problems);

        return application;
    } catch (BuildCanceledException bce) {
        return null;
    } catch (InterruptedException ie) {
        return null;
    } finally {
        buildFinished();
    }
}

From source file:org.vclipse.constraint.scoping.ConstraintScopeProvider.java

private IScope createCsticScope(Iterable<Class> classes) {
    Class cls = Iterables.getFirst(classes, null);
    Iterable<Class> restClasses = Iterables.skip(classes, 1);
    if (cls.getSuperClasses().isEmpty() && Iterables.isEmpty(restClasses)) {
        return Scopes.scopeFor(cls.getCharacteristics());
    } else {/*from w w  w . j  a va 2s .  co m*/
        return Scopes.scopeFor(cls.getCharacteristics(),
                createCsticScope(Iterables.concat(cls.getSuperClasses(), restClasses)));
    }
}

From source file:org.jboss.hal.ballroom.LabelBuilder.java

/**
 * Turns a list of names from the management model into a human readable enumeration wrapped in quotes and
 * separated with commas. The last name is separated with the specified conjunction.
 *
 * @return The list of names as human readable string or an empty string if the names are null or empty.
 *//*from  w ww  .  j a  v a2  s  . c o  m*/
public String enumeration(Iterable<String> names, String conjunction) {
    String enumeration = "";
    if (names != null && !Iterables.isEmpty(names)) {
        int size = Iterables.size(names);
        if (size == 1) {
            return QUOTE + label(names.iterator().next()) + QUOTE;
        } else if (size == 2) {
            return QUOTE + label(Iterables.getFirst(names, "")) + QUOTE + SPACE + conjunction + SPACE + QUOTE
                    + label(Iterables.getLast(names)) + QUOTE;
        } else {
            String last = Iterables.getLast(names);
            LinkedList<String> allButLast = new LinkedList<>();
            Iterables.addAll(allButLast, names);
            allButLast.removeLast();
            enumeration = allButLast.stream().map(name -> QUOTE + label(name) + QUOTE)
                    .collect(Collectors.joining(", "));
            enumeration = enumeration + SPACE + conjunction + SPACE + QUOTE + label(last) + QUOTE;
        }
    }
    return enumeration;
}

From source file:com.google.gerrit.server.config.SitePaths.java

@Inject
public SitePaths(@SitePath Path sitePath) throws IOException {
    site_path = sitePath;//from   w  w  w . java 2 s . c  om
    Path p = sitePath;

    bin_dir = p.resolve("bin");
    etc_dir = p.resolve("etc");
    lib_dir = p.resolve("lib");
    tmp_dir = p.resolve("tmp");
    plugins_dir = p.resolve("plugins");
    db_dir = p.resolve("db");
    data_dir = p.resolve("data");
    logs_dir = p.resolve("logs");
    mail_dir = etc_dir.resolve("mail");
    hooks_dir = p.resolve("hooks");
    static_dir = p.resolve("static");
    themes_dir = p.resolve("themes");
    index_dir = p.resolve("index");

    gerrit_sh = bin_dir.resolve("gerrit.sh");
    gerrit_war = bin_dir.resolve("gerrit.war");

    gerrit_config = etc_dir.resolve("gerrit.config");
    secure_config = etc_dir.resolve("secure.config");

    ssl_keystore = etc_dir.resolve("keystore");
    ssh_key = etc_dir.resolve("ssh_host_key");
    ssh_rsa = etc_dir.resolve("ssh_host_rsa_key");
    ssh_dsa = etc_dir.resolve("ssh_host_dsa_key");
    peer_keys = etc_dir.resolve("peer_keys");

    site_css = etc_dir.resolve(CSS_FILENAME);
    site_header = etc_dir.resolve(HEADER_FILENAME);
    site_footer = etc_dir.resolve(FOOTER_FILENAME);
    site_gitweb = etc_dir.resolve("gitweb_config.perl");

    boolean isNew;
    try (DirectoryStream<Path> files = Files.newDirectoryStream(site_path)) {
        isNew = Iterables.isEmpty(files);
    } catch (NoSuchFileException e) {
        isNew = true;
    }
    this.isNew = isNew;
}

From source file:org.dishevelled.bio.align.Alignments.java

/**
 * Return the maximum length in the specified ranges, or <code>-1</code> if ranges is empty.
 *
 * @param ranges ranges, must not be null, must not contain any null ranges, and all ranges must be [closed, open)
 * @return the maximum length in the specified ranges, or <code>-1</code> if ranges is empty
 *///from w  ww.j  a v a 2 s.  co  m
public static long maximumLength(final Iterable<Range<Long>> ranges) {
    checkNotNull(ranges);
    if (Iterables.isEmpty(ranges)) {
        return -1L;
    }
    return Ordering.natural().max(lengths(ranges));
}