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:net.sf.ehcache.util.PropertyUtil.java

/**
 * @return null if their is no property for the key, or their are no properties
 *///w  w w. j  a va 2 s  . c om
public static String extractAndLogProperty(String name, Map properties) {
    if (properties == null || properties.size() == 0) {
        return null;
    }
    String foundValue = (String) properties.get(name);
    if (foundValue != null) {
        foundValue = foundValue.trim();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(new StringBuffer().append("Value found for ").append(name).append(": ").append(foundValue)
                .toString());
    }
    return foundValue;
}

From source file:com.googlecode.dex2jar.v3.Main.java

public static void doData(byte[] data, File destJar, boolean handleException) throws IOException {

    DexFileReader reader = new DexFileReader(data);
    DexExceptionHandlerImpl handler = handleException ? new DexExceptionHandlerImpl() : null;

    Dex2jar.from(reader).withExceptionHandler(handler).to(destJar);

    if (handleException) {
        Map<Method, Exception> exceptions = handler.getExceptions();
        if (exceptions != null && exceptions.size() > 0) {
            File errorFile = new File(destJar.getParentFile(),
                    FilenameUtils.getBaseName(destJar.getName()) + ".error.zip");
            handler.dumpException(reader, errorFile);
            System.err.println("Detail Error Information in File " + errorFile);
            System.err.println(//from  w  w w.j  av a 2  s  .com
                    "Please report this file to http://code.google.com/p/dex2jar/issues/entry if possible.");
        }
    }
}

From source file:Main.java

/**
 * Format a string with size information about a map whose values are lists of elements.
 * @param <T> the type of the keys in the map.
 * @param <U> the type of the values in the map.
 * @param name an arbitrary name given to the map.
 * @param map the map from which to get size information.
 * @return a string containing information about the number of elements in the map. 
 *//*from  w  w w  .  ja  v a 2s. com*/
public static <T, U> String formatSizeMapInfo(String name, Map<T, List<U>> map) {
    StringBuilder sb = new StringBuilder();
    sb.append(name).append("[shallow size=").append(map.size());
    sb.append(", total elements=").append(sizeOfListMap(map)).append("]");
    return sb.toString();
}

From source file:monasca.api.app.validation.ValueMetaValidation.java

/**
 * Validates that the given {@code valueMetas} are valid.
 *
 * @throws WebApplicationException if validation fails
 */// ww  w .ja  va 2s .com
public static void validate(Map<String, String> valueMetas) {
    if (valueMetas.size() > VALUE_META_MAX_NUMBER) {
        throw Exceptions.unprocessableEntity("Maximum number of valueMeta key/value pairs is %d",
                VALUE_META_MAX_NUMBER);
    }

    // Validate valueMeta names and values
    for (Map.Entry<String, String> valueMeta : valueMetas.entrySet()) {
        // Have to check for null first because later check is for trimmed name
        if (valueMeta.getKey() == null) {
            throw Exceptions.unprocessableEntity("valueMeta name cannot be empty");
        }
        final String name = CharMatcher.WHITESPACE.trimFrom(valueMeta.getKey());
        String value = valueMeta.getValue();
        if (value == null) {
            // Store nulls as empty strings
            value = "";
        }

        // General validations
        if (Strings.isNullOrEmpty(name)) {
            throw Exceptions.unprocessableEntity("valueMeta name cannot be empty");
        }
        if (name.length() > VALUE_META_NAME_MAX_LENGTH) {
            throw Exceptions.unprocessableEntity("valueMeta name %s must be %d characters or less", name,
                    VALUE_META_NAME_MAX_LENGTH);
        }
    }
    verifyValueMetaStringLength(valueMetas);
}

From source file:Maps.java

public static <K, V> Map<K, V> putAll(Map<K, V> map, Map<K, V> toAdd) {
    switch (toAdd.size()) {
    case 0:// w  w w .  ja va2s  .c om
        // No-op.
        return map;
    case 1: {
        // Add one element.
        K key = toAdd.keySet().iterator().next();
        return put(map, key, toAdd.get(key));
    }
    default:
        // True list merge, result >= 2.
        switch (map.size()) {
        case 0:
            return new HashMap<K, V>(toAdd);
        case 1: {
            HashMap<K, V> result = new HashMap<K, V>();
            K key = map.keySet().iterator().next();
            result.put(key, map.get(key));
            result.putAll(toAdd);
            return normalize(result);
        }
        default:
            map.putAll(toAdd);
            return map;
        }
    }
}

From source file:Maps.java

public static <K, V> Map<K, V> remove(Map<K, V> map, K key) {
    switch (map.size()) {
    case 0:/*from w w w.  ja v  a2 s  .  c om*/
        // Empty
        return map;
    case 1:
        // Singleton -> Empty
        if (map.containsKey(key)) {
            return create();
        }
        return map;
    case 2:
        // HashMap -> Singleton
        if (map.containsKey(key)) {
            map.remove(key);
            key = map.keySet().iterator().next();
            return create(key, map.get(key));
        }
        return map;
    default:
        // IdentityHashMap
        map.remove(key);
        return map;
    }
}

From source file:Main.java

public static <T> List<Map<String, T>> permutations(Map<String, List<T>> parameterValues) {
    List<Map<String, T>> list = new ArrayList<Map<String, T>>();
    if (parameterValues == null || parameterValues.size() == 0) {
        return list;
    }//from   www  .  j  a va  2s .c o  m

    permute(new HashMap<String, T>(), new ArrayList<String>(parameterValues.keySet()), parameterValues, list);

    return list;

}

From source file:Main.java

public static List join(Map map, String separator) {
    if (map == null)
        return null;
    List list = new ArrayList();
    if (map == null || map.size() == 0)
        return list;
    for (Iterator i$ = map.entrySet().iterator(); i$.hasNext();) {
        java.util.Map.Entry entry = (java.util.Map.Entry) i$.next();
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (value == null || value.length() == 0)
            list.add(key);//from  ww  w .jav  a  2s  . c om
        else
            list.add((new StringBuilder()).append(key).append(separator).append(value).toString());
    }

    return list;
}

From source file:Maps.java

public static <K, V> Map<K, V> put(Map<K, V> map, K key, V value) {
    switch (map.size()) {
    case 0://from   www  .j  a  va  2s  .  com
        // Empty -> Singleton
        return Collections.singletonMap(key, value);
    case 1: {
        if (map.containsKey(key)) {
            return create(key, value);
        }
        // Singleton -> HashMap
        Map<K, V> result = new HashMap<K, V>();
        result.put(map.keySet().iterator().next(), map.values().iterator().next());
        result.put(key, value);
        return result;
    }
    default:
        // HashMap
        map.put(key, value);
        return map;
    }
}

From source file:Main.java

private static List<String> filterParamNames(Map<String, Object> paramValueMap,
        List<String> ignoreParamNameList) {
    List<String> filteredParamNames = new ArrayList<>(paramValueMap.size());
    filteredParamNames.addAll(paramValueMap.keySet());
    if (ignoreParamNameList != null && ignoreParamNameList.size() > 0) {
        for (String ignoreParamName : ignoreParamNameList) {
            filteredParamNames.remove(ignoreParamName);
        }/* www .  j a  v a2  s  . c  o m*/
    }
    return filteredParamNames;
}