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:Main.java

public static void checkFutures(Map<? extends Object, Future<Void>> futures, int maxSize)
        throws InterruptedException, ExecutionException {
    while (futures.size() > maxSize) {
        for (Iterator<? extends Object> i = futures.keySet().iterator(); i.hasNext();) {
            Object key = i.next();
            futures.get(key).get();/*from   w  w  w. ja  va2  s  .  co  m*/
            i.remove();
        }
    }
}

From source file:ee.ria.xroad.common.message.SoapMessageEncoder.java

private static String[] convertHeaders(Map<String, String> headers) {
    String[] ret = new String[headers.size()];
    int idx = 0;/*from   w  w w. j ava  2s.  c o  m*/
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        ret[idx++] = entry.getKey() + ": " + entry.getValue();
    }

    return ret;
}

From source file:Main.java

public static void writeStringStringMap(Map<String, String> map, OutputStream os) throws IOException {
    if (map != null) {
        writeInt(os, map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            writeString(os, entry.getKey());
            writeString(os, entry.getValue());
        }/*from   ww w.  j  a  v a  2  s. c  o m*/
    } else {
        writeInt(os, 0);
    }
}

From source file:com.aliyun.openservices.odps.console.commands.logview.LogViewBaseAction.java

protected static String deduceTaskName(Instance inst) throws ODPSConsoleException, OdpsException {
    Map<String, TaskStatus> ss = inst.getTaskStatus();
    if (ss.size() == 1) {
        for (String key : ss.keySet()) {
            return key;
        }/*w w  w.j a v a2  s  . c o m*/
    } else {
        throw new ODPSConsoleException(
                "Please specify one of these tasks with option '-t': " + StringUtils.join(ss.keySet(), ','));
    }
    return null;
}

From source file:Main.java

private static List<String> filterParamNamesWithObjectValue(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);
        }//w  w w. j a v  a 2s .  c  om
    }
    return filteredParamNames;
}

From source file:Main.java

private static List<Activity> getAllActivitiesHack() throws ClassNotFoundException, NoSuchMethodException,
        NoSuchFieldException, IllegalAccessException, InvocationTargetException {
    Class activityThreadClass = Class.forName("android.app.ActivityThread");
    Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
    Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
    activitiesField.setAccessible(true);
    Map activities = (Map) activitiesField.get(activityThread);
    List<Activity> activitiesList = new ArrayList<Activity>(activities.size());

    for (Object activityRecord : activities.values()) {
        Class activityRecordClass = activityRecord.getClass();
        Field activityField = activityRecordClass.getDeclaredField("activity");
        activityField.setAccessible(true);
        Activity activity = (Activity) activityField.get(activityRecord);
        activitiesList.add(activity);/* w w w  .  java 2  s  .co m*/
    }

    return activitiesList;
}

From source file:Main.java

private final static String sortedParams(Map<String, String> params) throws UnsupportedEncodingException {
    String vals[] = new String[params.size()];
    int idx = 0;//from w  w  w .java 2  s .c o  m
    for (String key : params.keySet()) {
        vals[idx++] = key;
    }
    Arrays.sort(vals);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < vals.length; i++) {
        if (i > 0) {
            sb.append("&");
        }
        sb.append(vals[i]);
        sb.append("=");
        sb.append(encode(params.get(vals[i])));
    }
    return sb.toString();
}

From source file:Main.java

public static Map<String, String> paraFilter(Map<String, String> para) {

    Map<String, String> result = new HashMap<String, String>();

    if (para == null || para.size() <= 0) {
        return result;
    }/*from   w  w w  .j av a 2s. c om*/

    for (String key : para.keySet()) {
        String value = para.get(key);
        if (value == null || value.equals("") || key.equalsIgnoreCase(SIGNATURE)
                || key.equalsIgnoreCase(SIGN_METHOD)) {
            continue;
        }
        result.put(key, value);
    }

    return result;
}

From source file:Maps.java

public static <K, V> Map<K, V> normalize(Map<K, V> map) {
    switch (map.size()) {
    case 0:// w  w w  .j a  va 2 s.c  o m
        return create();
    case 1: {
        if (map.getClass() == SINGLETON_MAP_CLASS) {
            return map;
        }
        K key = map.keySet().iterator().next();
        return create(key, map.get(key));
    }
    default:
        if (map.getClass() == MULTI_MAP_CLASS) {
            return map;
        }
        return new HashMap<K, V>(map);
    }
}

From source file:me.st28.flexseries.flexcore.util.MapUtils.java

/**
 * Retrieves an entry from a map with a given index. Intended for maps that preserve ordering (ex. LinkedHashMap)
 *
 * @param map The map to retrieve the entry from.
 * @param index The index of the entry in the map.
 * @return The entry at the given index in the given map.
 */// w  w w .  j a  v a 2  s.  com
public static <K, V> Entry<K, V> getEntryByIndex(Map<K, V> map, int index) {
    Validate.notNull(map, "Map cannot be null.");
    int mapSize = map.size();

    int curIndex = 0;
    Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
    while (iterator.hasNext() && curIndex < mapSize) {
        if (curIndex++ == index) {
            return iterator.next();
        }
    }
    throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + mapSize);
}