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:fuliao.fuliaozhijia.data.UserData.java

private static void cml() {
    String event = "<xml><ToUserName><![CDATA[gh_da521251eefb]]></ToUserName>"
            + "<FromUserName><![CDATA[o1c8wt40T2yDoCqxCkBJqg8G0yW4]]></FromUserName>"
            + "<CreateTime>1428133191</CreateTime><MsgType><![CDATA[event]]></MsgType>"
            + "<Event><![CDATA[subscribe]]></Event><EventKey><![CDATA[]]></EventKey>"
            + "<Encrypt><![CDATA[ALn/Li4lfALrfc5Z+6K1mNpAXfi1d3VRbzxiVF/jg2wPZgxofc5Kdtu/91XLkBJIQbNFmN+"
            + "GMDC6Z0PlmLmrWHckc9KILUtp3zSFbfCNV6l5gNh3SiCeMQZPmAzmT1DXd3sxxIxlirSAT6Zb3us9zfWRTWfpxzZGT"
            + "NAbw2/ZvdfvrTgFvbwmQPouTkUFtphy8NwEvCDdfkm+irADQhicsqKyFgPcfGuuVZf5QX/nPuOaIml5En6LLj/akF9"
            + "o7H3XpxyTLBv+WVetk0Zd7YJgbRCfnbnTKdTwH7rHu/O7X5OMqCdGLzX2UX7UazKgoZ0zvw50bim4PTPtJt04WkfrrT"
            + "uBWElkapAMN2yM3S5+cZETZzfAL6tTdYdLrM1W+zdwT+UjjyFJD9dkf6SBQg9Vmej5xuDOn7WmSIPedHhRtxI=]]></Encrypt></xml>";
    Map map;
    try {/*from  w ww  .j av  a 2s  . c om*/
        map = deailXml(event);
        System.out.println(map.size());
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:gr.abiss.calipso.dto.KeyValuePair.java

public static List<KeyValuePair> fromMap(Map map) {
    ArrayList<KeyValuePair> list = null;
    if (map != null) {
        list = new ArrayList<KeyValuePair>(map.size());
        if (map != null) {
            for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
                Entry entry = (Entry) iter.next();
                list.add(new KeyValuePair((Serializable) entry.getKey(), (Serializable) entry.getValue()));
            }// www .ja  v  a 2s  .  c  o m
        }
    }
    return list;
}

From source file:com.espertech.esper.epl.join.assemble.AssemblyStrategyTreeBuilder.java

private static void recursiveBuild(int parentStreamNum, BaseAssemblyNode parentNode,
        Map<Integer, int[]> streamsJoinedPerStream, boolean isRequiredPerStream[]) {
    int numStreams = streamsJoinedPerStream.size();

    for (int i = 0; i < streamsJoinedPerStream.get(parentStreamNum).length; i++) {
        int streamJoined = streamsJoinedPerStream.get(parentStreamNum)[i];
        BaseAssemblyNode childNode = createNode(false, streamJoined, numStreams,
                streamsJoinedPerStream.get(streamJoined), isRequiredPerStream);
        parentNode.addChild(childNode);/*from   www.  j  a  va 2  s . co m*/

        if (streamsJoinedPerStream.get(streamJoined).length > 0) {
            recursiveBuild(streamJoined, childNode, streamsJoinedPerStream, isRequiredPerStream);
        }
    }
}

From source file:com.ocrix.ppc.commons.Validator.java

/**
 * Validates a {@link Map}//from  www .  j ava2  s.  c  o  m
 * 
 * @param groups
 *            - Map<String, PeerGroupAdvertisement>
 */
public static void validateGroupMap(Map<String, PeerGroupAdvertisement> groups) {
    if (groups == null || groups.size() == 0)
        throw new IllegalArgumentException("No group found");
}

From source file:Main.java

/** */
public static Map<QName, String> toQName(Map<String, String> setProps) {
    if (setProps == null) {
        return Collections.emptyMap();
    }/*from  w  ww .  ja  v  a2  s  .com*/
    Map<QName, String> result = new HashMap<QName, String>(setProps.size());
    for (Map.Entry<String, String> entry : setProps.entrySet()) {
        result.put(createQNameWithCustomNamespace(entry.getKey()), entry.getValue());
    }
    return result;
}

From source file:Utils.java

/**
 * Create a typesafe copy of a raw map.//from   w  ww. j av  a2  s.c o m
 * @param rawMap an unchecked map
 * @param keyType the desired supertype of the keys
 * @param valueType the desired supertype of the values
 * @param strict true to throw a <code>ClassCastException</code> if the raw map has an invalid key or value,
 *               false to skip over such map entries (warnings may be logged)
 * @return a typed map guaranteed to contain only keys and values assignable
 *         to the named types (or they may be null)
 * @throws ClassCastException if some key or value in the raw map was not well-typed, and only if <code>strict</code> was true
 */
public static <K, V> Map<K, V> checkedMapByCopy(Map rawMap, Class<K> keyType, Class<V> valueType,
        boolean strict) throws ClassCastException {
    Map<K, V> m2 = new HashMap<K, V>(rawMap.size() * 4 / 3 + 1);
    Iterator it = rawMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        try {
            m2.put(keyType.cast(e.getKey()), valueType.cast(e.getValue()));
        } catch (ClassCastException x) {
            if (strict) {
                throw x;
            } else {
                System.out.println("not assignable");
            }
        }
    }
    return m2;
}

