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:es.pode.soporte.auditoria.registrar.Registrar.java

/**
 * La operacin realizada es una bsqueda por SQL
 * @param valores/*from w  ww . jav  a  2  s  . c  o m*/
 */
public static void operacionBuscarSQI(DatosVO datosInterceptados) {

    String usuario = null;
    String moduloDestino = datosInterceptados.getModuloDestino();
    HashMap valores = datosInterceptados.getValores();
    String palabrasClave = null;
    String query = (String) valores.get(RegistroCtes.PARAMETRO_QUERY);
    String idiomaBusqueda = ((String) valores.get(RegistroCtes.PARAMETRO_IDIOMA_BUSQUEDA));

    if (RegistroCtes.SQI_LANG.equals(idiomaBusqueda)) {
        log("Parseando query SQL_LANG: " + idiomaBusqueda + " query: " + query);
        palabrasClave = parsearVSQL(query);
    } else if (RegistroCtes.LUCENE_LANG.equals(idiomaBusqueda)) {
        log.warn("No se contempla la bsqueda a travs de Lucene Query Syntax");
        /* Hay que importar las libreras de Lucene. De momento no se hace ya que no hay que dar esta funcionalidad
        QueryParser parser = new QueryParser(props.getProperty("campo_titulo"), new StandardAnalyzer());
        parser.setLowercaseExpandedTerms(true);
        Query lqsQuery = parser.parse(unparsedQuery);
        query.add(lqsQuery);
        */
    }

    if (LdapUserDetailsUtils.estaAutenticado())
        usuario = LdapUserDetailsUtils.getUsuario();

    log("Registro de la bsqueda SQI. PalabrasClave " + palabrasClave + " usuario: " + usuario);

    BusquedaVO parametros = new BusquedaVO();
    parametros.setTerminoBuscado(palabrasClave);
    parametros.setUsuario(usuario);
    parametros.setFecha(Calendar.getInstance());
    parametros.setTipo_busqueda(moduloDestino);
    registrarBusqueda(parametros);
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithoutDetails(HashMap<String, BigDecimal> expenseData)
        throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 1f, 3f };
    expense.setWidths(colWidths);//from w  w  w  . j  av  a  2  s. com

    for (String cat : expenseData.keySet()) {
        Paragraph contentCell1 = new Paragraph(cat);
        PdfPCell cell1 = new PdfPCell(contentCell1);

        Paragraph contentCell2 = new Paragraph(formatter.format(expenseData.get(cat)));
        PdfPCell cell2 = new PdfPCell(contentCell2);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell1.setPaddingBottom(4f);
        cell2.setPaddingBottom(4f);

        expense.addCell(cell1);
        expense.addCell(cell2);
    }

    paragraph.add(expense);
    return paragraph;
}

From source file:com.ibm.mobilefirstplatform.clientsdk.cordovaplugins.core.CDVMFPLogger.java

public static JSONObject HashMapToJSONObject(HashMap<String, LEVEL> pairs) {
    if (pairs == null) {
        return new JSONObject();
    }//from w  w  w.j a va 2s. c o m

    Set<String> set = pairs.keySet();
    JSONObject jsonObj = new JSONObject();
    @SuppressWarnings("rawtypes")
    Iterator it = set.iterator();
    while (it.hasNext()) {
        String n = (String) it.next();
        try {
            jsonObj.put(n, pairs.get(n).toString());
        } catch (JSONException e) {
            // not possible
        }
    }
    return jsonObj;
}

From source file:fshp.FSHP.java

/**
 * Returns the hash of <tt>passwd</tt> 
 *
 * @param passwd Byte representation of clear text password.
 * @param salt Byte representation of salt to be used in hashing.
 * @param saltlen Length of the salt. Should be 0 if a salt is already
 *        provided. If salt is null, saltlen bytes of salt will be
 *        auto generated./*from w w  w.  jav  a2 s . co m*/
 * @param rounds Number of hashing rounds.
 * @param variant FSHP variant indicating the behaviour and/or
 * <ul>
 *        <li><tt>0: SHA-1</tt> <em>(not recommended)</em></li>
 *        <li><tt>1: SHA-256</tt></li>
 *        <li><tt>2: SHA-384</tt></li>
 *        <li><tt>3: SHA-512</tt></li>
 * </ul>
 *
 * @return       FSHP hash of <tt>passwd</tt>
 */
