Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Document

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

Usage

From source file:com.michellemay.mappings.DisplayNamesMapping.java

/**
 * Instantiates a new Display names mapping.
 *
 * @param name the name/*from ww  w  . jav a  2 s .co m*/
 * @param displayLocale the display locale
 */
public DisplayNamesMapping(String name, Locale displayLocale) {
    super(name);
    this.displayLocale = displayLocale;

    // Build reverse map
    HashMap<String, Locale> map = new HashMap<String, Locale>();
    for (String isoCode : Locale.getISOLanguages()) {
        Locale loc = LocaleUtils.toLocale(isoCode);
        String displayName = loc.getDisplayName(displayLocale).toLowerCase();
        if (isoCode.length() > 0 && !map.containsKey(displayName)) {
            map.put(displayName, loc);
        }
    }

    this.withMapping(map).withCaseSensitive(false);
}

From source file:com.thoughtworks.go.config.Agents.java

private boolean validateDuplicateElasticAgentIds() {
    HashMap<String, String> elasticAgentIdToUUIDMap = new HashMap<>();
    for (AgentConfig agentConfig : this) {

        if (!agentConfig.isElastic()) {
            continue;
        }//  w w  w  .j  a v a  2s .  c o m

        if (elasticAgentIdToUUIDMap.containsKey(agentConfig.getElasticAgentId())) {
            AgentConfig duplicatedAgentConfig = this
                    .getAgentByUuid(elasticAgentIdToUUIDMap.get(agentConfig.getElasticAgentId()));
            String error = String.format("Duplicate ElasticAgentId found for agents [%s, %s]",
                    duplicatedAgentConfig.getUuid(), agentConfig.getUuid());
            agentConfig.addError(elasticAgentId, error);
            duplicatedAgentConfig.addError("elasticAgentId", error);
            return false;
        }

        elasticAgentIdToUUIDMap.put(agentConfig.getElasticAgentId(), agentConfig.getUuid());
    }

    return true;
}

From source file:com.twosigma.beakerx.inspect.Inspect.java

private InspectResult getInspectResult(int caretPosition, String methodName, String className,
        String everything) {/*  w w w . j av a2  s.com*/
    HashMap<String, ClassInspect> stringClassInspectHashMap = new SerializeInspect().fromJson(everything);
    InspectResult inspectResult = new InspectResult();
    ClassInspect classInspect = null;
    if (stringClassInspectHashMap.containsKey(className)) {
        classInspect = stringClassInspectHashMap.get(className);
    } else {
        for (ClassInspect cls : stringClassInspectHashMap.values()) {
            if (cls.getClassName().equals(className)) {
                classInspect = cls;
                break;
            }
        }
    }
    if (methodName == null && classInspect != null) {
        List<MethodInspect> constructors = classInspect.getConstructors();
        String classInfo = parseClassInfo(classInspect) + "\n\n" + parseMethodsInfo(constructors, "");
        inspectResult = new InspectResult(classInfo, caretPosition);
    } else {
        List<MethodInspect> methodInspectsList = classInspect == null ? null : classInspect.getMethods();
        if (methodInspectsList == null) {
            return new InspectResult();
        }
        List<MethodInspect> methods = methodInspectsList.stream()
                .filter(m -> m.getMethodName().equals(methodName)).collect(Collectors.toList());
        if (!methods.isEmpty()) {
            return new InspectResult(parseMethodsInfo(methods, className), caretPosition);
        }
    }
    return inspectResult;
}

From source file:com.restservice.dto.DataGroupingResult.java

public DataGroupingResult(int[] clusterResult, double[][] coordinatesMDS, ArrayList<String> tweetIds) {
    HashMap<Integer, Integer> clusterToIndex = new HashMap<Integer, Integer>();

    series = new ArrayList<Series>();

    for (int i = 0; i < clusterResult.length; ++i) {
        int currentCluster = clusterResult[i];
        if (clusterToIndex.containsKey(currentCluster)) {
            series.get(clusterToIndex.get(currentCluster)).getData().add(coordinatesMDS[i]);
            series.get(clusterToIndex.get(currentCluster)).getIds().add(tweetIds.get(i));
        } else {//from   www .j  a  v a  2s . com
            clusterToIndex.put(currentCluster, series.size());
            Series newSeries = new Series();
            newSeries.setName("Cluster " + (currentCluster + 1));
            newSeries.getData().add(coordinatesMDS[i]);
            newSeries.getIds().add(tweetIds.get(i));
            series.add(newSeries);
        }
    }

    total_count = clusterResult.length;
}

From source file:com.sonicle.webtop.core.io.input.FileRowsReader.java

