Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:org.logger.event.web.utils.ServerValidationUtils.java

public static void rejectIfInvalid(Errors errors, Double data, String field, String errorCode, String errorMsg,
        Map<Double, String> ratingScore) {
    if (!ratingScore.containsKey(data)) {
        errors.rejectValue(field, errorCode, errorMsg);
    }//from w w w.  j  a  v  a  2  s .co m
}

From source file:com.simplymeasured.prognosticator.HiveUtils.java

/**
 * Get the HBase column mappings for a table defined in HCatalog. Needed to know which column family
 * each column should reside in/*w  w  w . j a v a 2  s.  co  m*/
 *
 * @param table table instance to retrieve mappings from
 * @return an ordered list of column family:column mappings
 */
public static List<String> getColumnMappings(HCatTable table) {
    List<String> columnMappings = null;

    Map<String, String> tableProperties = table.getTblProps();
    if (!tableProperties.containsKey(HBASE_COLUMNS_MAPPING)) {
        LOG.warn("hbase.columns.mapping missing, assuming all column families are 'default'");
    } else {
        columnMappings = Lists.newArrayList(tableProperties.get(HBASE_COLUMNS_MAPPING).split(","));
    }

    return columnMappings;
}

From source file:Main.java

public static String formetPropsAsTableKey(Map<String, List<String>> selectProps, List<String> keys_order) {
    String props = "";

    for (String key : keys_order) {
        if (selectProps.containsKey(key)) {
            props += ":" + selectProps.get(key).get(0);
        }//  w ww.j  a va2 s  .c  o  m
    }
    if (!TextUtils.isEmpty(props))
        props = props.substring(1);
    return props;
}

From source file:io.wcm.devops.conga.model.util.MapExpander.java

/**
 * Get object from map with "deep" access resolving dots in the key as nested map keys.
 * @param map Map/*from  ww  w. j ava  2  s.c  o  m*/
 * @param key Key with dots
 * @return Value or null
 */
@SuppressWarnings("unchecked")
public static Object getDeep(Map<String, Object> map, String key) {
    if (map.containsKey(key)) {
        return ObjectUtils.defaultIfNull(map.get(key), "");
    }
    if (StringUtils.contains(key, ".")) {
        String keyPart = StringUtils.substringBefore(key, ".");
        String keySuffix = StringUtils.substringAfter(key, ".");
        Object resultKeyPart = map.get(keyPart);
        if (resultKeyPart != null && resultKeyPart instanceof Map) {
            return getDeep((Map<String, Object>) resultKeyPart, keySuffix);
        }
    }
    return null;
}

From source file:alfio.model.modification.support.LocationDescriptor.java

public static ConfigurationKeys.GeoInfoProvider getProvider(Map<ConfigurationKeys, Optional<String>> geoConf) {
    if ((!geoConf.containsKey(ConfigurationKeys.MAPS_PROVIDER)
            || !geoConf.get(ConfigurationKeys.MAPS_PROVIDER).isPresent())
            && (geoConf.containsKey(ConfigurationKeys.MAPS_CLIENT_API_KEY)
                    && geoConf.get(ConfigurationKeys.MAPS_CLIENT_API_KEY).isPresent())) {
        return ConfigurationKeys.GeoInfoProvider.GOOGLE;
    } else if (geoConf.containsKey(ConfigurationKeys.MAPS_PROVIDER)
            && geoConf.get(ConfigurationKeys.MAPS_PROVIDER).isPresent()) {
        return geoConf.get(ConfigurationKeys.MAPS_PROVIDER).map(ConfigurationKeys.GeoInfoProvider::valueOf)
                .orElseThrow(IllegalStateException::new);
    } else {/*  w w  w.j a  v  a 2  s . c  om*/
        return ConfigurationKeys.GeoInfoProvider.NONE;
    }
}

From source file:com.mingo.mongo.aggregation.AggregationUtils.java

