Example usage for java.util Hashtable get

List of usage examples for java.util Hashtable get

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized 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.globalsight.util.file.XliffFileUtil.java

/**
 * Handle a list of files to verify if they are Xliff files and for each
 * file, 1.If it is single Xliff file with only one <File> tags, need not
 * process 2.If it is Xliff file with multiple <File> tags, it needs to be
 * separated into single Xliff files with content in each <File> tags. All
 * separated files will have the same header and footer as original file.
 * 3.If it is XLZ file, then unpack the file first and process each Xliff in
 * the package with step #2.//from   w w w . j  a  v a2  s.c o m
 * 
 * @param p_fileList
 *            A list of original uploaded or selected files and their
 *            corresponding file profile
 * @return java.util.Hashtable<String, FileProfile> List of files that are
 *         processed.
 * 
 * @version 1.0
 * @since 8.2.2
 */
public static Hashtable<String, FileProfile> processXliffFiles(Hashtable<String, FileProfile> p_fileList) {
    Hashtable<String, FileProfile> files = new Hashtable<String, FileProfile>();
    if (p_fileList == null || p_fileList.size() == 0)
        return files;

    String filename = "";
    FileProfile fp = null;
    try {
        Iterator<String> fileKeys = p_fileList.keySet().iterator();

        while (fileKeys.hasNext()) {
            filename = fileKeys.next();
            fp = p_fileList.get(filename);

            switch ((int) fp.getKnownFormatTypeId()) {
            case KNOWN_FILE_FORMAT_XLIFF:
                processMultipleFileTags(files, filename, fp);
                break;
            case KNOWN_FILE_FORMAT_XLZ:
                separateXlzFile(files, filename, fp);
                break;
            default:
                files.put(filename, fp);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return files;
}

From source file:com.seer.datacruncher.profiler.spring.MiscController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();
    String action = CommonUtil.notNullValue(request.getParameter("action"));

    if (action.equals("validateCondition") || action.equals("applyCondition")) {
        String table = CommonUtil.notNullValue(request.getParameter("table"));
        String columnNames = CommonUtil.notNullValue(request.getParameter("columnNames"));
        String columnType = CommonUtil.notNullValue(request.getParameter("columnTypes"));
        String condition = CommonUtil.notNullValue(request.getParameter("condition"));
        String conditionValue = CommonUtil.notNullValue(request.getParameter("conditionValue"));
        String conditionType = CommonUtil.notNullValue(request.getParameter("conditionType"));
        String indexValue = CommonUtil.notNullValue(request.getParameter("index"));
        MiscBL mbl = new MiscBL(1, table, (Integer.parseInt(indexValue) - 1));

        mbl.initMiscBL(columnNames, conditionType, conditionValue, columnType, condition);

        if (action.equals("validateCondition")) {
            String status = mbl.validateCondtion();
            if (status != null) {
                out.print("{success: true, count: \"" + status + "\" , conditionQuery:\"" + mbl.cond + "\"}");
            } else {
                out.println("{\"success\": false}");
            }/*from w ww  .  ja  va  2  s .  c o  m*/
        } else {
            @SuppressWarnings("unchecked")
            Hashtable<String, String> dbParams = (Hashtable<String, String>) request.getSession(true)
                    .getAttribute("dbConnectionData");
            if (dbParams != null) {
                request.setAttribute("serverName", CommonUtil.notNullValue(dbParams.get("Database_DSN")));
            }
            String selectedValue = CommonUtil.notNullValue(request.getParameter("table"));
            request.setAttribute("selectedValue", selectedValue);
            TableGridDTO tgDTO = mbl.applyCondition();
            GridUtil gridUtil = new GridUtil();
            gridUtil.generateGridData(tgDTO, false, null);
            request.setAttribute("gridColumns", gridUtil.getColumnNames());
            request.setAttribute("gridFields", gridUtil.getFieldNames());
            request.setAttribute("gridData", gridUtil.getData());

            request.setAttribute("rowCount", tgDTO.getRowValues().size());

            return new ModelAndView("jsp/profiler/info.jsp");
        }
    }
    return null;

}

From source file:com.fiorano.openesb.application.common.Param.java

public void populate(FioranoStaxParser parser) throws XMLStreamException {
    if (parser.markCursor(APSConstants.PARAM)) {
        // Get Attributes if needs to accessed later. This MUST be done before accessing any data of element.
        Hashtable attributes = parser.getAttributes();
        String name = (String) attributes.get(APSConstants.PARAM_NAME);// parser.getAttributeValue(null, "name");

        setParamName(name);/*from w ww .jav a 2 s . com*/

        String value = parser.getText();

        setParamValue(value);
    }
}

From source file:com.talkdesk.geo.GeoCodeResolver.java

/**
 * Get the minimum distance/*from  ww w.  j a  va2s .  c  o  m*/
 * @param numberList
 * @return
 * @throws GeoResolverException
 */
public String getClosestNumber(Hashtable<String, Double> numberList) throws GeoResolverException {
    String closest = "";
    Double lowestDistance = Double.MAX_VALUE;

    for (String key : numberList.keySet()) {
        Double currentDistance = numberList.get(key);
        if (currentDistance < lowestDistance) {
            lowestDistance = currentDistance;
            closest = key;
        }
    }
    return !closest.isEmpty() ? getTownFromNumber(closest) + " - " + closest : null;
}

From source file:algorithm.ZipPackagingTest.java

@Test
public void zipPackagingTest() {
    try {/*w w w.j a v  a2s.  c o m*/
        File carrier = TestDataProvider.TXT_FILE;
        File payload1 = TestDataProvider.TXT_FILE_2;
        File payload2 = TestDataProvider.XML_FILE;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        ZipPackaging algorithm = new ZipPackaging();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(3, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload1 = outputHash.get(payload1.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload1);
        assertNotNull(restoredPayload2);
        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        // (algorithm doesn't save original file paths)
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        // every file in a zip package is payload!:
        assertTrue(restoredCarrier.wasPayload);
        assertFalse(restoredCarrier.wasCarrier);
        assertTrue(restoredPayload1.wasPayload);
        assertFalse(restoredPayload1.wasCarrier);
        assertTrue(restoredPayload2.wasPayload);
        assertFalse(restoredPayload2.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1));
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:hu.sztaki.lpds.portal.util.stream.HttpClient.java

/**
 * Getting the stream// ww w  . ja v  a 2  s.c o m
 * @param pValue list of the parameters used during the connection
 * @return  datastream
 * @throws java.io.IOException communication error
 */
public InputStream getStream(Hashtable<String, String> pValue) throws IOException {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    Enumeration<String> enm = pValue.keys();
    String key;
    while (enm.hasMoreElements()) {
        key = enm.nextElement();
        nvps.add(new BasicNameValuePair(key, pValue.get(key)));
    }
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity entity = response.getEntity();
    return entity.getContent();
}

From source file:algorithm.BagItPackagingTest.java

@Test
public void bagItPackagingTest() {
    try {/* www  .j  a  v  a 2s . c  o m*/
        File carrier = TestDataProvider.TXT_FILE;
        File payload1 = TestDataProvider.TXT_FILE_2;
        File payload2 = TestDataProvider.XML_FILE;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);
        BagItPackaging algorithm = new BagItPackaging();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        assertTrue(outputFile.length() > carrier.length());

        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(3, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload1 = outputHash.get(payload1.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload1);
        assertNotNull(restoredPayload2);

        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        // (original file paths are not stored with BagIt)
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        assertTrue(restoredPayload1.wasPayload);
        assertFalse(restoredPayload1.wasCarrier);
        assertTrue(restoredPayload2.wasPayload);
        assertFalse(restoredPayload2.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1));
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:algorithm.PNGChunkAddingTest.java

@Test
public void pngMultipleChunkAddingTest() {
    try {/*from w w  w.  ja  va 2 s.c  om*/
        File carrier = TestDataProvider.PNG_FILE;
        File payload = TestDataProvider.TXT_FILE;
        File payload2 = TestDataProvider.TXT_FILE_2;

        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        payloadList.add(payload2);

        PNGChunkAdding algorithm = new PNGChunkAdding();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);

        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(3, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        assertNotNull(restoredPayload2);
        // TODO: The carrier checksum is not valid, because the PNG library
        // reorders the chunks! We would have to use a different library.
        // assertEquals(FileUtils.checksumCRC32(carrier),
        // FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath);
        assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath);
        assertEquals(algorithm, restoredCarrier.algorithm);
        // can't be true for this algorithm:
        // assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload.checksumValid);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        assertTrue(restoredPayload.wasPayload);
        assertFalse(restoredPayload.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier));
        assertFalse(restoredPayload.relatedFiles.contains(restoredPayload));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:algorithm.TxtInformationFrameTest.java

@Test
public void textInformationFrameAlgorithmTest() {
    try {// ww w.  j a v  a2s. c om
        File carrier = TestDataProvider.TXT_FILE;
        File payload1 = TestDataProvider.TXT_FILE_2;
        File payload2 = TestDataProvider.XML_FILE;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        TextInformationFrame algorithm = new TextInformationFrame();
        // Test encapsulation:
        File outputFile = algorithm.encapsulate(carrier, payloadList);
        assertNotNull(outputFile);
        assertTrue(outputFile.length() > carrier.length());
        // Test restore:
        Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>();
        for (RestoredFile file : algorithm.restore(outputFile)) {
            outputHash.put(file.getName(), file);
        }
        assertEquals(3, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload1 = outputHash.get(payload1.getName());
        RestoredFile restoredPayload2 = outputHash.get(payload2.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload1);
        assertNotNull(restoredPayload2);
        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload1), FileUtils.checksumCRC32(restoredPayload1));
        assertEquals(FileUtils.checksumCRC32(payload2), FileUtils.checksumCRC32(restoredPayload2));

        // check restoration metadata:
        assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath);
        assertEquals("" + payload1.getAbsolutePath(), restoredPayload1.originalFilePath);
        assertEquals("" + payload2.getAbsolutePath(), restoredPayload2.originalFilePath);
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        assertTrue(restoredCarrier.wasCarrier);
        assertFalse(restoredCarrier.wasPayload);
        assertTrue(restoredPayload1.wasPayload);
        assertFalse(restoredPayload1.wasCarrier);
        assertTrue(restoredPayload2.wasPayload);
        assertFalse(restoredPayload2.wasCarrier);
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload1));
        assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredCarrier));
        assertTrue(restoredPayload1.relatedFiles.contains(restoredPayload2));
        assertFalse(restoredPayload1.relatedFiles.contains(restoredPayload1));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ch.rgw.tools.StringTool.java

@SuppressWarnings("unchecked")
public static void dumpHashtable(final Log log, final Hashtable table) {
    Set<String> keys = table.keySet();
    log.log("Dump Hashtable\n", Log.INFOS);
    for (String key : keys) {
        log.log(key + ": " + table.get(key).toString(), Log.INFOS);
    }/*w  ww  .j av a2  s.  c o  m*/
    log.log("End dump\n", Log.INFOS);
}