public static String crypt(byte[] passwd, byte[] salt, int saltlen, int rounds, int variant) throws Exception {
    // Ensure we have sane values for salt length and rounds.
    if (saltlen < 0)
        saltlen = 0;
    if (rounds < 1)
        rounds = 1;

    if (salt == null) {
        salt = new byte[saltlen];
        new SecureRandom().nextBytes(salt);
    } else
        saltlen = salt.length;

    HashMap<Integer, String> algoMap = new HashMap<Integer, String>();
    algoMap.put(0, "SHA-1");
    algoMap.put(1, "SHA-256");
    algoMap.put(2, "SHA-384");
    algoMap.put(3, "SHA-512");

    MessageDigest md;
    try {
        if (!algoMap.containsKey(variant))
            throw new NoSuchAlgorithmException();

        md = MessageDigest.getInstance(algoMap.get(variant));
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("Unsupported FSHP variant " + variant);
    }

    md.update(salt);
    md.update(passwd);
    byte[] digest = md.digest();

    for (int i = 1; i < rounds; i++) {
        md.reset();
        md.update(digest);
        digest = md.digest();
    }

    String meta = "{FSHP" + variant + "|" + saltlen + "|" + rounds + "}";

    byte[] saltdigest = new byte[salt.length + digest.length];
    System.arraycopy(salt, 0, saltdigest, 0, salt.length);
    System.arraycopy(digest, 0, saltdigest, salt.length, digest.length);

    byte[] b64saltdigest = Base64.encodeBase64(saltdigest);

    return meta + new String(b64saltdigest, "US-ASCII");
}

From source file:com.mycsense.carbondb.domain.SourceRelation.java

public static HashMap<String, ArrayList<Dimension>> createGroupHashTable(Group group, Dimension commonKeywords,
        Integer alpha) {/*  w  w w  . j a  va  2  s .co m*/
    HashMap<String, ArrayList<Dimension>> elements = new HashMap<>();
    for (Dimension element : group.getCoordinates().dimensions) {
        String hashKey = getHashKey(element, commonKeywords, alpha);
        if (!hashKey.equals("#nullHashKey#")) {
            if (!elements.containsKey(hashKey)) {
                elements.put(hashKey, new ArrayList<Dimension>());
            }
            elements.get(hashKey).add(element);
        }
    }
    return elements;
}

From source file:de.fu_berlin.inf.dpp.misc.pico.DotGraphMonitor.java

public static String getColorOld(Class<?> clazz, HashMap<String, String> colors) {
    String name;// w w w  .j ava2 s. co m
    Package myPackage = clazz.getPackage();
    if (myPackage == null) {
        name = "misc";
    } else {
        name = myPackage.getName();
    }

    while (name != null && name.length() > 0) {

        String color = colors.get(name);
        if (color != null) {
            return "  \"" + clazz.getSimpleName() + "\" [color=" + color + "];\n";
        }

        int index = name.lastIndexOf('.');
        if (index == -1)
            break;

        name = name.substring(0, index);
    }

    return null;
}

From source file:edu.usc.squash.Main.java

