List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing test counts for each product area. * * @param suites List of test suites * @param areas List of product areas * /*w w w .j a v a 2 s . c o m*/ * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageAreaTestTimeChart(Vector<CMnDbBuildData> builds, Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) { JFreeChart chart = null; // Collect the average of all test types Hashtable timeAvg = new Hashtable(); DefaultPieDataset dataset = new DefaultPieDataset(); if ((suites != null) && (suites.size() > 0)) { // Collect test data for each of the suites in the list Enumeration suiteList = suites.elements(); while (suiteList.hasMoreElements()) { // Process the data for the current suite CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement(); Long elapsedTime = new Long(suite.getElapsedTime() / (1000 * 60)); CMnDbFeatureOwnerData area = null; // Iterate through each product area to determine who owns this suite CMnDbFeatureOwnerData currentArea = null; Iterator iter = areas.iterator(); while (iter.hasNext()) { currentArea = (CMnDbFeatureOwnerData) iter.next(); if (currentArea.hasFeature(suite.getGroupName())) { Long avgValue = null; String areaName = currentArea.getDisplayName(); if (timeAvg.containsKey(areaName)) { Long oldAvg = (Long) timeAvg.get(areaName); avgValue = oldAvg + elapsedTime; } else { avgValue = elapsedTime; } timeAvg.put(areaName, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = timeAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Long total = (Long) timeAvg.get(key); Long avg = new Long(total.longValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Time by Area", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatAreaChart(plot, "min"); return chart; }
From source file:com.flexoodb.engines.FlexDBDataEngine.java
private void indexValues(String id, String tablename, Object obj, Connection conn) throws Exception { Hashtable h = null; if (obj instanceof Hashtable) { h = (Hashtable) obj;/*from ww w . ja v a 2s. co m*/ } else { h = _flexutils.getAvailableValues(obj); } Enumeration en = h.keys(); while (en.hasMoreElements()) { String k = (String) en.nextElement(); Object o = ((Element) h.get(k)).getContent(); if (o != null && FlexUtils.indexable(o.getClass().getSimpleName())) { if (!k.equals("Id")) { try { String v = null; if (o instanceof Date) { v = (new SimpleDateFormat(FlexUtils._dateformat)).format((Date) o); } else { v = o.toString(); } PreparedStatement ps = (PreparedStatement) conn.prepareStatement( "insert into " + tablename + "_index (id,element,value) values (?,?,?)"); ps.setString(1, id); ps.setString(2, k); ps.setString(3, (v.length() > 100) ? v.substring(0, 99) : v); // possible issues in truncation? ps.executeUpdate(); ps.close(); } catch (Exception f) { } } } } }
From source file:org.ramadda.data.services.RecordApiHandler.java
/** * Handle the metrics API call/*w w w . j ava 2 s. c om*/ * * @param request The HTTP request * * @return The result * * @throws Exception On badness */ public Result processMetricsRequest(Request request) throws Exception { RecordOutputHandler loh = getRecordOutputHandler(); StringBuffer sb = new StringBuffer(); makeHeader(request, sb); boolean isAdmin = request.getUser().getAdmin(); if (!isAdmin) { //Allow anyone to view metrics // sb.append(getPageHandler().showDialogError("You must be a site administrator to see metrics")); // return makeResult(request, sb); } Hashtable<String, long[]> info = new Hashtable<String, long[]>(); List<Entry> entries = new ArrayList<Entry>(); long totalNumPoints = 0; long totalSize = 0; long totalJobs = 0; for (JobInfo jobInfo : getRecordOutputHandler().getRecordJobManager().readJobs(JOB_TYPE_POINT)) { int numberOfPoints = jobInfo.getNumPoints(); totalNumPoints += numberOfPoints; long productSize = jobInfo.getProductSize(); totalSize += productSize; String entryId = jobInfo.getEntryId(); long[] values = info.get(entryId); if (values == null) { Entry entry = getEntryManager().getEntry(request, entryId); if (entry == null) { System.err.println("missing entry from metrics:" + entryId); continue; } entries.add(entry); values = new long[] { 0, 0, 0 }; info.put(entryId, values); } values[0]++; totalJobs++; values[1] += numberOfPoints; values[2] += productSize; } sb.append(HtmlUtils.p()); sb.append( "<table cellpadding=0 cellspacing=0 class=\"result-table\"><tr class=\"result-header\"><td>Collection</td><td># Jobs</td><td># Points</td><td>Product size</td></tr>"); String size = ""; long mb; for (Entry entry : entries) { long[] values = info.get(entry.getId()); sb.append("<tr>"); sb.append(HtmlUtils.col(getEntryManager().getEntryLink(request, entry))); sb.append(HtmlUtils.col("" + values[0], " align=right ")); sb.append(HtmlUtils.col(loh.getFormHandler().formatPointCount(values[1]), " align=right ")); mb = (values[2] / 1000000); if (mb > 0) { size = mb + "MB"; } else { size = (values[2] / 1000) + "KB"; } sb.append(HtmlUtils.colRight(size)); sb.append("</tr>"); } sb.append("<tr>"); sb.append(HtmlUtils.col(" ")); sb.append(HtmlUtils.colRight("" + totalJobs)); sb.append(HtmlUtils.colRight(loh.getFormHandler().formatPointCount(totalNumPoints))); mb = (totalSize / 1000000); if (mb > 0) { size = mb + "MB"; } else { size = (totalSize / 1000) + "KB"; } sb.append(HtmlUtils.colRight(size)); sb.append("</tr>"); sb.append("</table>"); return makeResult(request, sb); }
From source file:net.rim.ejde.internal.packaging.RAPCFile.java
/** * Get the resource id for the given project. We look this up given the resource title key that has been chosen. We used to * store the id number but problems occur if people update their resources outside of the resource editor (which preserves the * id numbers).//from w ww .j a v a2s . co m * * @throws CoreException */ private int getTitleResourceId(BlackBerryProperties properties) throws CoreException { String key = properties._resources.getTitleResourceBundleKey(); Map<String, RRHFile> resourceMap = ProjectUtils.getProjectResources(_bbProject); RRHFile rrhFile = resourceMap.get(properties._resources.getTitleResourceBundleClassName()); if (rrhFile == null) { String msg = "Could not find key information for " + properties._resources.getTitleResourceBundleClassName(); _log.error(msg); throw new CoreException(StatusFactory.createErrorStatus(msg)); } Hashtable<String, String> headerKey2Id = rrhFile.getKeyTalbe(); if (headerKey2Id == null) { String path; if (rrhFile.getFile() != null) { path = rrhFile.getFile().getLocation().toOSString(); } else { path = properties._resources.getTitleResourceBundleClassName(); } String msg = NLS.bind(Messages.RAPCFIlE_NO_KEY_MSG, path); _log.error(msg); throw new CoreException(StatusFactory.createErrorStatus(msg)); } String resourceId = headerKey2Id.get(key); if (resourceId == null) { String msg = NLS.bind(Messages.RAPCFIlE_RESOURCE_KEY_NOT_FOUND_MSG, key); _log.error(msg); throw new CoreException(StatusFactory.createErrorStatus(msg)); } try { return Integer.parseInt(resourceId); } catch (NumberFormatException nfe) { _log.error(nfe); throw new CoreException(StatusFactory.createErrorStatus(nfe.getMessage())); } }
From source file:com.khubla.cbean.serializer.impl.DefaultClassHasher.java
/** * populate class from hash// www. j a v a2 s.c o m */ @Override public Object hashToClass(Hashtable<String, String> hashtable) throws SerializerException { try { /* * get a proxied class to use */ // final Object ret = getProxiedInstance(clazz); final Object ret = getInstance(clazz); /* * get the fields */ final Field[] persistableFields = CBeanType.getCBeanType(clazz).getPersistableFields(); for (int i = 0; i < persistableFields.length; i++) { final Field field = persistableFields[i]; final Class<?> fieldClazz = field.getType(); final FieldSerializer serializer = fieldSerializerFactory.getFieldSerializer(field); final String fieldValue = hashtable.get(field.getName()); if (null != serializer) { serializer.deserialize(ret, field, fieldValue); } else if (CBean.isEntity(fieldClazz)) { /* * recurse */ final Property property = field.getAnnotation(Property.class); if (property.cascadeLoad()) { final CBean<Object> cBean = CBeanServer.getInstance().getCBean(fieldClazz); /* * this load may come back as a null. If it does, the contained object referred to has been deleted. This is ok, just set the value to null. */ final Object o = cBean.load(new CBeanKey(fieldValue)); PropertyUtils.setProperty(ret, field.getName(), o); } else { final Object o = getProxiedInstance(fieldClazz, fieldValue); PropertyUtils.setProperty(ret, field.getName(), o); } } else { throw new SerializerException("Unsupported serialization type '" + fieldClazz.getName() + "'"); } } return ret; } catch (final Exception e) { throw new SerializerException(e); } }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
/** * Re-maps and clones the definitions.// ww w . j ava 2 s. c o m * @param viewDefs the hash table to be mapped * @throws Exception */ public static void mapDefinitionViewDefs(final Hashtable<String, ViewDefIFace> viewDefs) throws Exception { // Now that all the definitions have been read in // cycle thru and have all the tableform objects clone there definitions for (ViewDefIFace viewDef : new Vector<ViewDefIFace>(viewDefs.values())) { if (viewDef.getType() == ViewDefIFace.ViewType.formtable) { String viewDefName = ((FormViewDefIFace) viewDef).getDefinitionName(); if (viewDefName != null) { //log.debug(viewDefName); ViewDefIFace actualDef = viewDefs.get(viewDefName); if (actualDef != null) { viewDefs.remove(viewDef.getName()); actualDef = (ViewDef) actualDef.clone(); actualDef.setType(ViewDefIFace.ViewType.formtable); actualDef.setName(viewDef.getName()); viewDefs.put(actualDef.getName(), actualDef); } else { String msg = "Couldn't find the ViewDef for formtable definition name[" + ((FormViewDefIFace) viewDef).getDefinitionName() + "]"; log.error(msg); FormDevHelper.appendFormDevError(msg); } } } } }
From source file:org.gridchem.client.gui.charts.UsageChart.java
/** * Returns a dataset representing the relative usage of the given * projects against the given collaborator. * //from w ww.j a va 2 s .c o m * @param projectCollabTable * @return */ private DefaultPieDataset createProjectDataset( Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) { DefaultPieDataset pds = new DefaultPieDataset(); // add project summary info for (ProjectBean project : projectCollabTable.keySet()) { CollaboratorBean collabBean = projectCollabTable.get(project) .get(projectCollabTable.get(project).indexOf(collab)); if (collabBean != null) { pds.setValue(project.getName() + " Used", new Double(collabBean.getTotalUsage().getUsed())); pds.setValue(project.getName() + " Avail.", new Double(collabBean.getTotalUsage().getBalance())); // keep track of the current project so we can explode that piece // of the pie. if (project.equals(GridChem.project)) { defaultProjectIndex = pds.getItemCount() - 1; } } } return pds; }
From source file:org.mybatisorm.annotation.handler.JoinHandler.java
private String getOnPhrase(List<Field> fieldList, Hashtable<Set<Class<?>>, LinkedList<Field[]>> refMap) { StringBuilder sb = new StringBuilder(); Field field = fieldList.get(fieldList.size() - 1), field2; Class<?> clazz = field.getType(), clazz2; List<String> cnames = new LinkedList<String>(); int j;// w ww .ja va2s.c om for (j = fieldList.size() - 2; j >= 0; j--) { field2 = fieldList.get(j); clazz2 = field2.getType(); cnames.add(0, clazz2.getSimpleName()); LinkedList<Field[]> refs = refMap.get(pair(clazz, clazz2)); if (refs == null) continue; sb.append(" ON ("); Iterator<Field[]> it = refs.iterator(); while (it.hasNext()) { Field[] fs = it.next(); if (field.getType().equals(fs[0].getDeclaringClass())) { sb.append(field.getName()).append("_.").append(ColumnAnnotation.getName(fs[0])).append(" = ") .append(field2.getName()).append("_.").append(ColumnAnnotation.getName(fs[1])); } else { sb.append(field2.getName()).append("_.").append(ColumnAnnotation.getName(fs[0])).append(" = ") .append(field.getName()).append("_.").append(ColumnAnnotation.getName(fs[1])); } if (it.hasNext()) sb.append(" AND "); } sb.append(") "); break; } if (j < 0) throw new InvalidJoinException( "The class " + clazz.getSimpleName() + " doesn't refer to the former classes(" + StringUtil.join(cnames, ",") + "), nor vice versa."); return sb.toString(); }
From source file:eionet.util.Util.java
/** * A method for formatting the given timestamp into a String released_datasets.jsp. * * @param timestamp Milliseconds since 1 January 1970. *///from ww w. j av a 2 s .co m private static String releasedDate(long timestamp, boolean shortMonth) { Date date = new Date(timestamp); String year = String.valueOf(1900 + date.getYear()); String month = String.valueOf(date.getMonth()); String day = String.valueOf(date.getDate()); day = (day.length() < 2) ? ("0" + day) : day; Hashtable months = new Hashtable(); months.put("0", "January"); months.put("1", "February"); months.put("2", "March"); months.put("3", "April"); months.put("4", "May"); months.put("5", "June"); months.put("6", "July"); months.put("7", "August"); months.put("8", "September"); months.put("9", "October"); months.put("10", "November"); months.put("11", "December"); String time = day + " " + (shortMonth ? months.get(month).toString().substring(0, 3) : months.get(month)) + " " + year; return time; }
From source file:net.sf.joost.plugins.traxfilter.THResolver.java
/** * Set to the SAX TrAX Factory attributes by inspecting the given parameters * for those which are from TrAX namespace * */// ww w . j a va 2s .c om protected void setTraxFactoryAttributes(SAXTransformerFactory saxtf, Hashtable params) { // loop over all parameters Enumeration e = params.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); // is this one from TrAX namespace? if (key.startsWith(tmp_TRAX_ATTR_NS)) { // it is, remove the namespace prefix and set it to the factory String name = key.substring(tmp_TRAX_ATTR_NS.length()).toLowerCase(); saxtf.setAttribute(name, params.get(key)); if (DEBUG) log.debug("newTHOutOfTrAX(): set factory attribute " + name + "=" + params.get(key)); } } }