List of usage examples for java.util Hashtable size
public synchronized int size()
From source file:com.flexive.shared.FxArrayUtils.java
/** * Removes dupicated entries from the list. * * @param list the list/*from w w w . j av a 2s. c om*/ * @return the list without any duplicated entries */ public static long[] removeDuplicates(long[] list) { if (list == null || list.length == 0) { return new long[0]; } Hashtable<Long, Boolean> tbl = new Hashtable<Long, Boolean>(list.length); for (long ele : list) { tbl.put(ele, Boolean.FALSE); } long[] result = new long[tbl.size()]; int pos = 0; for (long element : Collections.list(tbl.keys())) { result[pos++] = element; } return result; }
From source file:com.flexive.shared.FxArrayUtils.java
/** * Removes dupicated entries from the list. * * @param list the list/*from w w w. j a v a 2 s . com*/ * @return the list without any duplicated entries */ public static int[] removeDuplicates(int[] list) { if (list == null || list.length == 0) { return new int[0]; } Hashtable<Integer, Boolean> tbl = new Hashtable<Integer, Boolean>(list.length); for (int ele : list) { tbl.put(ele, Boolean.FALSE); } int[] result = new int[tbl.size()]; int pos = 0; for (Enumeration e = tbl.keys(); e.hasMoreElements();) { result[pos++] = (Integer) e.nextElement(); } return result; }
From source file:org.globus.workspace.remoting.admin.client.RemoteAdminToolsMain.java
private static List<Map<String, String>> nodesToMaps(Hashtable<String, String[]> ht) { List<Map<String, String>> maps = new ArrayList<Map<String, String>>(ht.size()); Enumeration<String> hosts = ht.keys(); while (hosts.hasMoreElements()) { String host = hosts.nextElement(); String[] ids = ht.get(host); String idList = ""; for (int i = 0; i < ids.length; i++) { if (i + 1 != ids.length) idList += ids[i] + ", "; else/*from w w w . java 2 s . c o m*/ idList += ids[i]; } final HashMap<String, String> map = new HashMap(2); map.put(FIELD_NODE, host); map.put(FIELD_ID, idList); maps.add(map); } return maps; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a stacked bar graph representing the total number of tests in * in each build. /*from w w w .ja v a 2s. c o m*/ * * @param builds List of builds * * @return Stacked graph representing automated tests across all builds */ public static final JFreeChart getTestCountChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build test numbers for each of the builds in the list Collections.sort(builds, new CMnBuildIdComparator()); Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the test summary for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Hashtable testSummary = build.getTestSummary(); if ((testSummary != null) && (testSummary.size() > 0)) { Enumeration keys = testSummary.keys(); while (keys.hasMoreElements()) { String testType = (String) keys.nextElement(); Integer buildId = new Integer(build.getId()); CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType); // Record the total number of tests dataset.addValue(tests.getTotalCount(), testType, buildId); } } } // while list has elements } // if list has elements // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls) chart = ChartFactory.createStackedBarChart("Automated Tests by Type", "Builds", "Test Count", dataset, PlotOrientation.VERTICAL, true, true, false); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); chartFormatter.formatTypeChart(plot, dataset); return chart; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing average test counts for each type of test for * all builds in the list. //from w w w.j a va 2s.c o m * * @param builds List of builds * * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageTestCountChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; // Collect the average of all test types Hashtable countAvg = new Hashtable(); 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(); Hashtable testSummary = build.getTestSummary(); if ((testSummary != null) && (testSummary.size() > 0)) { Enumeration keys = testSummary.keys(); while (keys.hasMoreElements()) { String testType = (String) keys.nextElement(); CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType); Integer avgValue = null; if (countAvg.containsKey(testType)) { Integer oldAvg = (Integer) countAvg.get(testType); avgValue = oldAvg + tests.getTotalCount(); } else { avgValue = tests.getTotalCount(); } countAvg.put(testType, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = countAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Integer total = (Integer) countAvg.get(key); Integer avg = new Integer(total.intValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Count by Type", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatTypeChart(plot, "tests"); return chart; }
From source file:Sort.java
/** * Sort a Hashtable./*from w w w. j a v a 2 s . c om*/ * * @param h * A Hashtable with String or Ordered keys. * @return A sorted array of the keys. * @exception ClassCastException * If the keys of the hashtable are not <code>Ordered</code>. */ public static Object[] QuickSort(Hashtable h) throws ClassCastException { Enumeration e; boolean are_strings; Object[] ret; // make the array ret = new Ordered[h.size()]; e = h.keys(); are_strings = true; // until proven otherwise for (int i = 0; i < ret.length; i++) { ret[i] = e.nextElement(); if (are_strings && !(ret[i] instanceof String)) are_strings = false; } // sort it if (are_strings) QuickSort((String[]) ret); else QuickSort((Ordered[]) ret); return (ret); }
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./* www .j a va2 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:de.kaiserpfalzEdv.commons.jee.jndi.SimpleContextFactory.java
@Override public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { Hashtable<Object, Object> env = new Hashtable<>(environment.size()); for (Object key : environment.keySet()) { env.put(key, environment.get(key)); }/*from w w w.j a va2 s . c om*/ String configPath = System.getProperty(CONFIG_FILE_NAME_PROPERTY); if (isNotBlank(configPath)) { env.remove(org.osjava.sj.SimpleContext.SIMPLE_ROOT); env.put(org.osjava.sj.SimpleContext.SIMPLE_ROOT, configPath); } else { configPath = (String) env.get(org.osjava.sj.SimpleContext.SIMPLE_ROOT); } LOG.trace("***** Loading configuration from: {}", configPath); return new SimpleContext(env); }
From source file:org.sipfoundry.sipxconfig.admin.commserver.configdb.ConfigDbSettingAdaptor.java
public boolean get(Setting setting) { Collection names = new ArrayList(); setting.acceptVisitor(new NamesCollector(names)); String[] paramNames = (String[]) names.toArray(new String[names.size()]); Hashtable results = m_configDbParameter.get(setting.getProfileName(), paramNames); setting.acceptVisitor(new ResultRetriever(results)); return results.size() == paramNames.length; }
From source file:org.catechis.TransformerTest.java
/** *<element>/*from ww w .ja v a 2 s .c om*/ <sub_element1>test1</sub_element1> <sub_element2>test2</sub_element2> </element> */ public void testElementIntoHash() { Element element = new Element("element"); Element sub_element1 = new Element("sub_element1"); Element sub_element2 = new Element("sub_element2"); sub_element1.addContent("test1"); sub_element2.addContent("test2"); element.addContent(sub_element1); element.addContent(sub_element2); Transformer trans = new Transformer(); Hashtable results = trans.elementIntoHash(element); int size = results.size(); //System.out.println("Transformer.testElementIntoHash "+size); //printLog(trans.getLog()); //dumpLog(results); Enumeration keys = results.keys(); String actual = (String) results.get(keys.nextElement()); String expected = new String("test2"); assertEquals(expected, actual); }