From source file:Main.java

public static <T> T mostCommon(List<T> list, double percent) {
    if (list.isEmpty())
        return null;

    Map<T, Integer> map = new HashMap<>();

    for (T t : list) {
        Integer count = map.get(t);
        map.put(t, count == null ? 1 : count + 1);
    }/*from w  ww  .  j a  v a  2 s .  c  o  m*/

    double freq = map.size() / (double) list.size();
    if (1.0 == freq || (1.0 - freq) < percent)
        return null;

    Entry<T, Integer> max = null;
    for (Entry<T, Integer> e : map.entrySet()) {
        if (max == null || e.getValue() > max.getValue()) {
            max = e;
        }
    }

    return max.getKey();
}

From source file:com.quartz.monitor.util.Tools.java

public static QuartzInstance getQuartzInstance() {

    HttpServletRequest request = ServletActionContext.getRequest();// request
    HttpSession session = request.getSession();// requestsession
    String uuid = (String) session.getAttribute("configId");
    Map<String, QuartzInstance> quartzInstanceMap = QuartzInstanceContainer.getQuartzInstanceMap();
    if (quartzInstanceMap == null || quartzInstanceMap.size() == 0 || uuid == null || uuid.equals("")) {
        return null;
    }//from www  . j a  va 2s .c o m
    QuartzInstance instance = quartzInstanceMap.get(uuid);

    if (instance == null) {
        try {
            new InitAction().execute();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        instance = Tools.getQuartzInstance();
    }
    return instance;
}

From source file:com.spotify.scio.extra.transforms.ProcessUtil.java

static String[] createEnv(Map<String, String> environment) {
    if (environment == null || environment.isEmpty()) {
        return null;
    }/*from   w ww  .  j a v a 2 s . c o m*/
    String[] envp = new String[environment.size()];
    int i = 0;
    for (Map.Entry<String, String> e : environment.entrySet()) {
        envp[i] = e.getKey() + "=" + e.getValue();
        i++;
    }
    return envp;
}

From source file:Main.java

public static <TKey, TValue> boolean MapEquals(Map<TKey, TValue> mapA, Map<TKey, TValue> mapB) {
    if (mapA == null) {
        return mapB == null;
    }/*from  w ww.j a va  2 s .  co  m*/
    if (mapB == null) {
        return false;
    }
    if (mapA.size() != mapB.size()) {
        return false;
    }
    for (Map.Entry<TKey, TValue> kvp : mapA.entrySet()) {
        TValue valueB = null;
        boolean hasKey;
        valueB = mapB.get(kvp.getKey());
        hasKey = (valueB == null) ? mapB.containsKey(kvp.getKey()) : true;
        if (hasKey) {
            TValue valueA = kvp.getValue();
            if (!(((valueA) == null) ? ((valueB) == null) : (valueA).equals(valueB))) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}