Example usage for java.util Map size

List of usage examples for java.util Map size

Introduction

In this page you can find the example usage for java.util Map size.

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:com.wiiyaya.framework.provider.utils.PageableHelper.java

public static Pageable mappingAttr(Map<String, String> replaceAttr, Pageable pageRequest) {
    if (pageRequest.getSort() == null || replaceAttr == null || replaceAttr.size() == 0) {
        return pageRequest;
    }/*from   w  w w.j av a  2 s  .  c o m*/
    List<Order> orders = new ArrayList<Order>();

    for (Map.Entry<String, String> entry : replaceAttr.entrySet()) {
        Order ctOrd = pageRequest.getSort().getOrderFor(entry.getKey());
        if (ctOrd != null) {
            ctOrd = new Order(ctOrd.getDirection(), entry.getValue());
            orders.add(ctOrd);
        }
    }
    return new PageRequest(pageRequest.getPageNumber(), pageRequest.getPageSize(), new Sort(orders));
}

From source file:com.ieasy.basic.util.CookieSupport.java

/**
 * cookies/*from w  w  w  .  j  a va2  s.com*/
 * 
 * @param response
 * @param cookieParams
 * @param maxAge
 */
public static final void writeCookies(HttpServletResponse response, Map<String, String> cookieParams,
        int maxAge) {
    if (cookieParams == null || cookieParams.size() == 0)
        return;
    Set<String> keySet = cookieParams.keySet();
    for (String key : keySet) {
        Cookie cookie = new Cookie(key, cookieParams.get(key));
        cookie.setMaxAge(maxAge);
        response.addCookie(cookie);
    }
}

From source file:Main.java

public static <V> Map<String, V> cleanupMap(Map<String, V> map) {
    if (map == null || map.isEmpty()) {
        return null;
    }//from w ww. java  2s.c om

    Map<String, V> result = new HashMap<String, V>(map.size());
    Set<Entry<String, V>> entries = map.entrySet();

    for (Entry<String, V> entry : entries) {
        if (entry.getValue() != null) {
            result.put(entry.getKey(), entry.getValue());
        }
    }

    return result;
}

From source file:Main.java

public static boolean isEmpty(Map map) {
    if (map == null || map.size() == 0) {
        return true;
    }/*  www . ja v a 2  s  . c o  m*/
    return false;
}

From source file:net.sephy.postman.util.PostmanUtils.java

/**
 * ?/*w  w w.  j  av  a2s  .c  o m*/
 * @param builder
 * @param params
 */
public static void setParameter(RequestBuilder builder, Map<String, Object> params) {
    if (params != null && params.size() > 0) {
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            builder.addParameter(entryToNameAndValuePair(entry));
        }
    }
}

From source file:net.sephy.postman.util.PostmanUtils.java

/**
 * ?// w  w w  .j a  v  a2s .  co  m
 * @param builder
 * @param header
 */
public static void setHeader(RequestBuilder builder, Map<String, Object> header) {
    if (header != null && header.size() > 0) {
        for (Map.Entry<String, Object> entry : header.entrySet()) {
            builder.addHeader(entryToHeader(entry));
        }
    }
}

From source file:io.amira.zen.http.ZenHTTP.java

private static Header[] _parseHeaders(Map<String, String> headers) {
    Header[] rv = new Header[headers.size()];
    Iterator iter = headers.entrySet().iterator();
    int i = 0;//from w  ww.  j  a  v a2 s .c  o  m
    while (iter.hasNext()) {
        Map.Entry pairs = (Map.Entry) iter.next();
        rv[i] = new BasicHeader(pairs.getKey().toString(), pairs.getValue().toString());
        i++;
    }
    return rv;
}

From source file:Main.java

/**
 * Returns <tt>true</tt> iff the given {@link Collection}s contain exactly
 * the same elements with exactly the same cardinality.
 * <p>//  w  ww. j a  v a 2s .co  m
 * That is, iff the cardinality of <i>e</i> in <i>a</i> is equal to the
 * cardinality of <i>e</i> in <i>b</i>, for each element <i>e</i> in
 * <i>a</i> or <i>b</i>.
 */
public static boolean isEqualCollection(final Collection a, final Collection b) {
    if (a.size() != b.size()) {
        return false;
    } else {
        Map mapa = getCardinalityMap(a);
        Map mapb = getCardinalityMap(b);
        if (mapa.size() != mapb.size()) {
            return false;
        } else {
            Iterator it = mapa.keySet().iterator();
            while (it.hasNext()) {
                Object obj = it.next();
                if (getFreq(obj, mapa) != getFreq(obj, mapb)) {
                    return false;
                }
            }
            return true;
        }
    }
}

From source file:Main.java

/**
 * Copies the given {@link Map} into a new {@link Map}.<br>
 * //from  ww w .j a va2  s .  c  o m
 * @param <A>
 *            the type of the keys of the map
 * @param <B>
 *            the type of the values of the map
 * @param data
 *            the given map
 * @return If the given map was empty, a {@link Collections#emptyMap()} is
 *         returned<br>
 *         If the given map contained only one entry, a
 *         {@link Collections#singletonMap(Object, Object)}, containing
 *         said entry, is returned <br>
 *         If the given map contained more than one element, a
 *         {@link Collections#unmodifiableMap(Map)}, containing the entries
 *         of the given map, is returned.
 */
public static <A, B> Map<A, B> copy(Map<A, B> data) {
    final int size = data.size();

    switch (size) {
    case 0:
        return Collections.emptyMap();
    case 1:
        final A key = data.keySet().iterator().next();
        return Collections.singletonMap(key, data.get(key));
    default:
        return Collections.unmodifiableMap(new HashMap<A, B>(data));
    }
}

From source file:com.blackey.quickvolley.Request.JsonNetworkRequest.java

private static String paramstoString(Map<String, String> params) {
    if (params != null && params.size() > 0) {
        String paramsEncoding = "UTF-8";
        StringBuilder encodedParams = new StringBuilder();
        try {/*ww w  . ja  va 2 s  .com*/
            for (Map.Entry<String, String> entry : params.entrySet()) {
                encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
                encodedParams.append('=');
                encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
                encodedParams.append('&');

            }
            return encodedParams.toString();
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
        }
    }
    return null;
}