Example usage for com.google.common.collect Multimap isEmpty

List of usage examples for com.google.common.collect Multimap isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect Multimap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this multimap contains no key-value pairs.

Usage

From source file:com.torodb.torod.db.backends.meta.routines.DeleteDocuments.java

public static int execute(Configuration configuration, CollectionSchema colSchema,
        Multimap<DocStructure, Integer> didsByStructure, boolean justOne,
        @Nonnull DatabaseInterface databaseInterface) throws RetryTransactionException {
    Multimap<DocStructure, Integer> didsByStructureToDelete;
    if (didsByStructure.isEmpty()) {
        return 0;
    }//from w  w  w .  ja v  a2s .c  om

    if (justOne) {
        didsByStructureToDelete = MultimapBuilder.hashKeys(1).arrayListValues(1).build();

        Map.Entry<DocStructure, Integer> aEntry = didsByStructure.entries().iterator().next();

        didsByStructureToDelete.put(aEntry.getKey(), aEntry.getValue());
    } else {
        didsByStructureToDelete = didsByStructure;
    }

    try {
        return execute(configuration, colSchema, didsByStructureToDelete, databaseInterface);
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.google.devtools.build.lib.collect.ImmutableSortedKeyListMultimap.java

@SuppressWarnings("unchecked")
public static <K extends Comparable<K>, V> ImmutableSortedKeyListMultimap<K, V> copyOf(Multimap<K, V> data) {
    if (data.isEmpty()) {
        return EMPTY_MULTIMAP;
    }//from   w  w w .  j  ava  2  s.  com
    if (data instanceof ImmutableSortedKeyListMultimap) {
        return (ImmutableSortedKeyListMultimap<K, V>) data;
    }
    Set<K> keySet = data.keySet();
    int size = keySet.size();
    K[] sortedKeys = (K[]) new Comparable<?>[size];
    int index = 0;
    for (K key : keySet) {
        sortedKeys[index++] = Preconditions.checkNotNull(key);
    }
    Arrays.sort(sortedKeys);
    List<V>[] values = (List<V>[]) new List<?>[size];
    for (int i = 0; i < size; i++) {
        values[i] = ImmutableList.copyOf(data.get(sortedKeys[i]));
    }
    return new ImmutableSortedKeyListMultimap<>(sortedKeys, values);
}

From source file:org.eclipse.elk.layered.intermediate.SplineSelfLoopPreProcessor.java

/**
 * Creates a set of all connected components. If there are ports with no edge, they will form a
 * component of size 1. If there are edges connecting ports not in the list of ports, this will
 * result in unpredictable behavior./*  ww w.j  a  va 2 s .c  om*/
 * 
 * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list 
 *            of ports!
 * @param node The node we are currently working on.         
 * @return A set of sets. Every single set represents a connected component.
 */
private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges,
        final LNode node) {

    final List<ConnectedSelfLoopComponent> components = Lists.newArrayList();
    final Multimap<LPort, LEdge> portToEdge = LinkedListMultimap.create();

    for (final LEdge edge : loopEdges) {
        portToEdge.put(edge.getSource(), edge);
        portToEdge.put(edge.getTarget(), edge);
    }

    while (!portToEdge.isEmpty()) {
        components.add(findAConnectedComponent(portToEdge, node,
                node.getProperty(LayoutOptions.PORT_CONSTRAINTS).isOrderFixed()));
    }
    return components;
}

From source file:org.eclipse.elk.alg.layered.intermediate.SplineSelfLoopPreProcessor.java

/**
 * Creates a set of all connected components. If there are ports with no edge, they will form a
 * component of size 1. If there are edges connecting ports not in the list of ports, this will
 * result in unpredictable behavior.//from  w ww. j a  v a2  s  .  co  m
 * 
 * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list 
 *            of ports!
 * @param node The node we are currently working on.         
 * @return A set of sets. Every single set represents a connected component.
 */
private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges,
        final LNode node) {

    final List<ConnectedSelfLoopComponent> components = Lists.newArrayList();
    final Multimap<LPort, LEdge> portToEdge = LinkedListMultimap.create();

    for (final LEdge edge : loopEdges) {
        portToEdge.put(edge.getSource(), edge);
        portToEdge.put(edge.getTarget(), edge);
    }

    while (!portToEdge.isEmpty()) {
        components.add(findAConnectedComponent(portToEdge, node,
                node.getProperty(LayeredOptions.PORT_CONSTRAINTS).isOrderFixed()));
    }
    return components;
}

From source file:de.cau.cs.kieler.klay.layered.intermediate.SplineSelfLoopPreProcessor.java

/**
 * Creates a set of all connected components. If there are ports with no edge, they will form a
 * component of size 1. If there are edges connecting ports not in the list of ports, this will
 * result in unpredictable behavior./*from w w  w .j av a2  s. c  o  m*/
 * 
 * @param loopEdges The edges connecting the ports. They may not connect any ports not in the list 
 *            of ports!
 * @param node The node we are currently working on.         
 * @return A set of sets. Every single set represents a connected component.
 */
