Example usage for java.util Map.Entry get

List of usage examples for java.util Map.Entry get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:net.anthonypoon.ngram.correlation.CorrelationReducer.java

@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
    TreeMap<String, Double> currElement = new TreeMap();
    for (Text val : values) {
        String[] strArray = val.toString().split("\t");
        currElement.put(strArray[0], Double.valueOf(strArray[1]));
    }// w w  w  . j av a2 s  .com
    double[] currElementPrimitve = new double[upbound - lowbound + 1];
    for (Integer i = 0; i <= upbound - lowbound; i++) {
        if (currElement.containsKey(String.valueOf(lowbound + i - lag))) {
            currElementPrimitve[i] = currElement.get(String.valueOf(lowbound + i - lag));
        } else {
            currElementPrimitve[i] = 0;
        }

    }
    for (Map.Entry<String, TreeMap<String, Double>> pair : corrTargetArray.entrySet()) {
        double[] targetElemetPrimitive = new double[upbound - lowbound + 1];
        for (Integer i = 0; i <= upbound - lowbound; i++) {
            if (pair.getValue().containsKey(String.valueOf(lowbound + i))) {
                targetElemetPrimitive[i] = pair.getValue().get(String.valueOf(lowbound + i));
            } else {
                targetElemetPrimitive[i] = 0;
            }
        }
        Double correlation = new PearsonsCorrelation().correlation(targetElemetPrimitive, currElementPrimitve);
        if (correlation > threshold) {
            NumberFormat formatter = new DecimalFormat("#0.000");
            context.write(key, new Text(pair.getKey() + "\t" + formatter.format(correlation)));
        }
    }

}

From source file:com.spotify.helios.testing.TemporaryJob.java

/**
 * Returns a {@link com.google.common.net.HostAndPort} object for a registered port, for each
 * host the job has been deployed to. This is useful for discovering the value of dynamically
 * allocated ports./*from   w  w  w.j  av a  2 s. com*/
 * @param port the name of the registered port
 * @return a HostAndPort describing where the registered port can be reached. Null if
 * no ports have been registered.
 */
public List<HostAndPort> addresses(final String port) {
    checkArgument(job.getPorts().containsKey(port), "port %s not found", port);
    final List<HostAndPort> addresses = Lists.newArrayList();
    for (final Map.Entry<String, TaskStatus> entry : statuses.entrySet()) {
        final Integer externalPort = entry.getValue().getPorts().get(port).getExternalPort();
        assert externalPort != null;
        final String host = endpointFromHost(entry.getKey());
        addresses.add(HostAndPort.fromParts(host, externalPort));
    }
    return addresses;
}

From source file:Implement.DAO.CommonDAOImpl.java

@Override
public boolean insertNewLanguage() {
    String language = "JSON String";
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new StringReader(language));
    reader.setLenient(true);/*w  w w.j  av a 2 s .  co  m*/
    JsonObject myobject = gson.fromJson(reader, JsonObject.class);
    int flag = 0;
    for (Map.Entry<String, JsonElement> entry : myobject.entrySet()) {
        String name = entry.getValue().getAsJsonObject().get("name").toString();
        if (!name.equals(
                "\"Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic\"")) {
            String sql = "INSERT INTO Language" + " VALUES (?)";
            jdbcTemplate.update(sql, name.replaceAll("\"", ""));
        }
    }
    return true;
}

From source file:com.baasbox.android.HttpUrlConnectionClient.java

@Override
public HttpResponse execute(HttpRequest request) throws BaasException {
    try {/*ww  w .ja v  a  2s . c  o m*/
        HttpURLConnection connection = openConnection(request.url);

        for (String name : request.headers.keySet()) {
            connection.addRequestProperty(name, request.headers.get(name));
        }
        setupConnectionForRequest(connection, request);
        connection.connect();

        int responseCode = -1;
        try {
            responseCode = connection.getResponseCode();
        } catch (IOException e) {
            responseCode = connection.getResponseCode();
        }
        Logger.info("Connection response received");
        if (responseCode == -1) {
            throw new IOException("Connection failed");
        }
        StatusLine line = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), responseCode,
                connection.getResponseMessage());
        BasicHttpResponse response = new BasicHttpResponse(line);
        response.setEntity(asEntity(connection));
        for (Map.Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
            if (header.getKey() != null) {
                Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
                response.addHeader(h);
            }
        }
        return response;
    } catch (IOException e) {
        throw new BaasIOException(e);
    }
}

From source file:nu.nethome.home.items.web.proxy.HomeCloudConnection.java

private HttpResponse performLocalRequest(HttpRequest request) throws IOException {
    HttpResponse httpResponse;//from w  ww.j a  v  a 2s .  co  m
    HttpURLConnection connection = (HttpURLConnection) new URL(localURL + request.url).openConnection();
    for (String header : request.headers) {
        String parts[] = header.split(":");
        connection.setRequestProperty(parts[0].trim(), parts[1].trim());
    }
    ByteArrayBuffer baf = new ByteArrayBuffer(50);
    try (InputStream response = connection.getInputStream()) {
        BufferedInputStream bis = new BufferedInputStream(response);
        int read;
        int bufSize = 512;
        byte[] buffer = new byte[bufSize];
        while (true) {
            read = bis.read(buffer);
            if (read == -1) {
                break;
            }
            baf.append(buffer, 0, read);
        }
    } catch (IOException e) {
        return new HttpResponse(systemId, "", new String[0], CHALLENGE);
    }

    Map<String, List<String>> map = connection.getHeaderFields();
    String headers[] = new String[map.size()];
    int i = 0;
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
        headers[i++] = entry.getKey() + ":" + entry.getValue().get(0);
    }
    httpResponse = new HttpResponse(systemId, new String(Base64.encodeBase64(baf.toByteArray())), headers,
            CHALLENGE);
    return httpResponse;
}

