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:com.greenline.hrs.admin.cache.redis.util.RedisInfoParser.java

/**
 * RedisInfoMapT?RedisInfoMapRedis?/*from w  w  w. j a  v  a2 s. c o m*/
 *
 * @param redisInfoMap Map
 * @return instanceTypeinfomapnullinfoMap?instancenullRedisServerInfoPO
 */
public static List<RedisKeyspaceInfo> parserToKeySpaceInfo(Map<String, String> redisInfoMap) {
    if (redisInfoMap == null || redisInfoMap.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    int dbSize = 16;
    String dbSizeStr = redisInfoMap.get(RedisCommonConst.DB_SIZE);
    if (StringUtils.isNumeric(dbSizeStr)) {
        dbSize = Integer.valueOf(dbSizeStr);
    }
    List<RedisKeyspaceInfo> result = new ArrayList<RedisKeyspaceInfo>(dbSize * 2);
    for (int i = 0; i < dbSize; i++) {
        RedisKeyspaceInfo keyspaceInfo = new RedisKeyspaceInfo();
        // TODO createTime??
        keyspaceInfo.setCreateTime(DateTime.now().toDate());
        keyspaceInfo.setDbIndex(i);
        keyspaceInfo.setKeys(0L);
        keyspaceInfo.setExpires(0L);
        String keyspaceStr = redisInfoMap.get("db" + i);
        if (keyspaceStr != null) {
            String[] properties = StringUtils.split(keyspaceStr, KS_PROPERTY_DELIMITER);
            if (properties.length >= KS_PROPERTY_MIN_SIZE) {
                keyspaceInfo.setKeys(Long.valueOf(properties[1]));
                keyspaceInfo.setExpires(Long.valueOf(properties[3]));
                result.add(keyspaceInfo);
            }
        }
    }
    return result;
}

From source file:com.microsoft.gittf.core.util.RepositoryUtil.java

public static boolean isEmptyRepository(final Repository repository) throws IOException {
    final RefDatabase refsDB = repository.getRefDatabase();
    final Map<String, Ref> refs = refsDB.getRefs(RefDatabase.ALL);
    return refs.isEmpty();
}

From source file:com.ms.commons.cookie.parser.CookieParser.java

/**
 * CookieName???Cookievalue. ?CookieNameCookieKey
 * //ww  w  . j ava 2  s  . c om
 * @return ?null
 */
static CookieNameHelper paserCookieValue(CookieNameConfig cookieNameConfig, String cookieValue) {
    String value = StringUtils.trimToNull(cookieValue);
    if (value == null || StringUtils.equalsIgnoreCase("null", value))
        return null;

    // ?
    if (cookieNameConfig.isEncrypt()) {
        value = CookieUtils.decrypt(value);
    }
    CookieNameHelper cookieNameHelper = new CookieNameHelper(cookieNameConfig.getCookieName(),
            cookieNameConfig);
    // ??Key??,?
    if (cookieNameConfig.isSimpleValue()) {
        cookieNameHelper.parserValue(value);
    } else {
        // ??Value??
        Map<CookieKeyEnum, String> kv = CookieUtils.strToKVMap(value, cookieNameConfig);
        // CookieNameHelper cookieNameHelper = null;
        if (kv != null && !kv.isEmpty())
            cookieNameHelper.parserAllValues(kv);
    }
    return cookieNameHelper;
}

From source file:crow.util.JsonUtil.java

private static JSONObject toJSONObject(Map<String, Object> map) throws JSONException {
    JSONObject jsonOb = new JSONObject();
    if ((map == null) || (map.isEmpty()))
        return jsonOb;
    Iterator<String> iter = map.keySet().iterator();
    while (iter.hasNext()) {
        String key = iter.next();
        Object value = map.get(key);
        if ((value instanceof String) || (value instanceof Integer) || (value instanceof Double)
                || (value instanceof Long) || (value instanceof Float)) {
            jsonOb.put(key, value);/*  w ww. ja va  2s.  co m*/
            continue;
        }
        if ((value instanceof Map<?, ?>)) {
            try {
                @SuppressWarnings("unchecked")
                Map<String, Object> valueMap = (Map<String, Object>) value;
                jsonOb.put(key, toJSONObject(valueMap));
            } catch (ClassCastException e) {
                Log.w(TAG, "Unknown map type in json serialization: ", e);
            }
            continue;
        }
        if ((value instanceof Set<?>)) {
            try {
                @SuppressWarnings("unchecked")
                Set<Object> valueSet = (Set<Object>) value;
                jsonOb.put(key, toJSONObject(valueSet));
            } catch (ClassCastException e) {
                Log.w(TAG, "Unknown map type in json serialization: ", e);
            }
            continue;
        }
        Log.e(TAG, "Unknown value in json serialization: " + value.toString() + " : "
                + value.getClass().getCanonicalName().toString());
    }
    return jsonOb;
}

From source file:com.datumbox.common.dataobjects.MatrixDataset.java

public static RealVector parseRecord(Record r, Map<Object, Integer> featureIdsReference) {
    if (featureIdsReference.isEmpty()) {
        throw new RuntimeException("The featureIdsReference map should not be empty.");
    }/*from  ww  w . j a v a2 s  .c o m*/

    int d = featureIdsReference.size();

    RealVector v = new ArrayRealVector(d);

    boolean addConstantColumn = featureIdsReference.containsKey(Dataset.constantColumnName);

    if (addConstantColumn) {
        v.setEntry(0, 1.0); //add the constant column
    }
    for (Map.Entry<Object, Object> entry : r.getX().entrySet()) {
        Object feature = entry.getKey();
        Double value = Dataset.toDouble(entry.getValue());
        if (value != null) {
            Integer featureId = featureIdsReference.get(feature);
            if (featureId != null) {//if the feature exists in our database
                v.setEntry(featureId, value);
            }
        } else {
            //else the X matrix maintains the 0.0 default value
        }
    }

    return v;
}

From source file:com.dcits.govsbu.southernbase.baseproject2.modules.utils.Collections3.java

/**
 * ??.//from   w ww .j a  va 2  s  .  c  om
 */
public static boolean isNotEmpty(Map map) {
    return (map != null) && !(map.isEmpty());
}

From source file:aiai.ai.launchpad.experiment.ExperimentUtils.java

public static List<HyperParams> getAllHyperParams(Map<String, String> experimentMetadatas) {
    if (experimentMetadatas == null || experimentMetadatas.isEmpty()) {
        return new ArrayList<>();
    }/*from www .j a v  a2 s  .  c o m*/

    List<HyperParams> allHyperParams = new ArrayList<>();

    List<Map.Entry<String, String>> entries = new ArrayList<>(experimentMetadatas.entrySet());

    for (Map.Entry<String, String> entry : entries) {
        NumberOfVariants ofVariants = getNumberOfVariants(entry.getValue());
        int originSize = allHyperParams.size();
        if (originSize == 0 && ofVariants.count > 0) {
            addInstances(allHyperParams, ofVariants.count);
        } else {
            for (int i = 0; i < ofVariants.count - 1; i++) {
                for (int j = 0; j < originSize; j++) {
                    HyperParams elem = allHyperParams.get(j);
                    allHyperParams.add(elem.asClone());
                }
            }
        }
        for (HyperParams list : allHyperParams) {
            for (String value : ofVariants.values) {
                if (alreadyExists(allHyperParams, list, entry.getKey(), value)) {
                    continue;
                }
                list.put(entry.getKey(), value);
                break;
            }
        }
    }
    return allHyperParams;
}

From source file:cn.martin.sys.utils.Servlets.java

/**
 * ?Parameters?Query StringParameter, paramter nameprefix.
 * //from  w  ww .  j a  v  a 2  s  .com
 * @see #getParametersStartingWith
 */
public static String encodeParameterStringWithPrefix(Map<String, Object> params, String prefix) {
    if (null == params || params.isEmpty()) {
        return "";
    }

    if (prefix == null) {
        prefix = "";
    }

    StringBuilder queryStringBuilder = new StringBuilder();
    Iterator<Entry<String, Object>> it = params.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        queryStringBuilder.append(prefix).append(entry.getKey()).append('=').append(entry.getValue());
        if (it.hasNext()) {
            queryStringBuilder.append('&');
        }
    }
    return queryStringBuilder.toString();
}

