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.ui.tool.internal.util.FinalParentHelper.java

private ISequenceEvent getFinalParentOnResize(final Range fullFinalRange) {
    Preconditions.checkArgument(request.isResize());
    final Collection<ISequenceEvent> remoteErrors = Sets.newHashSet();

    /*/* www .  j a va  2 s . c  o  m*/
     * A simple resizing can not change the parent of an execution.
     */
    ISequenceEvent finalParent = self.getParentEvent();
    /*
     * We must still check that the resizing is valid, in that it will not
     * cause an overlap/conflict with sibling events.
     */
    final Collection<ISequenceEvent> linkedSiblings = FinalParentHelper.computeLinkedSiblings(request);
    Iterable<ISequenceEvent> finalSiblings = EventEndHelper.getIndependantEvents(self,
            finalParent.getSubEvents());

    final Option<Lifeline> selfLifeline = self.getLifeline();
    Predicate<ISequenceEvent> sameLifeline = new Predicate<ISequenceEvent>() {
        public boolean apply(ISequenceEvent input) {
            Option<Lifeline> inputLifeline = input.getLifeline();
            boolean same = !inputLifeline.some()
                    || (selfLifeline.some() && inputLifeline.get() == selfLifeline.get());

            if (input instanceof Message) {
                Option<Lifeline> sourceLifeline = ((Message) input).getSourceLifeline();
                same = same || !sourceLifeline.some()
                        || (selfLifeline.some() && sourceLifeline.get() == selfLifeline.get());
                Option<Lifeline> tgtLifeline = ((Message) input).getTargetLifeline();
                same = same || !tgtLifeline.some()
                        || (selfLifeline.some() && tgtLifeline.get() == selfLifeline.get());
            }

            return same;
        }
    };

    Predicate<ISequenceEvent> intersectsFinalBounds = new Predicate<ISequenceEvent>() {
        public boolean apply(ISequenceEvent input) {
            Range inputRange = input.getVerticalRange();
            boolean intersection = inputRange.intersects(fullFinalRange) && !linkedSiblings.contains(input);
            // Some event could not be parents : states for examples.
            boolean includedInput = !self.getValidSubEventsRange().isEmpty()
                    && fullFinalRange.includes(inputRange.grown(1));

            if (input instanceof Message) {
                Message msg = (Message) input;

                if (msg.isReflective() && !includedInput) {
                    intersection = inputRange.intersects(fullFinalRange)
                            && !inputRange.includes(fullFinalRange);
                    includedInput = inputRange.includes(fullFinalRange);
                }

                if (intersection && msg.isCompoundMessage()) {
                    Iterable<Execution> compoundEvents = Iterables
                            .filter(EventEndHelper.getCompoundEvents(input), Execution.class);
                    if (!Iterables.isEmpty(compoundEvents)) {
                        Execution remoteExec = compoundEvents.iterator().next();
                        if (remoteExec != null && remoteExec.getEndMessage().some()
                                && !fullFinalRange.includes(remoteExec.getExtendedVerticalRange())) {
                            includedInput = false;
                            remoteErrors.add(remoteExec);
                        }
                    }
                }
            }
            return intersection && !includedInput;
        }
    };

    /*
     * Removes parent combined fragment to be able to resize an execution in
     * a combined fragment
     */
    Predicate<ISequenceEvent> notParentCombinedFragment = new Predicate<ISequenceEvent>() {
        public boolean apply(ISequenceEvent input) {
            if (input instanceof CombinedFragment && self.getLifeline().some()) {
                CombinedFragment combinedFragment = (CombinedFragment) input;
                return !(combinedFragment.computeCoveredLifelines().contains(self.getLifeline().get())
                        && combinedFragment.getVerticalRange().includes(fullFinalRange));
            }
            return true;
        }
    };

    Iterable<ISequenceEvent> invalids = Iterables.filter(finalSiblings,
            Predicates.and(sameLifeline, notParentCombinedFragment, intersectsFinalBounds));
    if (!Iterables.isEmpty(invalids)) {
        finalParent = null;
        for (ISequenceEvent ise : Iterables.concat(invalids, remoteErrors)) {
            Range verticalRange = ise.getVerticalRange();

            if (ise instanceof Message && ((Message) ise).isReflective()
                    && verticalRange.includes(self.getVerticalRange())) {
                verticalRange = new Range(verticalRange.getUpperBound(), verticalRange.getUpperBound());
            }

            if (request.isResizeFromBottom()) {
                Range errorRange = new Range(verticalRange.getLowerBound() - 1,
                        Math.max(verticalRange.getLowerBound(), fullFinalRange.getUpperBound()));
                expansionZone = expansionZone == null ? errorRange : errorRange.union(expansionZone);
            }
        }
    }
    return finalParent;
}

