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.wealdtech.utils.GuavaUtils.java

public static <T, U> Multimap<T, U> emptyToNull(final Multimap<T, U> input) {
    if (input == null || input.isEmpty()) {
        return null;
    }//from w  w  w .j ava 2 s .  c  o m
    return input;
}

From source file:org.jclouds.http.utils.Queries.java

public static String buildQueryLine(Multimap<String, ?> queryParams) {
    if (queryParams.isEmpty())
        return null;
    return buildQueryLine(queryParams, new AppendParam());
}

From source file:org.jclouds.http.utils.Queries.java

/**
 * percent encodes the query parameters, excep {@code /} and {@code ,} characters.
 * // w  w w.  j av  a2s .c o  m
 * @param queryParams
 * @return percent encoded line or null if no queryParams present
 */
public static String encodeQueryLine(Multimap<String, ?> queryParams) {
    if (queryParams.isEmpty())
        return null;
    return buildQueryLine(queryParams, new EncodeAndAppendParam());
}

From source file:com.isotrol.impe3.core.impl.RequestParamsFactory.java

/**
 * Returns the collection of request parameters from a multimap object.
 * @param map Multimap./*  w w  w.  j  a v  a2 s .c o  m*/
 * @return The request query parameters.
 */
public static RequestParams of(Multimap<String, String> map) {
    if (map == null || map.isEmpty()) {
        return EMPTY;
    }
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    for (String key : map.keySet()) {
        final CaseIgnoringString cis = CaseIgnoringString.valueOf(key);
        builder.putAll(cis, map.get(key));
    }
    return new Immutable(builder.build());
}

From source file:org.jclouds.http.utils.Queries.java

/**
 * percent encodes the query parameters according except characters specified in the {@code skips} argument.
 * // w  w  w . j  a v a 2s . com
 * @param queryParams
 * @return percent encoded line or null if no queryParams present
 */
public static String encodeQueryLine(Multimap<String, ?> queryParams, Iterable<Character> skips) {
    if (queryParams.isEmpty())
        return null;
    return buildQueryLine(queryParams, new EncodeAndAppendParam(skips));
}

From source file:com.google.errorprone.bugpatterns.ReplacementVariableFinder.java

private static ImmutableList<Fix> buildValidReplacements(
        Multimap<Integer, JCVariableDecl> potentialReplacements,
        Function<JCVariableDecl, Fix> replacementFunction) {
    if (potentialReplacements.isEmpty()) {
        return ImmutableList.of();
    }//from w  w  w .  j a va  2 s. co  m

    // Take all of the potential edit-distance replacements with the same minimum distance,
    // then suggest them as individual fixes.
    return potentialReplacements.get(Collections.min(potentialReplacements.keySet())).stream()
            .map(replacementFunction).collect(toImmutableList());
}

From source file:org.hudsonci.plugins.vault.util.MultimapUtil.java

public static void save(final Multimap<String, String> map, final Writer target, final String sep)
        throws IOException {
    assert map != null;
    assert target != null;

    if (map.isEmpty()) {
        return;/*from  w  ww.j a  v  a 2s. c o m*/
    }

    PrintWriter writer = new PrintWriter(new BufferedWriter(target));

    for (String key : map.keySet()) {
        for (String value : map.get(key)) {
            writer.append(key).append('=').append(value).append(sep);
        }
    }

    writer.flush();
}

From source file:co.cask.common.http.HttpRequests.java

/**
 * Executes an HTTP request to the url provided.
 *
 * @param request HTTP request to execute
 * @param requestConfig configuration for the HTTP request to execute
 * @return HTTP response//from w  w  w .  j  a  v  a 2s  .c o m
 */
