List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java
private BoxAndWhiskerCategoryDataset addDataSet(Hashtable<String, List> info) { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (String key : info.keySet()) { System.out.println(key + ":" + info.get(key).size()); String[] keyData = key.split(Pattern.quote("+")); dataset.add(info.get(key), keyData[1], getTechniqueName(keyData[0])); }/*from ww w . jav a2 s .c o m*/ //System.out.println("dataset" + dataset); return dataset; }
From source file:com.hybris.mobile.adapter.FormAdapter.java
@SuppressWarnings("unchecked") private Boolean fieldIsValid(int index) { Boolean isRequired = false;// www . j a va 2 s . c o m Boolean hasValidation = false; Hashtable<String, Object> obj = (Hashtable<String, Object>) objects.get(index); hasValidation = obj.containsKey("validation"); if (obj.containsKey("required")) { isRequired = Boolean.parseBoolean(obj.get("required").toString()); } String value = ""; if (obj.containsKey("value")) { value = obj.get("value").toString(); } if ((obj.get("cellIdentifier").toString().equalsIgnoreCase("HYFormTextEntryCell")) || (obj.get("cellIdentifier").toString().equalsIgnoreCase("HYFormSecureTextEntryCell"))) { if ((value.length() > 0) && hasValidation) { Pattern pattern = Pattern.compile(obj.get("validation").toString()); Matcher matcher = pattern.matcher(value); Boolean show = matcher.matches(); obj.put("showerror", !show); return show; } else { obj.put("showerror", isRequired); return !isRequired; } } else if ((obj.get("cellIdentifier").toString().equalsIgnoreCase("HYFormTextSelectionCell"))) { if (value.length() > 0) { return true; } else return false; } return true; }
From source file:com.alfaariss.oa.profile.aselect.binding.protocol.cgi.CGIRequest.java
/** * Creates the CGI request object.//from w w w.j ava2 s .c o m * * Reads the request parameters and puts them in a <code>Hashtable</code> * @param oRequest the servlet request * @throws BindingException if the request object can't be created */ public CGIRequest(HttpServletRequest oRequest) throws BindingException { try { _logger = LogFactory.getLog(CGIRequest.class); _htRequest = new Hashtable<String, Object>(); _sRequestedURL = oRequest.getRequestURL().toString(); if (_logger.isDebugEnabled()) { String sQueryString = oRequest.getQueryString(); if (sQueryString == null) sQueryString = ""; _logger.debug("QueryString: " + sQueryString); } Hashtable<String, Vector<String>> htVectorItems = new Hashtable<String, Vector<String>>(); Enumeration enumNames = oRequest.getParameterNames(); while (enumNames.hasMoreElements()) { String sName = (String) enumNames.nextElement(); String sValue = oRequest.getParameter(sName); if (sName.endsWith(CGIBinding.ENCODED_BRACES) || sName.endsWith(CGIBinding.ENCODED_BRACES.toLowerCase()) || sName.endsWith("[]")) { Vector<String> vValues = htVectorItems.get(sName); if (vValues == null) vValues = new Vector<String>(); vValues.add(sValue); htVectorItems.put(sName, vValues); } else _htRequest.put(sName, sValue); } _htRequest.putAll(htVectorItems); } catch (Exception e) { _logger.fatal("Internal error during CGI Request creation", e); throw new BindingException(SystemErrors.ERROR_INTERNAL); } }
From source file:com.mobilefirst.fiberlink.WebServiceRequest.java
/** * formulateGetURI method formulates the get request URI * @param URI: uri to be formulated//from w ww . ja v a2 s .c om * @param params: uri to be formulated using params * @return returns the formulated uri * @throws Exception */ public String formulateGetURI(String URI, Hashtable<String, String> params) throws Exception { String newURI = null; String postURI = "?"; try { Enumeration<String> keys = params.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); postURI = postURI + key + "=" + params.get(key) + "&"; } postURI = (String) postURI.subSequence(0, postURI.length() - 1); newURI = URI + postURI.replaceAll(" ", "%20"); //TODO - Further URL Encoding } catch (Exception e) { throw new Exception(e); } return newURI; }
From source file:libra.common.kmermatch.KmerMatchInputFormat.java
public List<InputSplit> getSplits(JobContext job) throws IOException { KmerMatchInputFormatConfig inputFormatConfig = KmerMatchInputFormatConfig .createInstance(job.getConfiguration()); // generate splits List<InputSplit> splits = new ArrayList<InputSplit>(); List<FileStatus> files = listStatus(job); List<Path> kmerIndexFiles = new ArrayList<Path>(); for (FileStatus file : files) { Path path = file.getPath(); kmerIndexFiles.add(path);// w w w. j a va 2s . c o m } LOG.info("# of Split input file : " + kmerIndexFiles.size()); for (int i = 0; i < kmerIndexFiles.size(); i++) { LOG.info("> " + kmerIndexFiles.get(i).toString()); } Path[] kmerIndexFilePath = kmerIndexFiles.toArray(new Path[0]); // histogram List<KmerHistogram> histograms = new ArrayList<KmerHistogram>(); for (int i = 0; i < kmerIndexFiles.size(); i++) { String fastaFileName = KmerIndexHelper.getFastaFileName(kmerIndexFilePath[i]); Path histogramPath = new Path(inputFormatConfig.getKmerHistogramPath(), KmerHistogramHelper.makeKmerHistogramFileName(fastaFileName)); FileSystem fs = histogramPath.getFileSystem(job.getConfiguration()); if (fs.exists(histogramPath)) { KmerHistogram histogram = KmerHistogram.createInstance(fs, histogramPath); histograms.add(histogram); } else { throw new IOException("k-mer histogram is not found in given paths"); } } // merge histogram Hashtable<String, KmerHistogramRecord> histogramRecords = new Hashtable<String, KmerHistogramRecord>(); long kmerCounts = 0; for (int i = 0; i < histograms.size(); i++) { Collection<KmerHistogramRecord> records = histograms.get(i).getSortedRecord(); kmerCounts += histograms.get(i).getTotalKmerCount(); for (KmerHistogramRecord rec : records) { KmerHistogramRecord ext_rec = histogramRecords.get(rec.getKmer()); if (ext_rec == null) { histogramRecords.put(rec.getKmer(), rec); } else { ext_rec.increaseFrequency(rec.getFrequency()); } } } List<KmerHistogramRecord> histogramRecordsArr = new ArrayList<KmerHistogramRecord>(); histogramRecordsArr.addAll(histogramRecords.values()); Collections.sort(histogramRecordsArr, new KmerHistogramRecordComparator()); KmerRangePartitioner partitioner = new KmerRangePartitioner(inputFormatConfig.getKmerSize(), inputFormatConfig.getPartitionNum()); KmerRangePartition[] partitions = partitioner .getHistogramPartitions(histogramRecordsArr.toArray(new KmerHistogramRecord[0]), kmerCounts); for (KmerRangePartition partition : partitions) { splits.add(new KmerMatchInputSplit(kmerIndexFilePath, partition)); } // Save the number of input files in the job-conf job.getConfiguration().setLong(NUM_INPUT_FILES, files.size()); LOG.debug("Total # of splits: " + splits.size()); return splits; }
From source file:com.krawler.spring.hrms.common.hrmsDocumentController.java
public HashMap getDocInfo(KwlReturnObject kmsg, storageHandlerImpl storageHandlerObj) throws ServiceException { HashMap ht = null;/*from w w w . j a va2s . c o m*/ Hashtable htable; if (kmsg.getEntityList().size() != 0) { htable = getExtDocumentDownloadHash(kmsg.getEntityList()); ht = new HashMap(); String src = storageHandlerObj.GetDocStorePath(); src = src + htable.get("svnname"); try { File fp = new File(src); ht.put("attachment", src); ht.put("filename", htable.get("Name")); } catch (Exception ex) { ex.printStackTrace(); } } return ht; }
From source file:org.mahasen.util.PutUtil.java
/** * @param part/*from w ww . j ava 2 s. c om*/ * @param parentFileName * @param partName * @throws MahasenConfigurationException * @throws PastException * @throws InterruptedException */ public void replicateFilePart(File part, String parentFileName, String partName) throws MahasenConfigurationException, PastException, InterruptedException, MahasenException { Vector<String> nodeIpsToPut = getNodeIpsToPut(); String resourcePath = MahasenConstants.ROOT_REGISTRY_PATH + parentFileName; Id parentFileId = Id.build(String.valueOf(resourcePath.hashCode())); while (mahasenManager.lookupDHT(parentFileId) == null) { Thread.sleep(1000); } MahasenResource mahasenResourceToUpdate = mahasenManager.lookupDHT(parentFileId); getReplicaReference().put(partName, 0); Random random = new Random(); Hashtable<String, Vector<String>> spittedPartsStoredIps = mahasenResourceToUpdate.getSplittedPartsIpTable(); Vector<String> currentPartStoredIps = spittedPartsStoredIps.get(partName); List<String> replicateIds = new ArrayList<String>(); final BlockFlag blockFlag = new BlockFlag(true, 3000); while (true) { if (nodeIpsToPut.size() >= MahasenConstants.NUMBER_OF_REPLICAS + 1) { if (getReplicaReference().get(partName) == MahasenConstants.NUMBER_OF_REPLICAS) { log.info("Success in replicating :" + getReplicaReference().get(partName) + " parts"); break; } String nodeIp = nodeIpsToPut.get(random.nextInt(nodeIpsToPut.size())); if (!currentPartStoredIps.contains(nodeIp) && !replicateIds.contains(nodeIp)) { replicateIds.add(nodeIp); try { sendReplicateRequest(nodeIp, part, partName, mahasenResourceToUpdate, parentFileId); } catch (URISyntaxException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } } else { for (String ip : nodeIpsToPut) { if (!currentPartStoredIps.contains(ip)) { try { sendReplicateRequest(ip, part, partName, mahasenResourceToUpdate, parentFileId); } catch (URISyntaxException e) { e.printStackTrace(); } } } blockFlag.unblock(); break; } if (blockFlag.isBlocked()) { mahasenManager.getNode().getEnvironment().getTimeSource().sleep(10); } else { throw new MahasenException("Time out in storing " + part.getName()); } Thread.sleep(100); } }
From source file:com.openmeap.json.JSONObjectBuilder.java
public JSONObject toJSON(Object obj) throws JSONException { if (obj == null) { return null; }// w w w. ja v a 2s . c o m if (!HasJSONProperties.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "The rootObject being converted to JSON must implement the HasJSONProperties interface."); } JSONProperty[] properties = ((HasJSONProperties) obj).getJSONProperties(); JSONObject jsonObj = new JSONObject(); // iterate over each JSONProperty annotated method for (int jsonPropertyIdx = 0; jsonPropertyIdx < properties.length; jsonPropertyIdx++) { JSONProperty property = properties[jsonPropertyIdx]; // determine the method return type Class returnType = property.getReturnType(); Object value = property.getGetterSetter().getValue(obj); if (value == null) { continue; } if (returnType == null) { throw new JSONException(obj.getClass().getName() + "." + property.getPropertyName() + " is annotated with JSONProperty, but has no return type." + " I can't work with this."); } // strip "get" off the front String propertyName = property.getPropertyName(); try { if (Enum.class.isAssignableFrom(returnType)) { Enum ret = (Enum) value; jsonObj.put(propertyName, ret.value()); } else if (isSimpleType(returnType)) { jsonObj.put(propertyName, handleSimpleType(returnType, property.getGetterSetter().getValue(obj))); } else { if (returnType.isArray()) { Object[] returnValues = (Object[]) value; JSONArray jsonArray = new JSONArray(); for (int returnValueIdx = 0; returnValueIdx < returnValues.length; returnValueIdx++) { Object thisValue = returnValues[returnValueIdx]; jsonArray.put(toJSON(thisValue)); } jsonObj.put(propertyName, jsonArray); } else if (Hashtable.class.isAssignableFrom(returnType)) { Hashtable map = (Hashtable) value; JSONObject jsonMap = new JSONObject(); Enumeration enumer = map.keys(); while (enumer.hasMoreElements()) { Object key = (String) enumer.nextElement(); Object thisValue = (Object) map.get(key); if (isSimpleType(thisValue.getClass())) { jsonMap.put(key.toString(), handleSimpleType(returnType, thisValue)); } else { jsonMap.put(key.toString(), toJSON(thisValue)); } } jsonObj.put(propertyName, jsonMap); } else if (Vector.class.isAssignableFrom(returnType)) { Vector returnValues = (Vector) property.getGetterSetter().getValue(obj); JSONArray jsonArray = new JSONArray(); int size = returnValues.size(); for (int returnValueIdx = 0; returnValueIdx < size; returnValueIdx++) { Object thisValue = returnValues.elementAt(returnValueIdx); if (isSimpleType(property.getContainedType())) { jsonArray.put(thisValue); } else { jsonArray.put(toJSON(thisValue)); } } jsonObj.put(propertyName, jsonArray); } else { jsonObj.put(propertyName, toJSON(value)); } } } catch (Exception ite) { throw new JSONException(ite); } } return jsonObj; }
From source file:edu.ucsb.nceas.metacattest.UploadIPCCDataTest.java
private String handleSingleEML(String docid, boolean originalDataFileIncorrect) throws Exception { Metacat metacat = MetacatFactory.createMetacatConnection(METACATURL); // login metacat String response = metacat.login(USERNAME, PASSWORD); if (response.indexOf("<login>") == -1) { throw new Exception("login failed " + response); }//from w w w.j a v a 2 s .c o m // 1. Reads eml document from metacat Reader r = new InputStreamReader(metacat.read(docid)); Document DOMdoc = XMLUtilities.getXMLReaderAsDOMDocument(r); Node rootNode = (Node) DOMdoc.getDocumentElement(); //2. Gets online url information. If onlineUrl is not SRB, through an exception String onlineUrl = getOnLineURL(rootNode); //System.out.println("=================The url is "+onlineUrl); //3. Find the srb data file String dataFileName = getDataFileNameFromURL(onlineUrl); //System.out.println("the data fileName in eml "+dataFileName); //If the dataFileName in original eml is wrong, we need to look up the // the correct name first if (originalDataFileIncorrect) { Hashtable correctName = getCurrent_CorrectFileNamesPair(); dataFileName = (String) correctName.get(dataFileName); } //System.out.println("=================The data file is "+dataFileName); File dataFile = null; dataFile = new File(SRBDATAFILEDIR, dataFileName); if (!dataFile.exists()) { throw new Exception("Couldn't find the data file in srb data directory " + dataFile); } //4. Generate docid for data file String dataId = generateId(); //System.out.println("=======The docid for data file will be "+dataId); //5. upload data file to Metacat response = metacat.upload(dataId, dataFile); if (response.indexOf("<success>") == -1) { throw new Exception("Couldn't upload data file " + dataFileName + " with id " + dataId + " into Metacat since " + response); } //6. Updates eml online url and package id in DOM String newId = updateEMLDoc(rootNode, docid, dataId); //System.out.println("The new docid is ========"+newId); //Put EML DOM with the new packagId and oneline url into a StringWriter and store it to String StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); XMLUtilities.print(rootNode, printWriter); String xml = stringWriter.toString(); //System.out.println("the xml is "+xml); //7.insert new (update) EML document into Metacat StringReader xmlReader = new StringReader(xml); response = metacat.update(newId, xmlReader, null); if (response.indexOf("<success>") == -1) { throw new Exception("Upload data file " + dataFileName + " with id " + dataId + " successfully but update eml " + newId + " failed since " + response); } metacat.logout(); return dataId; }
From source file:com.mobilefirst.fiberlink.WebServiceRequest.java
/** * setMethodParams sets methods parameters * @param method: method whose parameters to be set * @param params: parameter list to be set * @return HttpMethodParams Object of HttpMethodParams *//* w w w . ja v a2s .co m*/ public HttpMethodParams setMethodParams(HttpMethod method, Hashtable<String, String> params) { HttpMethodParams httpMethodParams = new HttpMethodParams(); Enumeration<String> keys = params.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (method instanceof PostMethod) { ((PostMethod) method).setParameter(key, params.get(key)); System.out.println(key + " :: " + params.get(key) + "\n"); } } return httpMethodParams; }