From source file:org.apache.nifi.minifi.c2.cache.s3.S3ConfigurationCache.java

@Override
public ConfigurationCacheFileInfo getCacheFileInfo(String contentType, Map<String, List<String>> parameters)
        throws InvalidParameterException {

    String pathString = pathPattern;
    for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
        if (entry.getValue().size() != 1) {
            throw new InvalidParameterException(
                    "Multiple values for same parameter" + " are not supported by this provider.");
        }//from  w  w  w .ja  va  2s. c  om
        pathString = pathString.replaceAll(Pattern.quote("${" + entry.getKey() + "}"), entry.getValue().get(0));
    }
    pathString = pathString + "." + contentType.replace('/', '.');
    String[] split = pathString.split("/");
    for (String s1 : split) {
        int openBrace = s1.indexOf("${");
        if (openBrace >= 0 && openBrace < s1.length() + 2) {
            int closeBrace = s1.indexOf("}", openBrace + 2);
            if (closeBrace >= 0) {
                throw new InvalidParameterException(
                        "Found unsubstituted variable " + s1.substring(openBrace + 2, closeBrace));
            }
        }
    }

    return new S3CacheFileInfoImpl(s3, bucket, prefix, pathString + ".v");
}

From source file:org.hbasene.index.HBaseIndexStore.java

void doAddTermFrequency(final int docId, final Map<String, List<Integer>> termFrequencies) throws IOException {
    for (final Map.Entry<String, List<Integer>> entry : termFrequencies.entrySet()) {
        if (entry.getValue().size() == 1 && entry.getValue().get(0) == 0) {
            continue;
        }/*from w w  w .ja  v  a2s. c  o  m*/
        Map<Integer, List<Integer>> existingFrequencies = this.termFrequencies.get(entry.getKey());
        if (existingFrequencies == null) {
            existingFrequencies = Maps.newHashMap();
            this.termFrequencies.put(entry.getKey(), existingFrequencies);
        }
        existingFrequencies.put(docId, entry.getValue());
    }
}

From source file:com.aliyun.openservices.odps.console.mapreduce.runtime.MapReduceJob.java

private void makeAlias4TempResources() {
    Map<String, List<String>> tempResources = mrCmd.getTempResources();
    if (!tempResources.isEmpty()) {
        for (Map.Entry<String, List<String>> entry : tempResources.entrySet()) {
            SetCommand.aliasMap.put(entry.getKey(), entry.getValue().get(1));
        }/*w w  w  .jav  a 2s .  c  om*/
    }
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.CsvTable.java

public void add(String[] row) {
    table.add(row);//  w w  w . j  a  v a2 s.  co  m
    for (Map.Entry<Integer, TreeMap<String, List<String[]>>> me : indices.entrySet()) {
        if (row.length > me.getKey()) {
            String keyval = row[me.getKey()];
            List<String[]> sl = me.getValue().get(keyval);
            if (sl == null) {
                sl = new ArrayList<String[]>();
                sl.add(row);
                me.getValue().put(keyval, sl);
            } else {
                sl.add(row);
            }
        }
    }
}

From source file:org.languagetool.dev.RuleCreator.java

private void run(File homophoneOccurrences, String homophonePath) throws IOException {
    ConfusionSetLoader confusionSetLoader = new ConfusionSetLoader();
    InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(homophonePath);
    Map<String, List<ConfusionPair>> confusionPairsMap = confusionSetLoader.loadConfusionPairs(inputStream);
    initMaps(homophoneOccurrences);// w  w  w  .j  a  v  a  2  s  .c o  m
    int groupCount = 0;
    if (XML_MODE) {
        System.out.println("<rules lang='en'>\n");
        System.out.println("<category name='Auto-generated rules'>\n");
    }
    for (Map.Entry<String, List<ConfusionPair>> entry : confusionPairsMap.entrySet()) {
        System.err.println(" === " + entry + " === ");
        if (entry.getValue().size() > 1) {
            System.err.println("WARN: will use only first pair of " + entry.getValue().size() + ": "
                    + entry.getValue().get(0));
        }
        List<OccurrenceInfo> infos = occurrenceInfos.get(entry.getKey());
        if (infos == null) {
            System.err.println("Could not find occurrence infos for '" + entry.getKey() + "', skipping");
            continue;
        }
        Set cleanSet = new HashSet<>(entry.getValue().get(0).getTerms());
        cleanSet.remove(entry.getKey());
        String name = StringUtils.join(cleanSet, "/") + " -> " + entry.getKey();
        if (XML_MODE) {
            System.out.println(
                    "<rulegroup id='R" + groupCount + "' name=\"" + StringTools.escapeXML(name) + "\">\n");
        }
        groupCount++;
        for (OccurrenceInfo occurrenceInfo : infos) {
            String[] parts = occurrenceInfo.ngram.split(" ");
            for (ConfusionString variant : entry.getValue().get(0).getTerms()) {
                if (variant.getString().equals(entry.getKey())) {
                    continue;
                }
                printRule(occurrenceInfo, parts, variant.getString());
            }
        }
        if (XML_MODE) {
            System.out.println("</rulegroup>\n");
        }
    }
    if (XML_MODE) {
        System.out.println("</category>");
        System.out.println("</rules>");
    }
    System.err.println("Done. Wrote " + ruleCount + " rules.");
    System.err.println("Rules ignored because of different tokenization: " + tokenFilteredRules);
    System.err.println(
            "Rules ignored because of error probability limit (" + minErrorProb + "): " + probFilteredRules);
}