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:cn.teamlab.wg.framework.struts2.breadcrumb.Utils.java

@SuppressWarnings("rawtypes")
public static boolean compareParametersMap(Map m1, Map m2) {
    if (m1.size() != m2.size())
        return false;

    for (Object key : m1.keySet()) {
        String[] v1 = (String[]) m1.get(key);
        String[] v2 = (String[]) m2.get(key);

        if (v1.length != v2.length)
            return false;
        // XXX should values be sorted first ?
        // FIXME take care of null values ?
        for (int i = 0; i < v2.length; i++) {
            if (!v1[i].equals(v2[i]))
                return false;
        }/*from  w  ww  .  j  a v a2 s .c  om*/
    }
    return true;
}

From source file:Main.java

public static boolean isEmpty(Map<?, ?> map) {
    return (map == null) || (map.size() == 0);
}

From source file:Main.java

public static int getSize(final Map<?, ?> map) {
    if (map == null) {
        return 0;
    }//from  ww  w .  j  a va 2s.c  o  m
    return map.size();
}

From source file:org.opensprout.osaf.util.ApplicationContextUtils.java

public static <T> T getBeanByType(ApplicationContext applicationContext, Class<T> clazz) {
    Map beanMap = applicationContext.getBeansOfType(clazz);
    int size = beanMap.size();
    if (size == 0) {
        if (applicationContext.getParent() != null)
            return getBeanByType(applicationContext.getParent(), clazz);
        throw new NoSuchBeanDefinitionException(clazz.getSimpleName());
    }/*from   w  w  w.j  a  v a 2s  .c o m*/
    if (size > 1)
        throw new NoSuchBeanDefinitionException(
                "No unique bean definition type [" + clazz.getSimpleName() + "]");
    return (T) beanMap.values().iterator().next();
}

From source file:Main.java

public static boolean judgeNotNull(Map map) {
    return map != null && map.size() > 0 ? true : false;
}

From source file:Main.java

/**
 * Checks a map for either being empty or containing objects within it
 * @param myMap map to check/*w  w w.ja v  a 2 s.c om*/
 * @return Boolean, true if it is null or empty, false it if is not
 */
public static boolean isMapNullOrEmpty(Map<?, ?> myMap) {
    if (myMap == null) {
        return true;
    }
    if (myMap.size() <= 0) {
        return true;
    }
    return false;
}

From source file:Main.java

public static String mapToJson(Map<String, Object> maps) {
    StringBuffer sb = new StringBuffer();
    int size = maps.size();
    int i = 0;/*from w w w . j a  v  a2 s . c o m*/
    sb.append("{");
    for (String key : maps.keySet()) {
        i++;
        sb.append("\"" + key + "\"" + ":" + "\"" + maps.get(key) + "\"");
        if (i != size) {
            sb.append(",");
        }
    }
    sb.append("}");
    return sb + "";
}

From source file:Main.java

/**
 * Stick map into one sentence.//from  ww  w  . j  a  v  a  2 s .  co  m
 *
 * @param postfixMap
 * @return
 */
private static String stickFragments(Map<String, String> postfixMap) {
    for (int index = 1; index < postfixMap.size(); index++) {
        String value = postfixMap.get(TOKEN_PREFIX + index);
        if (value == null) {
            continue;
        }

        for (int innerIndex = index + 1; innerIndex < postfixMap.size(); innerIndex++) {
            String innerValue = postfixMap.get(TOKEN_PREFIX + innerIndex);
            if (innerValue != null) {
                innerValue = innerValue.replace(TOKEN_PREFIX + index, value);
                postfixMap.put(TOKEN_PREFIX + innerIndex, innerValue);
            }
        }

        String innerValue = postfixMap.get(TOKEN_MAIN);
        innerValue = innerValue.replace(TOKEN_PREFIX + index, value);
        postfixMap.put(TOKEN_MAIN, innerValue);
    }

    return postfixMap.get(TOKEN_MAIN);
}

From source file:Main.java

public static String mapToQueryString(Map<String, String> map) {
    StringBuilder string = new StringBuilder();

    if (map.size() > 0) {
        string.append("?");
    }/*from  w  w w .  j  a v  a 2s.c om*/

    for (Map.Entry<String, String> entry : map.entrySet()) {
        string.append(entry.getKey());
        string.append("=");
        string.append(entry.getValue());
        string.append("&");
    }

    return string.toString();
}

From source file:Main.java

/**
 * Returns the size of the collection if it can be determined to be a collection
 *
 * @param value the collection//www  . j  a  v  a2 s  .  c o  m
 * @return the size, or <tt>null</tt> if not a collection
 */
public static Integer size(Object value) {
    if (value != null) {
        if (value instanceof Collection) {
            Collection<?> collection = (Collection<?>) value;
            return collection.size();
        } else if (value instanceof Map) {
            Map<?, ?> map = (Map<?, ?>) value;
            return map.size();
        } else if (value instanceof Object[]) {
            Object[] array = (Object[]) value;
            return array.length;
        } else if (value.getClass().isArray()) {
            return Array.getLength(value);
        } else if (value instanceof NodeList) {
            NodeList nodeList = (NodeList) value;
            return nodeList.getLength();
        }
    }
    return null;
}