private static List<ConnectedSelfLoopComponent> findAllConnectedComponents(final Set<LEdge> loopEdges,
        final LNode node) {

    final List<ConnectedSelfLoopComponent> components = Lists.newArrayList();
    final Multimap<LPort, LEdge> portToEdge = ArrayListMultimap.create();

    for (final LEdge edge : loopEdges) {
        portToEdge.put(edge.getSource(), edge);
        portToEdge.put(edge.getTarget(), edge);
    }

    while (!portToEdge.isEmpty()) {
        components.add(findAConnectedComponent(portToEdge, node,
                node.getProperty(LayoutOptions.PORT_CONSTRAINTS).isOrderFixed()));
    }
    return components;
}

From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java

public static List<ProcessedQueryCriteria> process(InQueryCriteria criteria,
        QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor) {

    if (!Utils.isTypeKnownInStructure(criteria.getAttributeReference())) {
        return Collections.singletonList(new ProcessedQueryCriteria(null, criteria));
    } else {/*from   www  .  j a  v  a2s. co m*/

        Multimap<BasicType, Value<?>> byTypeValues = MultimapBuilder.enumKeys(BasicType.class).hashSetValues()
                .build();

        for (Value<?> value : criteria.getValue()) {
            byTypeValues.put(value.getType(), value);
        }

        List<ProcessedQueryCriteria> result;

        if (byTypeValues.isEmpty()) {
            result = Collections.emptyList();
        } else {
            result = Lists.newArrayList();

            ProcessedQueryCriteria typeQuery;

            typeQuery = getNumericQuery(criteria, byTypeValues);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.STRING);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.ARRAY);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.BOOLEAN);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.NULL);
            if (typeQuery != null) {
                result.add(typeQuery);
            }
        }

        return result;
    }
}

From source file:org.ambraproject.wombat.config.site.url.Link.java

private static String appendQueryParameters(Multimap<String, ?> queryParameters, String path) {
    if (!queryParameters.isEmpty()) {
        UrlParamBuilder paramBuilder = UrlParamBuilder.params();
        for (Map.Entry<String, ?> paramEntry : queryParameters.entries()) {
            paramBuilder.add(paramEntry.getKey(), paramEntry.getValue().toString());
        }//www  .j av a  2  s.com
        path = path + "?" + paramBuilder.format();
    }
    return path;
}

From source file:org.eclipse.xtext.scoping.impl.MultimapBasedScope.java

public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions,
        boolean ignoreCase) {
    Multimap<QualifiedName, IEObjectDescription> map = null;
    for (IEObjectDescription description : descriptions) {
        if (map == null)
            map = LinkedHashMultimap.create(5, 2);
        if (ignoreCase)
            map.put(description.getName().toLowerCase(), description);
        else/*from w w  w . j  a  v  a 2  s .  c  o m*/
            map.put(description.getName(), description);
    }
    if (map == null || map.isEmpty()) {
        return parent;
    }
    return new MultimapBasedScope(parent, map, ignoreCase);
}

From source file:com.torodb.torod.db.backends.query.processors.InProcessor.java

public static List<ProcessedQueryCriteria> process(InQueryCriteria criteria,
        QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor) {

    if (!Utils.isTypeKnownInStructure(criteria.getAttributeReference())) {
        return Collections.singletonList(new ProcessedQueryCriteria(null, criteria));
    } else {// w ww .j  a  va  2  s  .c o m

        Multimap<ScalarType, ScalarValue<?>> byTypeValues = MultimapBuilder.enumKeys(ScalarType.class)
                .hashSetValues().build();

        for (ScalarValue<?> value : criteria.getValue()) {
            byTypeValues.put(value.getType(), value);
        }

        List<ProcessedQueryCriteria> result;

        if (byTypeValues.isEmpty()) {
            result = Collections.emptyList();
        } else {
            result = Lists.newArrayList();

            ProcessedQueryCriteria typeQuery;

            typeQuery = getNumericQuery(criteria, byTypeValues);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.STRING);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.ARRAY);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.BOOLEAN);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.NULL);
            if (typeQuery != null) {
                result.add(typeQuery);
            }
        }

        return result;
    }
}

From source file:org.dslforge.xtext.common.scoping.BasicTextMultimapBasedScope.java

public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase,
        List<URI> uris) {
    availableResourceURs = uris;/*from  w  w  w  .  ja  v  a2 s  .  c  o  m*/
    Multimap<QualifiedName, IEObjectDescription> map = null;
    for (IEObjectDescription description : descriptions) {
        if (map == null)
            map = LinkedHashMultimap.create(5, 2);
        if (ignoreCase)
            map.put(description.getName().toLowerCase(), description);
        else
            map.put(description.getName(), description);
    }
    if (map == null || map.isEmpty()) {
        return parent;
    }
    return new BasicTextMultimapBasedScope(parent, map, ignoreCase);
}