Example usage for java.util Map isEmpty

List of usage examples for java.util Map isEmpty

Introduction

In this page you can find the example usage for java.util Map isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:Main.java

private static String parseConstant(String condition, Map<String, String> mpUser) {
    if (condition == null || condition.length() == 0)
        return "";
    if (mpUser == null || mpUser.isEmpty())
        return condition;

    condition = condition.replaceAll("{CURUSERID}", mpUser.get("user_id"));

    condition = condition.replaceAll("{CURUSERCODE}", mpUser.get("user_code"));

    condition = condition.replaceAll("{CURUSERNAME}", mpUser.get("user_name"));

    condition = condition.replaceAll("{CURDEPTID}", mpUser.get("dept_id"));

    condition = condition.replaceAll("{CURDEPTCODE}", mpUser.get("dept_code"));

    condition = condition.replaceAll("{CURDEPTNAME}", mpUser.get("dept_name"));

    return condition;
}

From source file:com.thoughtworks.go.security.RegistrationJSONizer.java

public static Registration fromJson(String json) {
    Map map = GSON.fromJson(json, Map.class);

    if (map.isEmpty()) {
        return Registration.createNullPrivateKeyEntry();
    }//  ww  w .  jav  a  2s. c om

    List<X509Certificate> chain = new ArrayList<>();
    try {
        PemReader reader = new PemReader(new StringReader((String) map.get("agentPrivateKey")));
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(reader.readPemObject().getContent());
        PrivateKey privateKey = kf.generatePrivate(spec);
        String agentCertificate = (String) map.get("agentCertificate");
        PemReader certReader = new PemReader(new StringReader(agentCertificate));
        while (true) {
            PemObject obj = certReader.readPemObject();
            if (obj == null) {
                break;
            }
            chain.add((X509Certificate) CertificateFactory.getInstance("X.509")
                    .generateCertificate(new ByteArrayInputStream(obj.getContent())));
        }
        return new Registration(privateKey, chain.toArray(new X509Certificate[0]));
    } catch (IOException | NoSuchAlgorithmException | CertificateException | InvalidKeySpecException e) {
        throw bomb(e);
    }
}

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

/**
 * Normalizes valueMeta by stripping whitespace from name. validate() must
 * already have been called on the valueMeta
 *///from w  w  w  . j  a va2 s  .c om
public static Map<String, String> normalize(Map<String, String> valueMeta) {
    if (valueMeta == null || valueMeta.isEmpty()) {
        return EMPTY_VALUE_META;
    }
    final Map<String, String> result = new HashMap<>();
    for (Map.Entry<String, String> entry : valueMeta.entrySet()) {
        final String key = CharMatcher.WHITESPACE.trimFrom(entry.getKey());
        result.put(key, entry.getValue());
    }

    return result;
}

From source file:com.mmj.app.common.cookie.parser.CookieUtils.java

/**
 * Map?//from w  ww  . ja  va 2 s . c om
 * 
 * @return KV(nullempty),null
 */
public static String mapToStr(Map<CookieKeyEnum, String> kv) {
    if (kv == null || kv.isEmpty()) {
        return null;
    }

    StringBuilder sb = new StringBuilder();
    List<CookieKeyEnum> keys = new ArrayList<CookieKeyEnum>(kv.keySet());
    for (int i = 0, j = keys.size(); i < j; i++) {
        CookieKeyEnum key = keys.get(i);
        String value = kv.get(key);
        sb.append(key.getKey()).append(COOKIE_KEY_VALUE_SEPARATOR_CHAR).append(value);
        // ??
        boolean notTheLast = (i < keys.size() - 1);
        if (notTheLast) {
            sb.append(COOKIE_MAP_SEPARATOR_CHAR);
        }
    }
    return sb.toString();
}

From source file:Main.java

/**
 * This method returns a new HashMap which is the intersection of the two Map parameters, based on {@link Object#equals(Object) equality}
 * of their entries.//from   w  ww . jav a  2s  . co  m
 * Any references in the resultant map will be to elements within map1.
 * 
 * @return a new HashMap whose values represent the intersection of the two Maps.
 */
public static <K, V> Map<K, V> intersect(Map<K, V> map1, Map<K, V> map2) {
    if (map1 == null || map1.isEmpty() || map2 == null || map2.isEmpty()) {
        return Collections.emptyMap();
    }

    // We now know neither map is null.
    Map<K, V> result = new HashMap<K, V>();
    for (Map.Entry<K, V> item : map1.entrySet()) {
        V value = map2.get(item.getKey());
        if (value != null && value.equals(item.getValue())) {
            result.put(item.getKey(), item.getValue());
        }
    }

    return result;
}

From source file:net.hamnaberg.confluence.admin.CacheControlConfig.java

public static CacheControlConfig fromMap(Map<String, String> map) {
    if (map == null || map.isEmpty()) {
        return null;
    }/*from   w w w .ja v a2  s .  co m*/
    return new CacheControlConfig(NumberUtils.toInt(map.get("ttl"), 300),
            Boolean.parseBoolean(map.get("transform")), Boolean.parseBoolean(map.get("revalidate")));
}

From source file:Main.java

public static void printDetails(Map<String, String> map) {
    String usage = map.get("CSS");
    System.out.println("Map: " + map);
    System.out.println("Map Size:  " + map.size());
    System.out.println("Map is empty:  " + map.isEmpty());
    System.out.println("Map contains CSS key:   " + map.containsKey("CSS"));
    System.out.println("Usage:  " + usage);
    System.out.println("removed:  " + map.remove("CSS"));
}

From source file:Main.java

public static boolean isNotEmpty(Map map) {
    return (map != null && !(map.isEmpty()));
}

From source file:org.activiti.spring.SpringConfigurationHelper.java

public static ProcessEngine buildProcessEngine(URL resource) {
    log.debug(/* w w  w.j av a2  s.  com*/
            "==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");

    ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
    Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
    if ((beansOfType == null) || (beansOfType.isEmpty())) {
        throw new ActivitiException("no " + ProcessEngine.class.getName()
                + " defined in the application context " + resource.toString());
    }

    ProcessEngine processEngine = beansOfType.values().iterator().next();

    log.debug(
            "==== SPRING PROCESS ENGINE CREATED ==================================================================");
    return processEngine;
}

From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java

public static void encodeAttachments(MultivaluedMap<String, Object> headers, Map<String, String> attachments) {
    if (attachments == null || attachments.isEmpty())
        return;//from  www  .  jav a 2  s . c om

    StringBuilder value = new StringBuilder();
    for (Map.Entry<String, String> entry : attachments.entrySet()) {
        value.append(StringTools.urlEncode(entry.getKey())).append("=")
                .append(StringTools.urlEncode(entry.getValue())).append(";");
    }

    if (value.length() > 1)
        value.deleteCharAt(value.length() - 1);

    headers.add(ATTACHMENT_HEADER, value.toString());
}