From source file:org.esupportail.publisher.repository.externals.ldap.LdapUserDaoImpl.java

private OrFilter orFilterOnUids(final Iterable<String> uids) {
    // needed since empty OrFilter() is true instead of false
    // we must not have an empty filter !
    // (https://jira.springsource.org/browse/LDAP-226)
    if (Iterables.isEmpty(uids))
        return null;

    OrFilter filter = new OrFilter();
    boolean emptyFilter = true;
    for (String uid : uids) {
        if (uid != null && !uid.trim().isEmpty()) {
            filter.or(new EqualsFilter(externalUserHelper.getUserIdAttribute(), uid));
            emptyFilter = false;//from   w  w  w.ja  v  a 2  s.  c  o  m
        }
    }
    if (emptyFilter)
        return null;
    return filter;
}

From source file:org.hibnet.jst.generator.JstJavaFileGenerator.java

public List<Issue> compile() {
    try {//from  w ww.j  a  v a2s .  c  om
        ResourceSet resourceSet = loadJstFiles();
        File sourceDirectory = createStubs(resourceSet);
        File classDirectory = createTempDir("classes");
        if (!preCompileStubs(sourceDirectory, classDirectory)) {
            log.debug(
                    "Compilation of stubs and existing Java code had errors. This is expected and usually is not a probblem.");
        }
        installJvmTypeProvider(resourceSet, classDirectory);
        EcoreUtil.resolveAll(resourceSet);
        List<Issue> issues = validate(resourceSet);
        Iterable<Issue> errors = Iterables.filter(issues, SeverityFilter.ERROR);
        if (!Iterables.isEmpty(errors)) {
            return issues;
        }
        generateJavaFiles(resourceSet);
    } finally {
        if (isDeleteTempDirectory()) {
            deleteTmpFolders();
        }
    }
    return null;
}

From source file:gov.nih.nci.firebird.data.SupplementalInvestigatorDataForm.java

@Transient
private Date getMostRecentPhrpCertificationDate() {
    Iterable<TrainingCertificate> certificatesWithEffectiveDates = getPhrpCertificatesWithEffectiveDates();
    Iterable<Date> certificateDates = getPhrpCertificateDates(certificatesWithEffectiveDates);
    return Iterables.isEmpty(certificateDates) ? null : Collections.max(Lists.newArrayList(certificateDates));
}

From source file:org.sosy_lab.cpachecker.core.algorithm.pdr.transition.Blocks.java

/**
 * The conjunction of the formulas extracted from the given blocks.
 *
 * @param pBlocks the blocks. The order of the blocks is expected to be
 * 'forward', e.g. from the program entry to a target state.
 * @param pExtractFormula a function for creating a formula for a block.
 * @param pFormulaManager the formula manager to be used for adjusting the
 * variable indices./*from   w w w .  j  a va 2s .  c  o m*/
 *
 * @return the conjunction of the formulas extracted from the given blocks,
 * in the provided order of the blocks and with the variable SSA indices for
 * each block formula adapted to the final SSA map of the preceding block.
 *
 * @throws CPATransferException if a CPATransferException occurs during the
 * extraction of a formula from a block.
 * @throws InterruptedException if the extraction of a formula from a block
 * is interrupted.
 */