private static HashMap<String, Module> parseQASMHF(Library library) {
    HFQParser hfqParser = null;/*from  w w  w.ja v  a 2 s .com*/
    /*
     * Pass 1: Getting module info
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> moduleMap = hfqParser.parse(library, true, null);

    /* 
     * In order traversal of modules
     */

    ArrayList<CalledModule> modulesList = new ArrayList<CalledModule>();
    modulesList.add(new CalledModule(moduleMap.get("main"), new ArrayList<String>()));
    while (!modulesList.isEmpty()) {
        Module module = modulesList.get(0).getModule();

        if (!module.isVisited()) {
            module.setVisited();

            ArrayList<CalledModule> calledModules = module.getChildModules();
            modulesList.addAll(calledModules);
            for (CalledModule calledModule : calledModules) {
                Module childModule = calledModule.getModule();
                for (int i = 0; i < calledModule.getOps().size(); i++) {
                    Operand operand = childModule.getOperand(i);
                    if (operand.isArray() && operand.getLength() == -1) {
                        operand.setLength(module.getOperandLength(calledModule.getOps().get(i)));
                    }
                }
            }
        }
        modulesList.remove(0);
    }

    /*
     * Pass 2: Making hierarchical QMDG
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> modules = hfqParser.parse(library, false, moduleMap);

    return modules;
}

From source file:edu.harvard.liblab.ecru.LoadCsvData.java

/**
 * @param rec        A HashMap containing the values for the Course record
 * @param sdoc       The record from the solr db, if it already exists
 * @throws Exception/*from w  ww .j av  a2s  . c om*/
 * 
 * A Course has to, minimally, have an id, name, term, start and end date. 
 * This version of the loader assumes that, if the course already exists in
 * the database, its data is being completely replaced by the incoming data,
 * with the exception that the "has_readings" value is preserved.
 * 
 * If the Course is new, this method will check for Readings which have the
 * reading.course_id equal to the Course's id, and will set the has_readings 
 * accordingly
 * 
 * If the Display field is empty, it will be constructed from the name and 
 * the first instructor in the instructor field (if it exists) as
 *   {name} ({instructor} )
 * 
 */
private static void processCourse(HashMap<String, String> rec, SolrDocument sdoc) throws Exception {
    String name = rec.get("Name");
    String term = rec.get("Term");
    String startDateStr = rec.get("Start Date");
    String endDateStr = rec.get("End Date");
    String errMsg = "";
    Date startDate = null;
    Date endDate = null;
    try {
        startDate = SIMPLE_DATE.parse(startDateStr);
        endDate = SIMPLE_DATE.parse(endDateStr);
    } catch (ParseException e) {
        errMsg = "bad start and/or end date";
    }
    if (term.isEmpty()) {
        errMsg += " missing Term";
    }
    if (name.isEmpty()) {
        errMsg += " missing name";
    }
    if (errMsg.isEmpty()) {
        String display = rec.get("Display");
        String[] insts = rec.get("Instructor").split(";");
        for (int i = 0; i < insts.length; i++) {
            insts[i] = insts[i].trim();
        }
        if (display.isEmpty()) {
            display = name;
            if (insts.length > 0) {
                display += " (" + insts[0] + ")";
            }
        }
        String id = rec.get("ID");
        if (needsPrefix) {
            id = "c_" + id;
        }
        String div = rec.get("Division");
        String catNo = rec.get("CatNo");
        String url = rec.get("URL");
        Course c = new Course(id, display, catNo, endDate, div, Arrays.asList(insts), name, startDate, term,
                url);
        c.setUpdateTimestamp(new Date());
        boolean hasReadings = false;
        if (sdoc != null) {
            if (sdoc.get("course.has_readings") != null) {
                hasReadings = ((Boolean) sdoc.get("course.has_readings")).equals(Boolean.TRUE);
            }
            if (!sdoc.get("term").equals(term) || !sdoc.get("start_date").equals(startDate)
                    || !sdoc.get("end_date").equals(endDate)) {
                updateReadingsTermDates(id, term, startDate, endDate);
            }
        } else {
            if (!hasReadings) {
                // make sure that readings weren't added BEFORE this course!!
                hasReadings = hasReadings(id);
            }

        }
        c.setReadings(hasReadings);
        beans.add(c);
    } else {
        throw new Exception("Course record " + errMsg);
    }

}

From source file:cloudworker.RemoteWorker.java

public static int getQueueSize(AmazonSQS sqs, String queueUrl) {
    HashMap<String, String> attributes;

    Collection<String> attributeNames = new ArrayList<String>();
    attributeNames.add("ApproximateNumberOfMessages");

    GetQueueAttributesRequest getAttributesRequest = new GetQueueAttributesRequest(queueUrl)
            .withAttributeNames(attributeNames);
    attributes = (HashMap<String, String>) sqs.getQueueAttributes(getAttributesRequest).getAttributes();

    return Integer.valueOf(attributes.get("ApproximateNumberOfMessages"));
}

From source file:br.gov.jfrj.siga.base.ConexaoHTTP.java

public static String get(String URL, HashMap<String, String> header, Integer timeout, String payload)
        throws AplicacaoException {

    try {//from  w w  w  . j a va 2s .c o  m

        HttpURLConnection conn = (HttpURLConnection) new URL(URL).openConnection();

        if (timeout != null) {
            conn.setConnectTimeout(timeout);
            conn.setReadTimeout(timeout);
        }

        //conn.setInstanceFollowRedirects(true);

        if (header != null) {
            for (String s : header.keySet()) {
                conn.setRequestProperty(s, header.get(s));
            }
        }

        System.setProperty("http.keepAlive", "false");

        if (payload != null) {
            byte ab[] = payload.getBytes("UTF-8");
            conn.setRequestMethod("POST");
            // Send post request
            conn.setDoOutput(true);
            OutputStream os = conn.getOutputStream();
            os.write(ab);
            os.flush();
            os.close();
        }

        //StringWriter writer = new StringWriter();
        //IOUtils.copy(conn.getInputStream(), writer, "UTF-8");
        //return writer.toString();
        return IOUtils.toString(conn.getInputStream(), "UTF-8");

    } catch (IOException ioe) {
        throw new AplicacaoException("No foi possvel abrir conexo", 1, ioe);
    }

}