From source file:com.rsa.redchallenge.standaloneapp.utils.RestInteractor.java

/**
 * Helper function to create the URL to be called
 *
 * @param params   parameter for the call
 * @param restPath path of the interface in the REST server to be called
 * @return URL to be called/*from  www.  j ava  2s  .  com*/
 */
private static String populatePath(Map<String, Object> params, String restPath) {
    String uri = null;
    if (params != null && !params.isEmpty()) {
        String url = restPath;
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);

        for (Map.Entry<String, Object> param : params.entrySet())
            builder.queryParam(param.getKey(), param.getValue());

        uri = builder.build().toUriString();
    } else {
        uri = restPath;
    }

    return uri;
}

From source file:com.thinkbiganalytics.nifi.feedmgr.NifiEnvironmentProperties.java

/**
 * Returns a collection of the Service Name along with the Map of nifi Properties stripping the ENVIRONMENT_PROPERTY_SERVICE_PREFIX from the properties
 *
 * @param envProperties the map of environment (.properties) properties
 * @return the table of nifi ready properties
 *///from   ww  w.j ava2 s .  c  o  m
public static Table<String, String, String> getEnvironmentControllerServiceProperties(
        Map<String, String> envProperties) {
    Table<String, String, String> allProps = HashBasedTable.create();
    if (envProperties != null && !envProperties.isEmpty()) {
        for (Map.Entry<String, String> entry : envProperties.entrySet()) {
            if (entry.getKey().startsWith(getPrefix())) {
                String key = environmentPropertyToControllerServiceProperty(entry.getKey());
                String serviceName = serviceNameForEnvironmentProperty(entry.getKey());
                allProps.put(serviceName, key, entry.getValue());
            }
        }
    }
    return allProps;
}