public static HttpResponse execute(HttpRequest request, HttpRequestConfig requestConfig) throws IOException {
    String requestMethod = request.getMethod().name();
    URL url = request.getURL();

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod(requestMethod);
    conn.setReadTimeout(requestConfig.getReadTimeout());
    conn.setConnectTimeout(requestConfig.getConnectTimeout());

    Multimap<String, String> headers = request.getHeaders();
    if (headers != null && !headers.isEmpty()) {
        for (Map.Entry<String, String> header : headers.entries()) {
            conn.setRequestProperty(header.getKey(), header.getValue());
        }
    }

    InputSupplier<? extends InputStream> bodySrc = request.getBody();
    if (bodySrc != null) {
        conn.setDoOutput(true);
        Long bodyLength = request.getBodyLength();
        if (bodyLength != null) {
            // use intValue to support 1.6
            if (bodyLength > requestConfig.getFixedLengthStreamingThreshold()) {
                conn.setFixedLengthStreamingMode(bodyLength.intValue());
            }
        } else {
            conn.setChunkedStreamingMode(0);
        }
    }

    if (conn instanceof HttpsURLConnection && !requestConfig.isVerifySSLCert()) {
        // Certificate checks are disabled for HTTPS connection.
        LOG.debug("Disabling SSL certificate check for {}", request.getURL());
        try {
            disableCertCheck((HttpsURLConnection) conn);
        } catch (Exception e) {
            LOG.error("Got exception while disabling SSL certificate check for {}", request.getURL());
        }
    }

    conn.connect();

    try {
        if (bodySrc != null) {
            OutputStream os = conn.getOutputStream();
            try {
                ByteStreams.copy(bodySrc, os);
            } finally {
                os.close();
            }
        }

        try {
            if (isSuccessful(conn.getResponseCode())) {
                return new HttpResponse(conn.getResponseCode(), conn.getResponseMessage(),
                        ByteStreams.toByteArray(conn.getInputStream()), conn.getHeaderFields());
            }
        } catch (FileNotFoundException e) {
            // Server returns 404. Hence handle as error flow below. Intentional having empty catch block.
        }

        // Non 2xx response
        InputStream es = conn.getErrorStream();
        byte[] content = (es == null) ? new byte[0] : ByteStreams.toByteArray(es);
        return new HttpResponse(conn.getResponseCode(), conn.getResponseMessage(), content,
                conn.getHeaderFields());
    } finally {
        conn.disconnect();
    }
}

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

public static int execute(Configuration configuration, CollectionSchema colSchema,
        Multimap<DocStructure, Integer> didsByStructure, boolean justOne) {
    Multimap<DocStructure, Integer> didsByStructureToDelete;
    if (didsByStructure.isEmpty()) {
        return 0;
    }/*from  w ww .ja  va 2  s.c o m*/

    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);
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:grakn.core.graql.gremlin.RelationTypeInference.java

public static Set<Fragment> inferRelationTypes(TransactionOLTP tx, Set<Fragment> allFragments) {

    Set<Fragment> inferredFragments = new HashSet<>();

    Map<Variable, Type> labelVarTypeMap = getLabelVarTypeMap(tx, allFragments);
    if (labelVarTypeMap.isEmpty())
        return inferredFragments;

    Multimap<Variable, Type> instanceVarTypeMap = getInstanceVarTypeMap(allFragments, labelVarTypeMap);

    Multimap<Variable, Variable> relationRolePlayerMap = getRelationRolePlayerMap(allFragments,
            instanceVarTypeMap);/*from w ww  .  j  a v a  2  s .c om*/
    if (relationRolePlayerMap.isEmpty())
        return inferredFragments;

    // for each type, get all possible relation type it could be in
    Multimap<Type, RelationType> relationMap = HashMultimap.create();
    labelVarTypeMap.values().stream().distinct().forEach(type -> addAllPossibleRelations(relationMap, type));

    // inferred labels should be kept separately, even if they are already in allFragments set
    Map<Label, Statement> inferredLabels = new HashMap<>();
    relationRolePlayerMap.asMap().forEach((relationVar, rolePlayerVars) -> {

        Set<Type> possibleRelationTypes = rolePlayerVars.stream().filter(instanceVarTypeMap::containsKey)
                .map(rolePlayer -> getAllPossibleRelationTypes(instanceVarTypeMap.get(rolePlayer), relationMap))
                .reduce(Sets::intersection).orElse(Collections.emptySet());

        //TODO: if possibleRelationTypes here is empty, the query will not match any data
        if (possibleRelationTypes.size() == 1) {

            Type relationType = possibleRelationTypes.iterator().next();
            Label label = relationType.label();

            // add label fragment if this label has not been inferred
            if (!inferredLabels.containsKey(label)) {
                Statement labelVar = var();
                inferredLabels.put(label, labelVar);
                Fragment labelFragment = Fragments.label(new TypeProperty(label.getValue()), labelVar.var(),
                        ImmutableSet.of(label));
                inferredFragments.add(labelFragment);
            }

            // finally, add inferred isa fragments
            Statement labelVar = inferredLabels.get(label);
            IsaProperty isaProperty = new IsaProperty(labelVar);
            EquivalentFragmentSet isaEquivalentFragmentSet = EquivalentFragmentSets.isa(isaProperty,
                    relationVar, labelVar.var(), relationType.isImplicit());
            inferredFragments.addAll(isaEquivalentFragmentSet.fragments());
        }
    });

    return inferredFragments;
}