private static BooleanFormula conjoinFormulas(Iterable<Block> pBlocks, BlockToFormula pExtractFormula,
        FormulaManagerView pFormulaManager) throws CPATransferException, InterruptedException {
    BooleanFormulaManager booleanFormulaManager = pFormulaManager.getBooleanFormulaManager();
    BooleanFormula formula = booleanFormulaManager.makeTrue();

    if (Iterables.isEmpty(pBlocks)) {
        return formula;
    }

    CFANode expectedPredecessorLocation = null;
    SSAMap previousBlockSuccessorContext = null;

    for (Block block : pBlocks) {
        Preconditions.checkArgument(
                expectedPredecessorLocation == null
                        || block.getPredecessorLocation().equals(expectedPredecessorLocation),
                "Blocks must connect.");
        BooleanFormula blockFormula = pExtractFormula.apply(block);
        SSAMap blockSuccessorContext = (block.getDirection() == AnalysisDirection.FORWARD
                ? block.getPrimedContext()
                : block.getUnprimedContext()).getSsa();
        if (previousBlockSuccessorContext != null) {
            final SSAMap previousContext = previousBlockSuccessorContext;
            blockFormula = Reindexer.reindex(blockFormula, blockSuccessorContext,
                    (var, i) -> previousContext.getIndex(var) + i - 1, pFormulaManager);
            previousBlockSuccessorContext = combine(previousBlockSuccessorContext, blockSuccessorContext,
                    blockFormula, pFormulaManager);
        } else {
            previousBlockSuccessorContext = Reindexer.adjustToFormula(blockFormula, blockSuccessorContext,
                    pFormulaManager);
        }
        formula = booleanFormulaManager.and(formula, blockFormula);

        expectedPredecessorLocation = block.getSuccessorLocation();
    }

    return formula;
}

From source file:eu.interedition.text.rdbms.RelationalTextRepository.java

public List<Text> load(Iterable<Long> ids) {
    if (Iterables.isEmpty(ids)) {
        return Collections.emptyList();
    }/* www .j av a  2s  . c  o  m*/

    final List<Long> idList = Lists.newArrayList(ids);
    final StringBuilder sql = new StringBuilder("select ");
    sql.append(selectTextFrom("t"));
    sql.append(" from text_content t where t.id in (");
    for (Iterator<Long> it = ids.iterator(); it.hasNext();) {
        it.next();
        sql.append("?").append(it.hasNext() ? ", " : "");
    }
    sql.append(")");

    return jt.query(sql.toString(), new RowMapper<Text>() {
        @Override
        public Text mapRow(ResultSet rs, int rowNum) throws SQLException {
            return mapTextFrom(rs, "t");
        }
    }, idList.toArray(new Object[idList.size()]));
}

From source file:com.google.googlejavaformat.java.RemoveUnusedImports.java

private static JCCompilationUnit parse(Context context, String javaInput) throws FormatterException {
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCCompilationUnit unit;/*  ww  w  .  ja va2s .c  o  m*/
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
            return javaInput;
        }
    };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    JavacParser parser = parserFactory.newParser(javaInput, /*keepDocComments=*/ true, /*keepEndPos=*/ true,
            /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
    Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables
            .filter(diagnostics.getDiagnostics(), Formatter::errorDiagnostic);
    if (!Iterables.isEmpty(errorDiagnostics)) {
        // error handling is done during formatting
        throw FormatterException.fromJavacDiagnostics(errorDiagnostics);
    }
    return unit;
}

From source file:org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper.java

private static boolean isFirstRegion(DDiagramElementContainer ddec) {
    EObject potentialRegionContainer = ddec.eContainer();
    if (potentialRegionContainer instanceof DNodeContainer) {
        Iterable<DDiagramElementContainer> regions = Iterables.filter(
                ((DNodeContainer) potentialRegionContainer).getOwnedDiagramElements(),
                DDiagramElementContainer.class);
        return !Iterables.isEmpty(regions) && ddec == Iterables.getFirst(regions, null);
    }//from   ww w  .  ja  v  a  2  s .  c o  m
    return false;
}

From source file:org.gradle.model.internal.registry.DefaultModelRegistry.java

public void remove(ModelPath path) {
    ModelNodeInternal node = modelGraph.find(path);
    if (node == null) {
        return;/*  w w  w . j a  v a  2  s  . c o  m*/
    }

    Iterable<? extends ModelNode> dependents = node.getDependents();
    if (Iterables.isEmpty(dependents)) {
        modelGraph.remove(node);
        ruleBindings.remove(node);
        unboundRules.remove(node.getCreatorBinder());
        unboundRules.removeAll(node.getInitializerRuleBinders());
    } else {
        throw new RuntimeException("Tried to remove model " + path + " but it is depended on by: "
                + Joiner.on(", ").join(dependents));
    }
}