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.amanzi.awe.render.core.utils.RenderMenuUtils.java

public static Pair<IRenderableModel, Iterable<IDataElement>> getLocationElements(
        final IStructuredSelection selection) {
    IRenderableModel renderableModel = null;
    boolean incorrect = false;

    Iterable<IDataElement> elementsIterable = Iterables.emptyIterable();

    for (final Object element : selection.toArray()) {
        if (element instanceof IUIItem) {
            final IUIItem item = (IUIItem) element;

            final IRenderableModel itemModel = getRenderableModel(item);

            // check UI Item is correct
            if (itemModel == null) {
                incorrect = true;//  w  w  w  .j a v  a 2s.  co  m
                break;
            }

            // check model is same for all elements
            if (renderableModel == null) {
                renderableModel = itemModel;
            } else if (!itemModel.equals(renderableModel)) {
                incorrect = true;
                break;
            }

            // check internal elements
            final Iterable<IDataElement> subIterable = collectDataElements(item, renderableModel);

            if (subIterable != null) {
                elementsIterable = Iterables.concat(elementsIterable, subIterable);
            }

        }
    }

    // check element locations
    if (!incorrect && !Iterables.isEmpty(elementsIterable)) {
        incorrect = Iterables.isEmpty(renderableModel.getElementsLocations(elementsIterable));
    }

    if (!incorrect) {
        return new ImmutablePair<IRenderableModel, Iterable<IDataElement>>(renderableModel, elementsIterable);
    }

    return null;
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.query.EdgeTargetQuery.java

/**
 * Test whether the element is the folding point of any edge which supports
 * folding and is visible./*w w  w. ja va 2  s .  c o  m*/
 * 
 * @return <code>true</code> if the element is the folding point of any edge
 *         which supports folding and is visible.
 */
public boolean isFoldingPoint() {
    Iterable<DEdge> foldables = getAllFoldableEdges();
    return !Iterables.isEmpty(foldables);
}

From source file:com.reprezen.swagedit.model.Model.java

/**
 * Parses all files into a list of models.
 * /*from   www  . j a  v  a  2  s . c om*/
 * @param files
 * @return list of models
 */
public static Iterable<Model> parseYaml(Iterable<IFile> files) {
    if (files == null || Iterables.isEmpty(files)) {
        return Lists.newArrayList();
    }

    final SwaggerSchema schema = Activator.getDefault().getSchema();
    final List<Model> models = Lists.newArrayList();
    for (IFile file : files) {
        Model model = new Model(schema, file.getFullPath());
        try {
            reader(model).readValue(file.getLocationURI().toURL());
        } catch (IllegalArgumentException | IOException e) {
            e.printStackTrace();
            continue;
        }

        models.add(model);
    }
    return models;
}

From source file:com.b2international.snowowl.datastore.server.snomed.ModuleDependencyCollector.java

public Multimap<String, String> getModuleDependencies(Iterable<Long> storageKeys) throws IOException {
    if (Iterables.isEmpty(storageKeys)) {
        return ImmutableMultimap.of();
    }//  w w w  . j  av a2  s  .co  m

    final Multimap<String, String> moduleDependencies = HashMultimap.create();

    final Multimap<String, String> componentIdsByReferringModule = HashMultimap.create();
    collectConceptModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectDescriptionModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectRelationshipModuleDependencies(storageKeys, componentIdsByReferringModule);
    collectMemberModuleDependencies(storageKeys, componentIdsByReferringModule);

    // iterate over each module and get modules of all components registered to componentsByReferringModule
    for (String module : ImmutableSet.copyOf(componentIdsByReferringModule.keySet())) {
        final Collection<String> dependencies = componentIdsByReferringModule.removeAll(module);
        for (Class<? extends SnomedComponentDocument> type : CORE_COMPONENT_TYPES) {
            Query<String[]> dependencyQuery = Query.select(String[].class).from(type)
                    .fields(SnomedComponentDocument.Fields.ID, SnomedComponentDocument.Fields.MODULE_ID)
                    .where(SnomedComponentDocument.Expressions.ids(dependencies)).limit(10000).build();
            for (Hits<String[]> dependencyHits : searcher.scroll(dependencyQuery)) {
                for (String[] idAndModule : dependencyHits) {
                    String targetModule = idAndModule[1];
                    if (!module.equals(targetModule)) {
                        moduleDependencies.put(module, targetModule);
                    }
                }
            }
        }
    }

    return moduleDependencies;
}

From source file:org.sonar.java.checks.xml.spring.SingleConnectionFactoryCheck.java

private boolean hasPropertyAsChild(Node bean, XmlCheckContext context) {
    return !Iterables.isEmpty(context.evaluate(reconnectOnExceptionPropertyValueExpression, bean));
}

From source file:org.fuusio.api.nfc.SmartPosterRecord.java

/**
 * Returns the first element of {@code elements} which is an instance of {@code type}, or
 * {@code null} if no such element exists.
 *//*from   w w w . jav  a2s.c  o  m*/
private static <T> T getFirstIfExists(final Iterable<?> elements, final Class<T> type) {
    final Iterable<T> filtered = Iterables.filter(elements, type);
    T instance = null;

    if (!Iterables.isEmpty(filtered)) {
        instance = Iterables.get(filtered, 0);
    }
    return instance;
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.query.ISequenceElementQuery.java

/**
 * Return the flagged absolute bounds, ie the last known logical bounds.
 * //from  www  .j a v a 2 s.  com
 * @return the flagged absolute bounds.
 */
public Rectangle getFlaggedAbsoluteBounds() {
    Rectangle bounds = new Rectangle();
    if (event.getNotationView() != null && event.getNotationView().getElement() instanceof DDiagramElement) {
        DDiagramElement dde = (DDiagramElement) event.getNotationView().getElement();
        Iterable<AbsoluteBoundsFilter> flags = Iterables.filter(dde.getGraphicalFilters(),
                AbsoluteBoundsFilter.class);
        if (!Iterables.isEmpty(flags)) {
            AbsoluteBoundsFilter flag = flags.iterator().next();
            bounds.x = safeGetInt(flag.getX());
            bounds.y = safeGetInt(flag.getY());
            bounds.width = safeGetInt(flag.getWidth());
            bounds.height = safeGetInt(flag.getHeight());
        }
    }
    return bounds;
}

From source file:com.groupon.jenkins.extensions.DotCiExtensionsHelper.java

private <T extends DotCiExtension> List<T> createPlugins(List<?> pluginSpecs, Class<T> extensionClass) {
    if (Iterables.isEmpty(pluginSpecs)) {
        return Collections.emptyList();
    }//from   ww w  . j a  v  a  2s .co  m
    List<T> plugins = new ArrayList<T>(pluginSpecs.size());
    for (Object pluginSpec : pluginSpecs) {
        String pluginName;
        Object options;
        if (pluginSpec instanceof String) {
            pluginName = (String) pluginSpec;
            options = new HashMap<Object, Object>();
        } else { // has to be a Map
            Map<String, Object> pluginSpecMap = (Map<String, Object>) pluginSpec;
            pluginName = Iterables.getOnlyElement(pluginSpecMap.keySet());
            options = pluginSpecMap.get(pluginName);
        }
        plugins.add(create(pluginName, options, extensionClass));
    }
    return plugins;
}

From source file:org.sosy_lab.cpachecker.core.algorithm.invariants.ReachedSetBasedExpressionTreeSupplier.java

@Override
public ExpressionTree<Object> getInvariantFor(CFANode pLocation) {
    ExpressionTree<Object> locationInvariant = ExpressionTrees.getFalse();

    Set<InvariantsState> invStates = Sets.newHashSet();
    boolean otherReportingStates = false;
    Iterable<AbstractState> locationStates = lazyLocationMapping.get(pLocation, Optional.empty());
    if (Iterables.isEmpty(locationStates)) {
        // Location is not necessarily unreachable, but might have been skipped,
        // e.g. by the multi-edge/basic-block optimization of the CompositeCPA.
        // In this case, we err on the side of caution.
        return ExpressionTrees.getTrue();
    }/*from  ww w.ja  v  a 2 s.  c om*/

    for (AbstractState locState : locationStates) {
        ExpressionTree<Object> stateInvariant = ExpressionTrees.getTrue();

        for (ExpressionTreeReportingState expressionTreeReportingState : AbstractStates.asIterable(locState)
                .filter(ExpressionTreeReportingState.class)) {
            if (expressionTreeReportingState instanceof InvariantsState) {
                InvariantsState invState = (InvariantsState) expressionTreeReportingState;
                boolean skip = false;
                for (InvariantsState other : invStates) {
                    if (invState.isLessOrEqual(other)) {
                        skip = true;
                        break;
                    }
                }
                if (skip) {
                    stateInvariant = ExpressionTrees.getFalse();
                    continue;
                }
                invStates.add(invState);
            } else {
                otherReportingStates = true;
            }
            stateInvariant = And.of(stateInvariant, expressionTreeReportingState
                    .getFormulaApproximation(cfa.getFunctionHead(pLocation.getFunctionName()), pLocation));
        }

        locationInvariant = Or.of(locationInvariant, stateInvariant);
    }

    if (!otherReportingStates && invStates.size() > 1) {
        Set<InvariantsState> newInvStates = Sets.newHashSet();
        for (InvariantsState a : invStates) {
            boolean skip = false;
            for (InvariantsState b : invStates) {
                if (a != b && a.isLessOrEqual(b)) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                newInvStates.add(a);
            }
        }
        if (newInvStates.size() < invStates.size()) {
            locationInvariant = ExpressionTrees.getFalse();
            for (InvariantsState state : newInvStates) {
                locationInvariant = Or.of(locationInvariant, state
                        .getFormulaApproximation(cfa.getFunctionHead(pLocation.getFunctionName()), pLocation));
            }
        }
    }

    return locationInvariant;
}

From source file:eu.interedition.collatex.dekker.DekkerAlgorithm.java

@Override
public void collate(VariantGraph graph, Iterable<Token> tokens) {
    Preconditions.checkArgument(!Iterables.isEmpty(tokens), "Empty witness");
    final Witness witness = Iterables.getFirst(tokens, null).getWitness();

    if (LOG.isTraceEnabled()) {
        LOG.trace("{} + {}: {} vs. {}", new Object[] { graph, witness, graph.vertices(), tokens });
    }//from w w w .ja  va2 s  .c  om

    LOG.debug("{} + {}: Match and link tokens", graph, witness);
    tokenLinks = tokenLinker.link(graph, tokens, comparator);
    if (LOG.isTraceEnabled()) {
        for (Map.Entry<Token, VariantGraphVertex> tokenLink : tokenLinks.entrySet()) {
            LOG.trace("{} + {}: Token match: {} = {}",
                    new Object[] { graph, witness, tokenLink.getValue(), tokenLink.getKey() });
        }
    }

    LOG.debug("{} + {}: Detect phrase matches", graph, witness);
    phraseMatches = phraseMatchDetector.detect(tokenLinks, graph, tokens);
    if (LOG.isTraceEnabled()) {
        for (List<Match> phraseMatch : phraseMatches) {
            LOG.trace("{} + {}: Phrase match: {}",
                    new Object[] { graph, witness, Iterables.toString(phraseMatch) });
        }
    }

    LOG.debug("{} + {}: Detect transpositions", graph, witness);
    transpositions = transpositionDetector.detect(phraseMatches, graph);
    if (LOG.isTraceEnabled()) {
        for (List<Match> transposition : transpositions) {
            LOG.trace("{} + {}: Transposition: {}",
                    new Object[] { graph, witness, Iterables.toString(transposition) });
        }
    }

    LOG.debug("{} + {}: Determine aligned tokens by filtering transpositions", graph, witness);
    alignments = Maps.newHashMap(tokenLinks);

    for (List<Match> transposedPhrase : transpositions) {
        for (Match match : transposedPhrase) {
            alignments.remove(match.token);
        }
    }
    if (LOG.isTraceEnabled()) {
        for (Map.Entry<Token, VariantGraphVertex> alignment : alignments.entrySet()) {
            LOG.trace("{} + {}: Alignment: {} = {}",
                    new Object[] { graph, witness, alignment.getValue(), alignment.getKey() });
        }
    }

    merge(graph, tokens, alignments);
    mergeTranspositions(graph, transpositions);

    if (LOG.isTraceEnabled()) {
        LOG.trace("!{}: {}", graph, Iterables.toString(graph.vertices()));
    }
}