public List<FieldMapping> listFieldMappings(File file, String[] targetFields, boolean strict)
        throws IOException, FileReaderException {
    ArrayList<FieldMapping> mappings = new ArrayList<>();
    HashMap<String, String> cols = listColumnNames(file);

    String lwr, source = null;//from  w w  w .  jav a  2 s  . com
    for (int i = 0; i < targetFields.length; i++) {
        source = null;
        lwr = targetFields[i].toLowerCase();
        if (cols.containsKey(lwr)) {
            if (!strict || StringUtils.equals(targetFields[i], cols.get(lwr))) {
                source = cols.get(lwr);
            }
        }
        mappings.add(new FieldMapping(targetFields[i], source));
    }

    return mappings;
}

From source file:com.michellemay.mappings.ISO639Alpha3Mapping.java

/**
 * Instantiates a new ISO 639 alpha 3 mapping.
 *///from www .  j  av  a2  s.c o  m
public ISO639Alpha3Mapping() {
    super(NAME);

    // Build reverse map
    HashMap<String, Locale> map = new HashMap<String, Locale>();
    for (Locale loc : LocaleUtils.availableLocaleList()) {
        String isoCode = loc.getLanguage();
        if (isoCode.length() > 0) {
            String displayValue = loc.getISO3Language().toLowerCase();
            if (!map.containsKey(displayValue)) {
                map.put(displayValue, LocaleUtils.toLocale(isoCode));
            }
        }
    }
    this.withMapping(map).withCaseSensitive(false);
}

From source file:com.unister.semweb.drums.bucket.hashfunction.RangeHashFunction.java

/**
 * The header of could contain characters which are not numbers. Some of them can be translated into bytes. E.g.
 * char would be two byte./*from www.ja v a2 s.  c o  m*/
 * 
 * @param code
 *            the code to look for
 * @return the size of the given code
 */
public static int stringToByteCount(String code) {
    @SuppressWarnings("serial")
    HashMap<String, Integer> codingMap = new HashMap<String, Integer>() {
        {
            put("b", 1);
            put("byte", 1);
            put("bool", 1);
            put("boolean", 1);
            put("c", 2);
            put("char", 2);
            put("character", 2);
            put("i", 4);
            put("int", 4);
            put("integer", 4);
            put("f", 4);
            put("float", 4);
            put("d", 8);
            put("double", 8);
            put("l", 8);
            put("long", 8);
            put("1", 1);
            put("2", 2);
            put("3", 3);
            put("4", 4);
            put("5", 5);
            put("6", 6);
            put("7", 7);
            put("8", 8);
        }
    };
    if (codingMap.containsKey(code)) {
        return codingMap.get(code.toLowerCase());
    } else {
        return 0;
    }
}

From source file:ru.apertum.qsystem.reports.model.QReportsList.java

private boolean checkLogin(HttpRequest request) {
    boolean res = false;
    //  ?     , ? ,    
    String entityContent = NetUtil.getEntityContent(request);
    QLog.l().logger().trace("?  \"" + entityContent + "\".");
    // ?? ?   . ?  ??        
    //  //from   ww  w .jav a 2s  . c o m
    final HashMap<String, String> cookie = NetUtil.getCookie(entityContent, "&");
    if (cookie.containsKey("username") && cookie.containsKey("password")) {
        if (isTrueUser(cookie.get("username"), cookie.get("password"))) {
            res = true;
        }
    }
    return res;
}

From source file:gr.cti.android.experimentation.controller.ui.RestRankingController.java

@ResponseBody
@RequestMapping(value = { "/results/{experimentId}" }, method = RequestMethod.GET)
public Set<DownloadableResultDTO> getResults(@PathVariable("experimentId") final int experimentId) {
    final Set<DownloadableResultDTO> externalResults = new TreeSet<>();
    final Set<Result> results = resultRepository.findByExperimentId(experimentId);
    LOGGER.info("Will try to convert " + results.size() + " results.");
    for (final Result result : results) {
        try {//www . ja  v a2s .  c  o  m
            final DownloadableResultDTO dres = new DownloadableResultDTO();
            dres.setDate(result.getTimestamp());
            final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(),
                    new HashMap<String, Object>().getClass());
            if (dataMap.containsKey(LONGITUDE) && dataMap.containsKey(LATITUDE)) {
                dres.setLongitude((Double) dataMap.get(LONGITUDE));
                dres.setLatitude((Double) dataMap.get(LATITUDE));
                dres.setResults(new HashMap<>());
                dataMap.keySet().stream().filter(key -> !key.equals(LATITUDE) && !key.contains(LONGITUDE))
                        .forEach(key -> {
                            dres.getResults().put(key, String.valueOf(dataMap.get(key)));
                        });
            }
            if (dres.getResults() != null) {
                externalResults.add(dres);
            }
        } catch (Exception e) {
            LOGGER.error(e, e);
        }
    }
    return externalResults;
}

From source file:com.cloud.api.ApiServletTest.java

@Test
public void utf8FixupStrangeInputs() {
    Mockito.when(request.getQueryString()).thenReturn("&&=a&=&&a&a=a=a=a");
    HashMap<String, Object[]> params = new HashMap<String, Object[]>();
    servlet.utf8Fixup(request, params);// w w  w.  ja  v a2 s  .co m
    Assert.assertTrue(params.containsKey(""));
}