List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:com.instantme.api.InstagramAPI.java
public boolean login(String user, String password, IAnimation anim) { IHTTPResponseHandler step1 = new IHTTPResponseHandler() { public boolean Response30X(HttpConnection connection, Hashtable cookies) { return false; }/*from w w w . ja va 2s .c o m*/ public boolean Response20X(HttpConnection connection, Hashtable cookies) { return cookies.get("csrftoken") != null; } public boolean ResponseOthers(HttpConnection connection, Hashtable cookies) { return false; } }; IHTTPResponseHandler step2 = new IHTTPResponseHandler() { public boolean Response30X(HttpConnection connection, Hashtable cookies) { if (cookies.get("sessionid") == null) { return false; } else { parseUserID(); return true; } } public boolean Response20X(HttpConnection connection, Hashtable cookies) { return false; } public boolean ResponseOthers(HttpConnection connection, Hashtable cookies) { return false; } }; IHTTPResponseHandler step3 = new IHTTPResponseHandler() { public boolean Response30X(HttpConnection connection, Hashtable cookies) { return cookies.get("accessToken") != null; } public boolean Response20X(HttpConnection connection, Hashtable cookies) { return true; } public boolean ResponseOthers(HttpConnection connection, Hashtable cookies) { return false; } }; IHTTPResponseHandler step4 = new IHTTPResponseHandler() { public boolean Response30X(HttpConnection connection, Hashtable cookies) { return cookies.get("accessToken") != null; } public boolean Response20X(HttpConnection connection, Hashtable cookies) { return false; } public boolean ResponseOthers(HttpConnection connection, Hashtable cookies) { return false; } }; this.user = user; this.password = password; // clear all cookies and session information cookies.clear(); lastUrl = ""; logged = false; Hashtable getParams = new Hashtable(); getParams.put("client_id", CLIENT_ID); getParams.put("redirect_uri", REDIRECT_URI); getParams.put("response_type", "token"); getParams.put("scope", "basic+likes+comments+relationships"); println("Step 1"); setAnimation(anim); updateProgress(Locale.getInst().getStr(Locale.LOGIN_1_4)); logged = HttpLoginRequest(HttpConnection.GET, LOGIN_URL, getParams, null, step1); if (logged == false) { println("Failed at step 1"); return false; } Hashtable postParams = new Hashtable(); postParams.put("csrfmiddlewaretoken", cookies.get("csrftoken")); postParams.put("username", user); postParams.put("password", password); postParams.put("scope", "basic+likes+comments+relationships"); println("Step 2"); updateProgress(Locale.getInst().getStr(Locale.LOGIN_2_4)); logged = HttpLoginRequest(HttpConnection.POST, LOGIN_URL, getParams, postParams, step2); if (logged == false) { println("Failed at step 2"); return logged; } println("Step 3"); updateProgress(Locale.getInst().getStr(Locale.LOGIN_3_4)); logged = HttpLoginRequest(HttpConnection.GET, AUTH_URL, getParams, null, step3); if (logged == false) { println("Failed at step 3"); return logged; } step1 = step2 = step3 = null; updateProgress(Locale.getInst().getStr(Locale.LOGIN_4_4)); if (cookies.get("accessToken") == null) { postParams.clear(); postParams.put("csrfmiddlewaretoken", cookies.get("csrftoken")); postParams.put("allow", "Authorize"); postParams.put("scope", "basic+likes+comments+relationships"); println("Step 4"); logged = HttpLoginRequest(HttpConnection.POST, AUTH_URL, getParams, postParams, step4); if (logged == false) { println("Failed at step 4"); return logged; } } step4 = null; // update user info getFullUserInfo(userInfo, getAuthUserID(), anim); return logged; }
From source file:imapi.IMAPIClass.java
public void printResultInstances(Hashtable<Float, Vector<ResultSourceTargetPair>> resultInstances) { int resultsCounter = 0; if (resultInstances.size() == 0) { System.out.println("0 results found."); } else {/* w ww.j a va 2 s. c om*/ Vector<Float> sortBySimilarityVec = new Vector<Float>(resultInstances.keySet()); Collections.sort(sortBySimilarityVec); Collections.reverse(sortBySimilarityVec); for (int i = 0; i < sortBySimilarityVec.size(); i++) { float sim = sortBySimilarityVec.get(i); Vector<ResultSourceTargetPair> stPairs = resultInstances.get(sim); Collections.sort(stPairs); for (int k = 0; k < stPairs.size(); k++) { ResultSourceTargetPair resultInfo = stPairs.get(k); SourceTargetPair pair = resultInfo.getSourceTargetPair(); SequenceSimilarityResultVector tripVec = resultInfo.getSimilarityResultsVector(); System.out.println((++resultsCounter) + ".\t" + Utilities.df.format(sim) + "\t" + pair.getSourceInstance().getSourceName() + " " + pair.getSourceInstance().getInstanceUri() + " " + pair.getTargetInstance().getSourceName() + " " + pair.getTargetInstance().getInstanceUri()); //check if uri similarity is encoutered if (pair.getSourceInstance().getInstanceUri() .equals(pair.getTargetInstance().getInstanceUri())) { System.out.println("\t\t\turi similarity 1\n"); continue; } else { this.printSimilaritiesData(tripVec); } System.out.println(); } } } }
From source file:org.gridchem.client.gui.charts.UsageChart.java
/** * Returns a dataset representing the cumulative usage of each user * across the set of projects. // w w w. ja v a2s . co m * * @param projectCollabTable * @return */ private DefaultPieDataset createUserDataset(Hashtable<ProjectBean, List<CollaboratorBean>> usageTable, CollaboratorBean collab) { DefaultPieDataset pds = new DefaultPieDataset(); Hashtable<String, Double> userUsageTable = new Hashtable<String, Double>(); // for every project for (ProjectBean project : usageTable.keySet()) { // if the user is part of this project if (usageTable.get(project).contains(collab)) { userUsageTable.put(project.getName(), usageTable.get(project) .get(usageTable.get(project).indexOf(collab)).getTotalUsage().getUsed()); } } // now put the tallies in the dataset for (String userName : userUsageTable.keySet()) { pds.setValue(userName, userUsageTable.get(userName).doubleValue()); } return pds; }
From source file:hu.sztaki.lpds.storage.service.carmen.server.upload.UploadServlet.java
/** * Processes requests for <code>GET</code> methods. * * @param request/*from www .j a va 2 s. c o m*/ * servlet request * @param response * servlet response * @throws IOException channel handling error * @throws ServletException Servlet error */ protected void getProcessRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // System.out.println(""); // System.out.println("UploadServlet getProcessRequest begin..."); ServletOutputStream out = response.getOutputStream(); String getSID = null; String getendSID = null; String retStr = new String(""); try { getSID = request.getParameter("sid"); // System.out.println("getSID: " + getSID); } catch (Exception e) { e.printStackTrace(); } try { getendSID = request.getParameter("endsid"); // System.out.println("getendSID: " + getendSID); } catch (Exception e) { e.printStackTrace(); } // if ((getSID != null) && (getendSID == null)) { // get type "sid" // System.out.println("get type SID : " + getSID); if (!getSID.trim().equals("")) { retStr = UploadUtils.getInstance().getGenerateRetHTMLString(getSID); } else { retStr = new String("Error in parameter: sid"); } } else if ((getSID == null) && (getendSID != null)) { // get type "endsid" // System.out.println("get type endSID : " + getendSID); if (!getendSID.trim().equals("")) { // check error uploads boolean haveError = false; // get file list (fileHash) Hashtable fileHash = UploadItemsList.getInstance().getFileHash(getendSID); // parse if ((fileHash != null) && (!fileHash.isEmpty())) { Enumeration enumeration = fileHash.keys(); StringBuffer sb = new StringBuffer(); while (enumeration.hasMoreElements()) { String fileName = (String) enumeration.nextElement(); if ((fileName != null) && (!fileName.equals(""))) { UploadItemBean uploadItemBean = (UploadItemBean) fileHash.get(fileName); Integer filePerCent = uploadItemBean.getPerCent(); String fileErrorStr = uploadItemBean.getErrorStr(); // System.out.println("fileName - fileErrorStr : " + fileName + " - " + fileErrorStr); if (fileErrorStr.startsWith("Error")) { haveError = true; // System.out.println("have error in : "); // retStr = new String(fileErrorStr + "</ br>"); sb.append(new String(fileErrorStr + "</ br>")); // System.out.println("fileName : " + fileName); } } } retStr = sb.toString(); // System.out.println("Storage Upload Servlet haveError : " + haveError); if (haveError) { retStr = new String("Error in upload process ! </ br>\n" + retStr); } else { // System.out.println("no have error in : "); retStr = new String("Upload is succesfull !" + "</ br>"); } } else { retStr = new String("Error getFileHash is null !"); } } else { retStr = new String("Error in parameter: endsid"); } } else if ((getSID == null) && (getendSID == null)) { // getSID == null and getendSID == null // System.out.println("getSID : " + getSID + " - getendSID : " + getendSID); retStr = new String("Error in parameter: sid and endsid !"); } else { retStr = new String("Error in parameters !"); } out.print(retStr); // System.out.println("UploadServlet getProcessRequest retString: " + retStr); // System.out.println("UploadServlet getProcessRequest end..."); }
From source file:org.hdiv.filter.RequestWrapper.java
/** * Parses an http cookie request header and replace values if confidentiality is activated. * /* w w w.j a va2 s. c o m*/ * @param cookieHader * value assigned to cookie header * @param sessionCookies * cookies stored in user session * @return cookie request header with replaced values * @since HDIV 1.1.1 */ private String replaceCookieString(String cookieHeader, Hashtable sessionCookies) { String header = cookieHeader.trim(); // Cookie fields are separated by ';' StringTokenizer tokens = new StringTokenizer(cookieHeader, ";"); while (tokens.hasMoreTokens()) { // field name is separated from value by '=' StringTokenizer t = new StringTokenizer(tokens.nextToken(), "="); String name = t.nextToken().trim(); if (name.equals(Constants.JSESSIONID)) { continue; } if (sessionCookies.containsKey(name)) { if (t.hasMoreTokens()) { String value = t.nextToken().trim(); SavedCookie savedCookie = (SavedCookie) sessionCookies.get(name); header = header.replaceFirst("=" + value, "=" + savedCookie.getValue()); } } } return header; }
From source file:com.zoffcc.applications.aagtl.FieldnotesUploader.java
public data_ret _encode_multipart_formdata(Hashtable<String, String> values, String file_field, String filename, byte[] file_data) throws IOException { data_ret ret2 = new data_ret(); //byte[] ret = new byte[1]; ByteArrayOutputStream b = new ByteArrayOutputStream(); String BOUNDARY = "----------ThIs_Is_tHe_bouNdaRY_$"; String CRLF = "\r\n"; Enumeration<String> i = values.keys(); String x = null;/* w w w . ja v a 2s .c o m*/ String y = null; // values while (i.hasMoreElements()) { x = i.nextElement(); y = values.get(x); if (b.size() > 0) { b.write(CRLF.getBytes()); } else { //ret = ""; } //ret = ret + "--" + BOUNDARY + CRLF; //ret = ret + "Content-Disposition: form-data; name=\"" + x + "\"" + CRLF; //ret = ret + CRLF; //ret = ret + y; b.write(("--" + BOUNDARY + CRLF).getBytes()); b.write(("Content-Disposition: form-data; name=\"" + x + "\"" + CRLF).getBytes()); b.write((CRLF + y).getBytes()); } // file if (b.size() > 0) { //ret = ret + CRLF; b.write(CRLF.getBytes()); } else { //ret = ""; } b.write(("--" + BOUNDARY + CRLF + "Content-Disposition: form-data; name=\"" + file_field + "\"; filename=\"" + filename + "\"" + CRLF + "Content-Type: " + "text/plain" + CRLF + CRLF).getBytes()); b.write(file_data); // finish if (b.size() > 0) { // ret = ret + CRLF; b.write(CRLF.getBytes()); } else { // ret = ""; } b.write(("--" + BOUNDARY + "--" + CRLF + CRLF).getBytes()); ret2.data = b; ret2.encoding = String.format("multipart/form-data; boundary=%s", BOUNDARY); return ret2; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing average build execution times across * all builds in the list. /* w w w .j av a2s . c o m*/ * * @param builds List of builds * * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageMetricChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; // Get a list of all possible build metrics int[] metricTypes = CMnDbMetricData.getAllTypes(); Hashtable metricAvg = new Hashtable(metricTypes.length); DefaultPieDataset dataset = new DefaultPieDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build metrics for each of the builds in the list Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the build metrics for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Vector metrics = build.getMetrics(); if ((metrics != null) && (metrics.size() > 0)) { // Collect data for each of the build metrics in the current build Enumeration metricList = metrics.elements(); while (metricList.hasMoreElements()) { CMnDbMetricData currentMetric = (CMnDbMetricData) metricList.nextElement(); // Get elapsed time in "minutes" Long elapsedTime = new Long(currentMetric.getElapsedTime() / (1000 * 60)); String metricName = CMnDbMetricData.getMetricType(currentMetric.getType()); Long avgValue = null; if (metricAvg.containsKey(metricName)) { Long oldAvg = (Long) metricAvg.get(metricName); avgValue = oldAvg + elapsedTime; } else { avgValue = elapsedTime; } metricAvg.put(metricName, avgValue); } // while build has metrics } // if has metrics } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = metricAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Long total = (Long) metricAvg.get(key); Long avg = new Long(total.longValue() / (long) builds.size()); //dataset.setValue(key, (Long) metricAvg.get(key)); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Average Build Metrics", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatMetricChart(plot, "min"); return chart; }
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Create the UI for the panel//from ww w. ja v a 2s. c om */ protected void createUI() { createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$ UIValidator.setIgnoreAllValidation(this, true); JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$ ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$ JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$ ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$ JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$ ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$ formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$ fontNames = fontNamesVCB.getComboBox(); fontSizes = fontSizesVCB.getComboBox(); controlSizes = controlSizesVCB.getComboBox(); testField = form.getCompById("fontTest"); //$NON-NLS-1$ if (testField != null) { testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$ } if (UIHelper.isMacOS_10_5_X()) { fontNamesLabel.setVisible(false); fontNamesVCB.setVisible(false); fontSizesLabel.setVisible(false); fontSizesVCB.setVisible(false); testField.setVisible(false); int inx = -1; int i = 0; Vector<String> controlSizeTitles = new Vector<String>(); for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) { String titleStr = getResourceString(cs.toString()); controlSizeTitles.add(titleStr); controlSizesHash.put(titleStr, cs); controlSizes.addItem(titleStr); if (cs == UIHelper.getControlSize()) { inx = i; } i++; } controlSizes.setSelectedIndex(inx); Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.addItem(baseFont.getFamily()); fontSizes.addItem(Integer.toString(baseFont.getSize())); fontNames.setSelectedIndex(0); fontSizes.setSelectedIndex(0); } } else { controlSizesLabel.setVisible(false); controlSizesVCB.setVisible(false); Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (Font font : ge.getAllFonts()) { if (namesUsed.get(font.getFamily()) == null) { fontNames.addItem(font.getFamily()); namesUsed.put(font.getFamily(), true); //$NON-NLS-1$ } } for (int i = BASE_FONT_SIZE; i < 22; i++) { fontSizes.addItem(Integer.toString(i)); } Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.setSelectedItem(baseFont.getFamily()); fontSizes.setSelectedItem(Integer.toString(baseFont.getSize())); if (testField != null) { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN, fontSizes.getSelectedIndex() + BASE_FONT_SIZE)); form.getUIComponent().validate(); clearFontSettings = false; } }; fontNames.addActionListener(al); fontSizes.addActionListener(al); } } } //----------------------------------- // Do DisciplineType Icons //----------------------------------- String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$ List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$ Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() { public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) { String s1 = UIRegistry.getResourceString(o1.first); String s2 = UIRegistry.getResourceString(o2.first); return s1.compareTo(s2); } }); disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$ final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$ JComboBox comboBox = disciplineCBX.getComboBox(); comboBox.setRenderer(new DefaultListCellRenderer() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public Component getListCellRendererComponent(JList listArg, Object value, int index, boolean isSelected, boolean cellHasFocus) { Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value; JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected, cellHasFocus); if (item != null) { label.setIcon(item.second); label.setText(UIRegistry.getResourceString(item.first)); } return label; } }); int inx = 0; Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$ IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$ comboBox.addItem(colObj); int cnt = 1; for (Pair<String, ImageIcon> item : list) { if (item.first.equals(iconName)) { inx = cnt; } comboBox.addItem(item); cnt++; } comboBox.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JComboBox cbx = (JComboBox) e.getSource(); Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem(); if (item != null) { dispLabel.setIcon(IconManager.getIcon(item.first)); form.getUIComponent().validate(); } } }); comboBox.setSelectedIndex(inx); //----------------------------------- // Date Field //----------------------------------- dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$ fillDateFormat(); //----------------------------------- // FormType //----------------------------------- fillFormTypes(); //----------------------------------- // Do App Icon //----------------------------------- final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$ final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$ final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$ final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$ String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$ ImageIcon innerAppImgIcon = null; if (StringUtils.isNotEmpty(imgEncoded)) { innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$ if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32 || innerAppImgIcon.getIconHeight() != 32) { innerAppImgIcon = null; clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } } if (innerAppImgIcon == null) { innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$ clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } appLabel.setIcon(innerAppImgIcon); getIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chooseToolbarIcon(appLabel, clearIconBtn); } }); clearIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ImageIcon appIcon = IconManager.getIcon("AppIcon"); IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME); entry.setIcon(appIcon); if (entry.getIcons().get(IconManager.IconSize.Std32) != null) { entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon); } appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); form.getValidator().dataChanged(null, null, null); } }); resetDefFontBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Font sysDefFont = UIRegistry.getDefaultFont(); ComboBoxModel model = fontNames.getModel(); for (int i = 0; i < model.getSize(); i++) { //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]"); if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) { fontNames.setSelectedIndex(i); clearFontSettings = true; break; } } if (clearFontSettings) { fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE); clearFontSettings = true; // needs to be redone } form.getValidator().dataChanged(null, null, null); } }); //----------------------------------- // Do Banner Icon Size //----------------------------------- String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE"); bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$ int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20); inx = 0; cnt = 0; for (int pixelSize : pixelSizes) { ((DefaultComboBoxModel) bnrIconSizeCBX.getModel()) .addElement(String.format(fmtStr, pixelSize, pixelSize)); if (pixelSize == size) { inx = cnt; } cnt++; } bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { form.getUIComponent().validate(); } }); bnrIconSizeCBX.getComboBox().setSelectedIndex(inx); UIValidator.setIgnoreAllValidation(this, false); fontNamesVCB.setChanged(false); fontSizesVCB.setChanged(false); form.getValidator().validateForm(); }
From source file:edu.wisc.ssec.mcidasv.data.cyclone.AtcfStormDataSource.java
/** * _more_//from ww w . j ava2 s.c o m * * @param stormInfo * _more_ * @param waysToUse * _more_ * @param observationWay * _more_ * * @return _more_ * * @throws Exception * _more_ */ public StormTrackCollection getTrackCollectionInner(StormInfo stormInfo, Hashtable<String, Boolean> waysToUse, Way observationWay) throws Exception { if (localTracks != null) { return localTracks; } long t1 = System.currentTimeMillis(); StormTrackCollection tracks = new StormTrackCollection(); String trackFile; boolean justObs = (waysToUse != null) && (waysToUse.size() == 1) && (waysToUse.get(Way.OBSERVATION.toString()) != null); int nowYear = new GregorianCalendar(DateUtil.TIMEZONE_GMT).get(Calendar.YEAR); int stormYear = getYear(stormInfo.getStartTime()); // If its the current year then its in the aid_public dir String aSubDir = ((stormYear == nowYear) ? "aid_public" : ("archive/" + stormYear)); String bSubDir = ((stormYear == nowYear) ? "btk" : ("archive/" + stormYear)); if (!justObs) { trackFile = getFullPath(aSubDir + "/" + PREFIX_ANALYSIS + stormInfo.getBasin().toLowerCase() + stormInfo.getNumber() + stormYear + ".dat.gz"); // What we think might be in the archive might actually be the last // year // and they haven't moved it into the archive try { readTracks(stormInfo, tracks, trackFile, waysToUse, true); } catch (BadDataException bde) { if (!aSubDir.equals("aid_public")) { try { trackFile = getFullPath("aid_public/" + PREFIX_ANALYSIS + stormInfo.getBasin().toLowerCase() + stormInfo.getNumber() + stormYear + ".dat.gz"); readTracks(stormInfo, tracks, trackFile, waysToUse, true); } catch (BadDataException bde2) { System.err.println("Failed reading 'A' file for storm:" + stormInfo + " file:" + trackFile); } } // System.err.println("Failed reading 'A' file for storm:" + // stormInfo+" file:" + trackFile); } } // Now read the b"est file trackFile = getFullPath(bSubDir + "/" + PREFIX_BEST + stormInfo.getBasin().toLowerCase() + stormInfo.getNumber() + stormYear + ".dat.gz"); try { readTracks(stormInfo, tracks, trackFile, null, true); } catch (BadDataException bde) { if (!bSubDir.equals("btk")) { try { trackFile = getFullPath("btk/" + PREFIX_BEST + stormInfo.getBasin().toLowerCase() + stormInfo.getNumber() + stormYear + ".dat.gz"); readTracks(stormInfo, tracks, trackFile, null, true); } catch (BadDataException bde2) { System.err.println("Failed reading 'B' file for storm:" + stormInfo + " file:" + trackFile); } } // System.err.println("Failed reading 'B' file for storm:" + // stormInfo+" file:" + trackFile); } long t2 = System.currentTimeMillis(); // System.err.println("time: " + (t2 - t1)); return tracks; }
From source file:org.gridchem.client.gui.charts.UsageChart.java
/** * Returns a dataset representing the cumulative resource usage across all * projects./*from ww w . ja v a2 s. c o m*/ * * @param projectCollabTable * @return */ @SuppressWarnings("unused") private DefaultPieDataset createResourceDataset( Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) { DefaultPieDataset pds = new DefaultPieDataset(); Hashtable<String, Double> resourceUsageTable = new Hashtable<String, Double>(); // for each project find the collaborator's usage on each resource for (ProjectBean project : projectCollabTable.keySet()) { List<CollaboratorBean> collabs = projectCollabTable.get(project); if (projectCollabTable.get(project).contains(collab)) { CollaboratorBean projectCollab = projectCollabTable.get(project) .get(projectCollabTable.get(project).indexOf(collab)); for (String systemName : projectCollab.getUsageTable().keySet()) { if (resourceUsageTable.containsKey(systemName)) { double previousUsage = resourceUsageTable.get(systemName).doubleValue(); resourceUsageTable.remove(systemName); resourceUsageTable.put(systemName, new Double( previousUsage + projectCollab.getUsageTable().get(systemName).getUsed())); } else { resourceUsageTable.put(systemName, new Double(projectCollab.getUsageTable().get(systemName).getUsed())); } } } } // now put the tallies in the dataset for (String systemName : resourceUsageTable.keySet()) { pds.setValue(systemName, resourceUsageTable.get(systemName).doubleValue()); } return pds; }