com.ykun.commons.utils.collection.MapUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.ykun.commons.utils.collection.MapUtils.java

Source

/*
 * Commons-Utils
 * Copyright (c) 2017.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

package com.ykun.commons.utils.collection;

import com.google.common.collect.Maps;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Map?
 * ?Google Guava
 *
 * @author Ykun  2017-02-15 14:53
 */
public class MapUtils {

    /**
     * ?
     *
     * @param map the map
     * @return boolean boolean
     */
    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    /**
     * ?
     *
     * @param map the map
     * @return the boolean
     */
    public static boolean isNotEmpty(Map<?, ?> map) {
        return map != null && !map.isEmpty();
    }

    /**
     * @return the hash map
     * @see com.google.common.collect.Maps#newHashMap
     */
    public static <K, V> HashMap<K, V> newHashMap() {
        return Maps.newHashMap();
    }

    /**
     * @param key   the key
     * @param value the value
     * @return the hash map
     * @see com.google.common.collect.Maps#newHashMap
     */
    public static <K, V> HashMap<K, V> newHashMap(K key, V value) {
        HashMap<K, V> map = newHashMap();
        map.put(key, value);
        return map;
    }

    /**
     * Map??
     *
     * @return the map
     */
    public static final <K, V> Map<K, V> emptyMap() {
        return (Map<K, V>) Collections.EMPTY_MAP;
    }
}