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:algorithm.TarPackagingTest.java

@Test
public void singleTarPackagingTest() {
    try {/*from  w  w  w.  j  a  v a  2s . co  m*/
        File carrier = TestDataProvider.TXT_FILE;
        File payload = TestDataProvider.XML_FILE;
        TarPackaging algorithm = new TarPackaging();
        // Test encapsulation:
        List<File> carrierList = new ArrayList<File>();
        carrierList.add(carrier);
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        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(2, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        assertEquals(FileUtils.checksumCRC32(carrier), FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));

        // check restoration metadata:
        // assertEquals("" + carrier.getAbsolutePath(),
        // restoredCarrier.originalFilePath);
        // assertEquals("" + payload.getAbsolutePath(),
        // restoredPayload.originalFilePath);
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload.checksumValid);
        // Every file in a .tar archive is a payload file!
        assertTrue(restoredCarrier.wasPayload);
        assertFalse(restoredCarrier.wasCarrier);
        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:org.nees.rpi.vis.ui.XYChartPanelProxy.java

private String processLabelfromUnits(Hashtable<String, Integer> h, String defaultLabel) {
    String axisLabel = "";

    ArrayList<String> units = new ArrayList<String>();
    for (String key : h.keySet())
        if (h.get(key) > 0)
            units.add(key);/*from w w w  .  j av  a  2s .co m*/

    for (String s : units)
        axisLabel += s + ", ";

    if (axisLabel.length() == 0)
        axisLabel = defaultLabel;
    else
        axisLabel = axisLabel.substring(0, axisLabel.length() - 2);

    return axisLabel;
}

From source file:algorithm.PDFFileAttacherTest.java

@Test
public void pdfSingleFileAttacherTest() {
    try {//from w w  w  . ja  v a 2  s.  c  o m
        File carrier = TestDataProvider.PDF_FILE;
        File payload = TestDataProvider.TXT_FILE;
        PDFFileAttacher algorithm = new PDFFileAttacher();
        // Test encapsulation:
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload);
        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(2, outputHash.size());
        RestoredFile restoredCarrier = outputHash.get(carrier.getName());
        RestoredFile restoredPayload = outputHash.get(payload.getName());
        assertNotNull(restoredCarrier);
        assertNotNull(restoredPayload);
        /*
         * TODO: as long as I can see, it is at the moment not possible to
         * remove the attached file with pdf box, so we can't restore the
         * carrier. We would have to use a different pdf library to solve
         * this.
         */
        // assertEquals(FileUtils.checksumCRC32(carrier),
        // FileUtils.checksumCRC32(restoredCarrier));
        assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload));

        // check restoration metadata:
        // (This algorithm doesn't save original file paths, as it doesn't
        // use the payload segment)
        assertEquals(algorithm, restoredCarrier.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.PDFFileAttacherTest.java

@Test
public void pdfMultipleFileAttacherTest() {
    try {//from   www  .j  av  a 2  s  .  co  m
        File carrier = TestDataProvider.PDF_FILE;
        File payload1 = TestDataProvider.TXT_FILE;
        File payload2 = TestDataProvider.TXT_FILE_2;
        List<File> payloadList = new ArrayList<File>();
        payloadList.add(payload1);
        payloadList.add(payload2);

        PDFFileAttacher algorithm = new PDFFileAttacher();
        // 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(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.TarPackagingTest.java

@Test
public void multipleTarPackagingTest() {
    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);

        TarPackaging algorithm = new TarPackaging();
        // 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 and checksums, as it
        // doesn't use the payload segment and restoration metadata)
        assertEquals(algorithm, restoredCarrier.algorithm);
        assertTrue(restoredCarrier.checksumValid);
        assertTrue(restoredPayload1.checksumValid);
        assertTrue(restoredPayload2.checksumValid);
        // Every file in a .tar archive is a payload file!
        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:org.alfresco.filesys.NfsServerNodeMonitor.java

/**
 * Searches for {@link ShareDetails} to access NFS server cache for specific device name (e.g. 'Alfresco', etc)
 * /*from w  w  w  .j av a2  s.  com*/
 * @param fileId - {@link Integer} value which contains <code>fileId</code> specific to device
 * @return {@link ShareDetails} instance which contains <code>fileId</code> key in the cache or <code>null</code> if such instance was not found
 */
private ShareDetails findShareDetailsForId(int fileId) {
    if ((null == nfsServer) || (null == nfsServer.getShareDetails())) {
        return null;
    }

    Hashtable<Integer, ShareDetails> details = nfsServer.getShareDetails().getShareDetails();
    for (Integer key : details.keySet()) {
        ShareDetails shareDetails = details.get(key);
        if (null != shareDetails.getFileIdCache().findPath(fileId)) {
            return shareDetails;
        }
    }

    return null;
}

From source file:com.globalsight.everest.webapp.pagehandler.projects.workflows.JobControlInProgressHandler.java

/**
 * Invokes this EntryPageHandler object/*from   w w  w .ja  v a  2  s .c om*/
 * <p>
 * 
 * @param p_ageDescriptor
 *            the description of the page to be produced.
 * @param p_request
 *            original request sent from the browser.
 * @param p_response
 *            original response object.
 * @param p_context
 *            the Servlet context.
 */
public void myInvokePageHandler(WebPageDescriptor p_thePageDescriptor, HttpServletRequest p_request,
        HttpServletResponse p_response, ServletContext p_context)
        throws ServletException, IOException, RemoteException, EnvoyServletException {
    HttpSession session = p_request.getSession(false);
    SessionManager sessionMgr = (SessionManager) session.getAttribute(SESSION_MANAGER);
    boolean stateMarch = false;
    if (Job.DISPATCHED.equals((String) sessionMgr.getMyjobsAttribute("lastState")))
        stateMarch = true;
    String action = p_request.getParameter(ACTION_STRING);
    if (StringUtil.isNotEmpty(action) && "removeJobFromGroup".equals(action)) {
        removeJobFromGroup(p_request);
    }
    setJobSearchFilters(sessionMgr, p_request, stateMarch);

    HashMap beanMap = invokeJobControlPage(p_thePageDescriptor, p_request, BASE_BEAN);
    p_request.setAttribute("searchType", p_request.getParameter("searchType"));

    // since an instance of a page handler is used by different clients,
    // this instance variable needs to be set only once. There's no need
    // to synchronize this section as the value of export url is always the
    // same.
    if (m_exportUrl == null) {
        m_exportUrl = ((NavigationBean) beanMap.get(EXPORT_BEAN)).getPageURL();
    }

    if (p_request.getParameter("checkIsUploadingForExport") != null) {
        long jobId = Long.parseLong(p_request.getParameter("jobId"));
        Job job = WorkflowHandlerHelper.getJobById(jobId);
        String result = "";
        for (Workflow workflow : job.getWorkflows()) {
            if (result.length() > 0)
                break;
            Hashtable<Long, Task> tasks = workflow.getTasks();
            for (Long taskKey : tasks.keySet()) {
                if (tasks.get(taskKey).getIsUploading() == 'Y') {
                    result = "uploading";
                    break;
                }
            }
        }
        PrintWriter out = p_response.getWriter();
        p_response.setContentType("text/html");
        out.write(result);
        out.close();
        return;
    } else if (p_request.getParameter("action") != null
            && "checkDownloadQAReport".equals(p_request.getParameter("action"))) {
        ServletOutputStream out = p_response.getOutputStream();
        String jobIds = p_request.getParameter("jobIds");
        boolean checkQA = checkQAReport(sessionMgr, jobIds);
        String download = "";
        if (checkQA) {
            download = "success";
        } else {
            download = "fail";
        }
        Map<String, Object> returnValue = new HashMap();
        returnValue.put("download", download);
        out.write((JsonUtil.toObjectJson(returnValue)).getBytes("UTF-8"));
        return;
    } else if (p_request.getParameter("action") != null
            && "downloadQAReport".equals(p_request.getParameter("action"))) {
        Set<Long> jobIdSet = (Set<Long>) sessionMgr.getAttribute("jobIdSet");
        Set<File> exportFilesSet = (Set<File>) sessionMgr.getAttribute("exportFilesSet");
        Set<String> localesSet = (Set<String>) sessionMgr.getAttribute("localesSet");
        long companyId = (Long) sessionMgr.getAttribute("companyId");
        WorkflowHandlerHelper.zippedFolder(p_request, p_response, companyId, jobIdSet, exportFilesSet,
                localesSet);
        sessionMgr.removeElement("jobIdSet");
        sessionMgr.removeElement("exportFilesSet");
        sessionMgr.removeElement("localesSet");
        return;
    }

    performAppropriateOperation(p_request);

    sessionMgr.setMyjobsAttribute("lastState", Job.DISPATCHED);
    JobVoInProgressSearcher searcher = new JobVoInProgressSearcher();
    searcher.setJobVos(p_request, true);
    p_request.setAttribute(EXPORT_URL_PARAM, m_exportUrl);
    p_request.setAttribute(JOB_ID, JOB_ID);
    p_request.setAttribute(JOB_LIST_START_PARAM, p_request.getParameter(JOB_LIST_START_PARAM));
    p_request.setAttribute(PAGING_SCRIPTLET,
            getPagingText(p_request, ((NavigationBean) beanMap.get(BASE_BEAN)).getPageURL(), Job.DISPATCHED));
    try {
        Company company = ServerProxy.getJobHandler()
                .getCompanyById(CompanyWrapper.getCurrentCompanyIdAsLong());
        p_request.setAttribute("company", company);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Set the EXPORT_INIT_PARAM in the sessionMgr so we can bring
    // the user back here after they Export
    sessionMgr.setAttribute(JobManagementHandler.EXPORT_INIT_PARAM, BASE_BEAN);
    sessionMgr.setAttribute("destinationPage", "inprogress");
    // clear the session for download job from joblist page
    sessionMgr.setAttribute(DownloadFileHandler.DOWNLOAD_JOB_LOCALES, null);
    sessionMgr.setAttribute(DownloadFileHandler.DESKTOP_FOLDER, null);
    setJobProjectsLocales(sessionMgr, session);

    // turn on cache. do both. "pragma" for the older browsers.
    p_response.setHeader("Pragma", "yes-cache"); // HTTP 1.0
    p_response.setHeader("Cache-Control", "yes-cache"); // HTTP 1.1
    p_response.addHeader("Cache-Control", "yes-store"); // tell proxy not to
                                                        // cache
                                                        // forward to the jsp page.
    RequestDispatcher dispatcher = p_context.getRequestDispatcher(p_thePageDescriptor.getJspURL());
    dispatcher.forward(p_request, p_response);
}

From source file:net.aepik.alasca.core.ldap.Schema.java

/**
 * Get sorted object identifiers keys, to loop on object identifiers
 * into a valid order.//from w w  w  . jav  a2 s.c  o  m
 * @param oids Object identifiers.
 * @return String[] Sorted keys
 */
public static String[] getSortedObjectsIdentifiersKeys(Properties oids) {
    Hashtable<String, String> ht = new Hashtable<String, String>();
    for (Enumeration keys = oids.propertyNames(); keys.hasMoreElements();) {
        String k = (String) keys.nextElement();
        Oid o = new Oid(oids.getProperty(k));
        String v = o.toString();
        String p = o.getPrefix();
        while (p != null) {
            v = v.replaceFirst(p + ":", oids.getProperty(p) + ".");
            p = (new Oid(oids.getProperty(p))).getPrefix();
        }
        ht.put(v, k);
    }
    String[] st = ht.keySet().toArray(new String[0]);
    Arrays.sort(st);
    String[] result = new String[st.length];
    int result_index = 0;
    for (String k : st) {
        result[result_index] = ht.get(k);
        result_index++;
    }
    return result;
}

From source file:autohit.vm.VMLoader.java

/**
 * Create a core./*from ww  w .jav a 2  s.c o  m*/
 */
public VMCore create() {

    // create it
    VMCore core = corefactory.allocate();

    // mirror all the invoker props
    Hashtable iprop = sc.getInvokerProperties();
    String ikey;
    Object ivalue;
    for (Enumeration e = iprop.keys(); e.hasMoreElements();) {

        try {
            ikey = (String) e.nextElement();
            ivalue = iprop.get(ikey);
            core.store(ikey, ivalue);
        } catch (Exception ecc) {
            // ignore and just disqualify that entry
        }
    }

    return core;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java

/**
 * Save the request parameters from the Custom Fields page
 */// w w w  . j  av  a2 s  .c om
public static void saveCustom(Vendor vendor, HttpServletRequest request, SessionManager sessionMgr) {
    FieldSecurity fs = (FieldSecurity) sessionMgr.getAttribute(VendorConstants.FIELD_SECURITY_CHECK_PROJS);
    if (fs != null) {
        String access = fs.get(VendorSecureFields.CUSTOM_FIELDS);
        if ("hidden".equals(access) || "locked".equals(access)) {
            return;
        }
    }
    Hashtable fields = vendor.getCustomFields();
    if (fields == null) {
        fields = new Hashtable();
    }
    ArrayList list = CustomPageHelper.getCustomFieldNames();
    for (int i = 0; i < list.size(); i++) {
        String key = (String) list.get(i);
        String value = (String) request.getParameter(key);
        if (value == null) {
            fields.remove(key);
        } else {
            // if already in the list
            CustomField cf = (CustomField) fields.get(key);
            if (cf != null) {
                cf.setValue(value);
            } else {
                cf = new CustomField(key, value);
            }
            fields.put(key, cf);

        }
    }
    vendor.setCustomFields(fields);
}