get Map Bool - Android java.util

Android examples for java.util:Map

Description

get Map Bool

Demo Code


//package com.java2s;

import java.util.Map;

public class Main {
    public static boolean getMapBool(final Map<?, ?> map, final String key) {
        String value = getMapStr(map, key);
        if (value.isEmpty())
            return false;
        if (value.startsWith("0")) // handles "0" and "0.0"
            return false;
        if (value.equalsIgnoreCase("false"))
            return false;
        // all other values are assume to be true
        return true;
    }//from   w w w  . ja  v  a 2s .  c  o m

    public static String getMapStr(final Map<?, ?> map, final String key) {
        if (map == null || key == null || !map.containsKey(key)
                || map.get(key) == null) {
            return "";
        }
        return map.get(key).toString();
    }
}

Related Tutorials