Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public 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:com.twosigma.beakerx.mimetype.MIMEContainer.java

private static String parseParams(HashMap paramsMap) {
    List iframeParamKeys = Arrays.asList("width", "height", "id");

    StringBuilder sb = new StringBuilder();
    for (Object key : paramsMap.keySet()) {
        if (iframeParamKeys.contains(key)) {
            continue;
        }//from w  ww  .j  a va  2 s  .  com
        sb.append("&").append(key.toString()).append("=").append(paramsMap.get(key).toString());
    }
    String result = sb.toString().replaceFirst("&", "?");
    return result.length() > 0 ? result : "";
}

From source file:it.acubelab.smaph.SmaphUtils.java

/**
 * Turns a list of pairs <b,r>, where b is a bold and r is the position in
 * which the bold occurred, to a mapping from a bold to the positions in
 * which the bolds occurred.//from ww  w  .  j a v  a  2 s. c om
 * 
 * @param boldAndRanks
 *            a list of pairs <b,r>, where b is a bold and r is the position
 *            in which the bold occurred.
 * @return a mapping from a bold to the positions in which the bold
 *         occurred.
 */
public static HashMap<String, HashSet<Integer>> findPositionsLC(List<Pair<String, Integer>> boldAndRanks) {
    HashMap<String, HashSet<Integer>> positions = new HashMap<>();
    for (Pair<String, Integer> boldAndRank : boldAndRanks) {
        String bold = boldAndRank.first.toLowerCase();
        int rank = boldAndRank.second;
        if (!positions.containsKey(bold))
            positions.put(bold, new HashSet<Integer>());
        positions.get(bold).add(rank);
    }
    return positions;
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEAppHandler.java

public static HashMap<String, List<TrackerFieldSoapDO>> loadTrackerFieldsInHashMap(
        TrackerFieldSoapDO[] flexFields) {
    HashMap<String, List<TrackerFieldSoapDO>> fieldsMap = new HashMap<String, List<TrackerFieldSoapDO>>();
    for (TrackerFieldSoapDO field : flexFields) {
        String fieldName = field.getName();
        // FIXME Will we ever get two field with same name in method?
        if (fieldsMap.containsKey(fieldName)) {
            List<TrackerFieldSoapDO> fieldsList = fieldsMap.get(fieldName);
            fieldsList.add(field);/*w  ww. j a va2  s  .  c  om*/
        } else {
            List<TrackerFieldSoapDO> fieldsList = new ArrayList<TrackerFieldSoapDO>();
            fieldsList.add(field);
            fieldsMap.put(fieldName, fieldsList);
        }
    }
    return fieldsMap;
}

From source file:es.pode.soporte.auditoria.registrar.Registrar.java

/**
 * Registro de la operacin ficha//from  www .j a va 2s  . c om
 *    @param valores Tabla con los valores capturados
 *  @param destino Operacin realizada
 */
public static void operacionFicha(DatosVO datosInterceptados) throws Exception {

    String moduloDestino = datosInterceptados.getModuloDestino();
    HashMap valores = datosInterceptados.getValores();

    String fichaBusquedaSimpleAvanzada = (String) valores.get(RegistroCtes.PARAMETRO_TIPO_BUSQUEDA);

    log("Valores ficha busqueda simple avanzada:  " + fichaBusquedaSimpleAvanzada);

    /* Nos aseguramos que en la ficha es la llamada que nos interesa */
    if (!RegistroCtes.VALORES_FICHA_SIMPLEAVANZADA.equals(fichaBusquedaSimpleAvanzada))
        return;

    String idODE = (String) valores.get(RegistroCtes.PARAMETRO_IDENTIFICADOR_ODE);
    String idioma = (String) valores.get(RegistroCtes.PARAMETRO_IDIOMA);//En la operacin de solicitar metadato(ficha) nos interesa el idioma de bsqueda

    registrarOperacion(idODE, idioma, moduloDestino);
}

From source file:Main.java

public static int getFrequentElement(int[] bcp) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;/*from   w  ww .j a  va  2  s. c  o  m*/

    for (int col = 0; col < bcp.length; col++) {
        //System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(bcp[col])) {
            map.put(bcp[col], id++);
            count.add(1);
            uniId.add(bcp[col]);
        } else {
            no = map.get(bcp[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    //System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    return maxId;
}

From source file:Main.java

public static boolean getFrequentElementBinary(int[] sample) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;//from   ww w  .j  av a  2  s .  c  o  m

    for (int col = 0; col < sample.length; col++) {
        // System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(sample[col])) {
            map.put(sample[col], id++);
            count.add(1);
            uniId.add(sample[col]);
        } else {
            no = map.get(sample[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    // System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    if (maxId == 1)
        return true;
    else
        return false;
}

From source file:org.addhen.smssync.net.SmsSyncHttpClient.java

/**
 * Upload SMS to a web service via HTTP POST
 * //from w w w .  ja va  2  s  .co  m
 * @param address
 * @throws MalformedURLException
 * @throws IOException
 * @return
 */
public static boolean postSmsToWebService(String url, HashMap<String, String> params, Context context) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);

    try {

        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("secret", params.get("secret")));
        nameValuePairs.add(new BasicNameValuePair("from", params.get("from")));
        nameValuePairs.add(new BasicNameValuePair("message", params.get("message")));
        nameValuePairs.add(new BasicNameValuePair("sent_timestamp", params.get("sent_timestamp")));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        if (response.getStatusLine().getStatusCode() == 200) {
            String resp = getText(response);
            boolean success = Util.extractPayloadJSON(resp);

            if (success) {
                // auto response message is enabled to be received from the
                // server.
                if (Prefrences.enableReplyFrmServer) {
                    Util.sendResponseFromServer(context, resp);
                }

                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }

    } catch (ClientProtocolException e) {
        return false;
    } catch (IOException e) {
        return false;
    }

}

From source file:edu.isistan.carcha.util.PluginUtil.java

/**
 * Gets the DD distribution for cross cutting concern.
 *
 * @param cp the cp//from  w  w  w .  j  a  va2s . com
 * @param kind the kind
 * @return the DD distribution for cross cutting concern
 */
public static HashMap<String, Integer> getDDDistributionForCrossCuttingConcern(CarchaProject cp, String kind) {
    HashMap<String, Integer> values = new HashMap<String, Integer>();
    Integer temp = 0;

    for (TraceabilityLink link : cp.getLinks()) {
        if (link.getConcern().getKind().equalsIgnoreCase(kind)) {
            temp = values.get(link.getDesignDecision().getKind());
            if (temp != null) {
                temp++;
            } else {
                temp = 1;
            }
            values.put(link.getDesignDecision().getKind(), temp);
        }
    }
    return values;
}

From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java

public static void buildJson3(HashMap<String, Object> json, String[] path) {
    if (path.length == 1) {
        HashMap<String, Object> newObj = new HashMap<>();
        newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
        newObj.put("files", new ArrayList<HashMap<String, Object>>());
        json.put(path[0], newObj);/*from   w  w w. j  a v  a2 s .  c  o  m*/

    } else {
        HashMap<String, Object> current = (HashMap<String, Object>) json.get(path[0]);
        for (int i = 1; i < path.length; i++) {
            String currentName = path[i];
            if (Pattern.matches(extensionRegex, currentName)) {
                HashMap<String, Object> newFile = new HashMap<>();
                newFile.put("name", currentName);
                newFile.put("link", getLink(path));
                List filesList = (List) current.get("files");
                filesList.add(newFile);
            } else {
                if (containsName((List<Map>) current.get("dirs"), currentName)) {
                    List<Map> directories = (List<Map>) current.get("dirs");
                    current = (HashMap<String, Object>) directories.get(getObjByName(directories, currentName));
                } else {
                    HashMap<String, Object> newObj = new HashMap<>();
                    newObj.put("name", currentName);
                    newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
                    newObj.put("files", new ArrayList<HashMap<String, Object>>());
                    List dirsList = (List) current.get("dirs");
                    dirsList.add(newObj);
                }
            }
        }
    }
}

From source file:jp.mamesoft.mailsocketchat.Mail.java

public static void Send(String to, int mode) {
    //mode 0 = ?, 1 = ?, 2 = ?, 3 = ??, 4 = , 5 = 
    System.out.println("???");
    String from = Mailsocketchat.mail_user;
    String host = "smtp.gmail.com";
    String port = "465";
    String text = "";
    String subject = "";
    if (mode == 0) {
        text = logprint(text);//  w ww .j a  v a 2 s .com
        subject = " - MailSocketChat";
        if (Mailsocketchat.newver) {
            text = text + "\n\n??????????\n";
        }
    }
    if (mode == 1) {
        if (Mailsocketchat.subjectname) {
            subject = Mailsocketchat.logs.get(0).get("name");
        } else {
            subject = "?? - MailSocketChat";
        }
        text = logprint(text);
    }
    if (mode == 8) {
        text = logprint(text);
        subject = "?? - MailSocketChat";
    }
    if (mode == 2) {

        if (!Mailsocketchat.push) {
            subject = "????? - MailSocketChat";
            text = "???????????????????\n\n??????\n";
            text = logprint(text);
        } else {
            subject = "??? - MailSocketChat";
            text = "?????????????????\n(???????????)\n\n";
        }
        if (Mailsocketchat.newver) {
            text = text + "\n\n??????????\n";
        }
    }
    if (mode == 3) {

        if (!Mailsocketchat.push && !Mailsocketchat.repeat) {
            subject = "???? - MailSocketChat";
            text = "????\n\n??????\n";
            text = logprint(text);
        } else {
            subject = "?????? - MailSocketChat";
            text = "?????????????????\n\n";
            if (Mailsocketchat.repeat) {
                text = text + "??????\n";
                text = logprint(text);
            }
        }
        if (Mailsocketchat.newver) {
            text = text + "\n\n??????????\n";
        }
    }

    if (mode == 7) {

        if (!Mailsocketchat.repeat) {
            subject = "????? - MailSocketChat";
            text = "?????30????????????\n\n";
            if (!Mailsocketchat.push) {
                text = text + "??????\n";
                text = logprint(text);
            }
        } else {
            subject = "??? - MailSocketChat";
            text = "???\n\n";
        }
        if (Mailsocketchat.newver) {
            text = text + "\n\n??????????\n";
        }
    }

    if (mode == 4) {
        subject = " - MailSocketChat";

        int userint = Mailsocketchat.users.size();
        int romint = Mailsocketchat.roms.size();
        text = ": " + userint + " ROM: " + romint + "\n\n\n";

        for (Integer id : Mailsocketchat.users.keySet()) {
            HashMap<String, String> data = Mailsocketchat.users.get(id);
            text = text + data.get("name") + "\n";
            text = text + " (" + data.get("ip") + ")\n";
        }

        text = text + "\n\nROM\n";
        for (Integer id : Mailsocketchat.roms.keySet()) {
            HashMap<String, String> data = Mailsocketchat.roms.get(id);
            text = text + data.get("ip") + "\n";
        }
        if (Mailsocketchat.newver) {
            text = text + "\n\n??????????\n";
        }
    }
    if (mode == 5) {
        subject = " - MailSocketChat";
        if (Mailsocketchat.push) {
            text = "??: \n\n";
        } else if (Mailsocketchat.repeat) {
            text = "??: \n\n";
        } else {
            text = "??: ?\n\n";
        }
        text = text + "?\n";
        text = text + "?(fetch): ?????\n";
        text = text + "(push): ????\n";
        text = text + "(repeat): ????\n";
        text = text + "(list): ???\n";
        text = text + "#: ?????\n";
        text = text + "#hoge: ??hoge????\n";
        text = text + "(help): ?????\n\n";

        text = text + "\nMailSocketChat Ver." + Mailsocketchat.version + "\n";
        if (Mailsocketchat.newver) {
            text = text + "??????????\n";
        }
    }
    if (mode == 6) {
        subject = "????????? - MailSocketChat";
        text = text
                + "MailSocketChat??????????????????\n";
    }

    // create some properties and get the default Session
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.transport.protocol", "smtps");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);

    Session sendsession = Session.getInstance(props,
            new PlainAuthenticator(Mailsocketchat.mail_user, Mailsocketchat.mail_pass));

    try {
        // create a message
        MimeMessage msg = new MimeMessage(sendsession);
        msg.setFrom(new InternetAddress(from));
        InternetAddress[] sendaddress = { new InternetAddress(to) };
        msg.setRecipients(Message.RecipientType.TO, sendaddress);
        msg.setSubject(subject);
        msg.setSentDate(new Date());
        // If the desired charset is known, you can use
        // setText(text, charset)
        msg.setText(text);

        Transport.send(msg);
        System.out.println("?????");
    } catch (MessagingException mex) {
        System.out.println("??????");
    }
}