/**
 * Add field to builder if exist in  parameters.
 *
 * @param builder    {@link BasicDBObjectBuilder}
 * @param fieldName  field name/*from w  ww.  j  a  v a 2  s .  c  om*/
 * @param parameters parameters
 */
public static void appendField(BasicDBObjectBuilder builder, String fieldName, Map<String, String> parameters) {
    if (MapUtils.isNotEmpty(parameters) && parameters.containsKey(fieldName)) {
        builder.add(fieldName, parameters.get(fieldName));
    }
}

From source file:com.cloudant.todo.Task.java

public static Task fromRevision(BasicDocumentRevision rev) {
    Task t = new Task();
    t.rev = rev;//  w  ww. ja  va  2 s  . com
    // this could also be done by a fancy object mapper
    Map<String, Object> map = rev.asMap();
    if (map.containsKey("tipe") && map.get("tipe").equals(Task.DOC_TYPE)) {
        t.setType((String) map.get("tipe"));
        t.setGeometry((String) map.get("geometry"));
        //t.setLatitude((Double) map.get("latitude"));
        //t.setLongitude((Double) map.get("longitude"));
        return t;
    }
    return null;
}

From source file:com.github.stagirs.lingvo.build.MorphStateMachineBuilder.java

private static void add(Map<String, List<WordForm[]>> result, WordForm raw, WordForm norm) {
    if (!result.containsKey(raw.getWord())) {
        result.put(raw.getWord(), new ArrayList<WordForm[]>());
    }/* w w w  . ja va2 s.co  m*/
    result.get(raw.getWord()).add(new WordForm[] { raw, norm });
}

From source file:Main.java

/**
 * Given an Object, and a key (index), it will get value associated with
 * that key in the Object. The following checks are made:
 * <ul>/*from   w  w  w . j a v  a 2s.c  o m*/
 * <li>If obj is a Map, use the index as a key to get a value. If no match
 * continue.
 * <li>Check key is an Integer. If not, return the object passed in.
 * <li>If obj is a Map, get the nth value from the <b>key</b> iterator.
 * <li>If obj is a List or an array, get the nth value.
 * <li>If obj is an iterator, enumeration or Collection, get the nth value
 * from the iterator.
 * <li>Return the original obj.
 * </ul>
 * 
 * @param obj
 *            the object to get an index of
 * @param index
 *            the index to get
 * @return the object at the specified index
 * @throws IndexOutOfBoundsException
 * @throws NoSuchElementException
 */
public static Object index(Object obj, Object index) {
    if (obj instanceof Map) {
        Map map = (Map) obj;
        if (map.containsKey(index)) {
            return map.get(index);
        }
    }
    int idx = -1;
    if (index instanceof Integer) {
        idx = ((Integer) index).intValue();
    }
    if (idx < 0) {
        return obj;
    } else if (obj instanceof Map) {
        Map map = (Map) obj;
        Iterator iterator = map.keySet().iterator();
        return index(iterator, idx);
    } else if (obj instanceof List) {
        return ((List) obj).get(idx);
    } else if (obj instanceof Object[]) {
        return ((Object[]) obj)[idx];
    } else if (obj instanceof Enumeration) {
        Enumeration enumeration = (Enumeration) obj;
        while (enumeration.hasMoreElements()) {
            idx--;
            if (idx == -1) {
                return enumeration.nextElement();
            } else {
                enumeration.nextElement();
            }
        }
    } else if (obj instanceof Iterator) {
        return index((Iterator) obj, idx);
    } else if (obj instanceof Collection) {
        Iterator iterator = ((Collection) obj).iterator();
        return index(iterator, idx);
    }
    return obj;
}

From source file:jj.resource.FileTypeSettingsDefaultProvider.java

private static ResourceSettings makeSettings(Map<String, Object> input) {
    String mimeType = (String) input.get("mimeType");
    Charset charset = input.containsKey("charset") ? Charset.forName((String) input.get("charset")) : null;
    boolean compressible = input.containsKey("compressible") && Boolean.TRUE.equals(input.get("compressible"));

    return new ResourceSettings(mimeType, charset, compressible);
}