List of usage examples for java.util TreeMap TreeMap
public TreeMap()
From source file:josejamilena.pfc.analizador.GraficoPorScript.java
public GraficoPorScript(final String hostCliente, final String hostSgbd) throws ClassNotFoundException, SQLException { Map<String, String> res = new TreeMap<String, String>(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Statement stmt = null;//from w w w . jav a 2 s .c om ResultSet rs = null; String consulta = "select tiempo, fecha from estadisticas where host_cliente=\'" + hostCliente + "\' and host_sgbd=\'" + hostSgbd + "\'"; stmt = App.conn.createStatement(); rs = stmt.executeQuery(consulta); while (rs.next()) { res.put(rs.getString(2), rs.getString(1)); } rs.close(); stmt.close(); Iterator it = res.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); dataset.setValue(Double.parseDouble(pairs.getValue().toString()), hostCliente, pairs.getKey().toString()); } JFreeChart chart = ChartFactory.createBarChart(hostCliente + " / " + hostSgbd, // chart title "Hora", // domain axis label "Duracin (milisegundos)", // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false); CategoryPlot plot = chart.getCategoryPlot(); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); ChartPanel chartPanel = new ChartPanel(chart); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add((new JPanel()).add(chartPanel)); setContentPane(scrollPane); }
From source file:com.webcohesion.ofx4j.io.TestAggregateMarshaller.java
/** * test marshal//from w w w.j av a2 s .co m */ public void testMarshal() throws Exception { final Map<String, String> elementValuesWritten = new TreeMap<String, String>(); final Map<String, String> headersWritten = new TreeMap<String, String>(); final List<String> aggregatesStarted = new ArrayList<String>(); final List<String> aggregatesEnded = new ArrayList<String>(); AggregateExample example = new AggregateExample(); example.setHeader1("header1"); example.setHeader2("header2"); example.setElement1("root-element1"); AggregateExample2 child1 = new AggregateExample2(); child1.setElement("child1-element1"); example.setAggregate1(child1); AggregateExample2 child2 = new AggregateExample2(); child2.setElement("child2-element1"); example.setAggregate2(child2); AggregateExample2 child3 = new AggregateExample2(); child3.setElement("child3-element1"); AggregateExample3 child4 = new AggregateExample3(); child4.setElement("child4-element1"); example.setAggregateList(Arrays.asList(child3, child4)); new AggregateMarshaller().marshal(example, new OFXWriter() { public void writeHeaders(Map<String, String> headers) throws IOException { headersWritten.putAll(headers); } public void writeStartAggregate(String aggregateName) throws IOException { aggregatesStarted.add(aggregateName); } public void writeElement(String name, String value) throws IOException { elementValuesWritten.put(value, name); } public void writeEndAggregate(String aggregateName) throws IOException { aggregatesEnded.add(aggregateName); } public void close() throws IOException { //we'll clear these to make sure the tests fail if close() was called. headersWritten.clear(); aggregatesEnded.clear(); aggregatesStarted.clear(); elementValuesWritten.clear(); } }); assertEquals(2, headersWritten.size()); assertEquals("header1", headersWritten.get("HEADER1")); assertEquals("header2", headersWritten.get("ANOTHERHEADER")); assertEquals(5, elementValuesWritten.size()); assertEquals("SOMEELEMENT", elementValuesWritten.get("root-element1")); assertEquals("EXAMPLE2EL1", elementValuesWritten.get("child1-element1")); assertEquals("EXAMPLE2EL1", elementValuesWritten.get("child2-element1")); assertEquals("EXAMPLE2EL1", elementValuesWritten.get("child3-element1")); assertEquals("EXAMPLE3EL1", elementValuesWritten.get("child4-element1")); assertEquals(5, aggregatesStarted.size()); Iterator<String> it = aggregatesStarted.iterator(); assertEquals("EXAMPLE", it.next()); assertEquals("EXAMPLE2", it.next()); assertEquals("EXAMPLE2", it.next()); assertEquals("EXAMPLE3", it.next()); assertEquals("DIFFERENT", it.next()); assertEquals(5, aggregatesEnded.size()); it = aggregatesEnded.iterator(); assertEquals("EXAMPLE2", it.next()); assertEquals("EXAMPLE2", it.next()); assertEquals("EXAMPLE3", it.next()); assertEquals("DIFFERENT", it.next()); assertEquals("EXAMPLE", it.next()); }
From source file:dk.sdu.mmmi.hwr.group2.Utils.java
public static TreeMap<Calendar, Match> getAllMatches(boolean ignoreEmpty, boolean refresh) { if (!refresh && allCachedMaches != null) { return allCachedMaches; }/*from w w w. j a v a2 s .c o m*/ JSONObject json; try { json = new JSONObject(readURL("http://178.62.164.18:8080/foosball/api/match/getAll")); } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); return null; } TreeMap<Calendar, Match> matches = new TreeMap(); JSONArray matchesJSON = json.getJSONArray("matches"); for (int i = 0; i < matchesJSON.length(); i++) { JSONObject matchJSON = matchesJSON.getJSONObject(i); Match match = new Match(matchJSON.getInt("id"), matchJSON.getInt("startTime") * 1000l); JSONArray goalsJSON = matchJSON.getJSONArray("goals"); for (int k = 0; k < goalsJSON.length(); k++) { JSONObject goal = goalsJSON.getJSONObject(k); int player = goal.getInt("player"); int time = goal.getInt("time"); match.addGoal(player, time * 1000l); } if (ignoreEmpty && match.getGoalsMap().isEmpty()) { continue; } matches.put(match.getOldestGoalTime(), match); } allCachedMaches = matches; return allCachedMaches; }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.UtilityFunctions.java
public static Map<String, Integer> getYearToActivityCount(Set<Activity> activities) { /*// w ww.java2 s.c o m * Create a map from the year to number of publications. Use the BiboDocument's * or Grant's parsedPublicationYear or parsedGrantYear to populate the data passed * via Activity's getParsedActivityYear. * */ Map<String, Integer> yearToActivityCount = new TreeMap<String, Integer>(); for (Activity currentActivity : activities) { /* * Increment the count because there is an entry already available for * that particular year. * */ String activityYear = currentActivity.getParsedActivityYear(); if (yearToActivityCount.containsKey(activityYear)) { yearToActivityCount.put(activityYear, yearToActivityCount.get(activityYear) + 1); } else { yearToActivityCount.put(activityYear, 1); } } return yearToActivityCount; }
From source file:boa.aggregators.StatisticsAggregator.java
/** {@inheritDoc} */ @Override/* w w w. j a va2s. c om*/ public void start(final EmitKey key) { super.start(key); map = new TreeMap<Long, Long>(); count = 0; }
From source file:com.googlecode.psiprobe.controllers.threads.ListThreadsController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ////from w w w . j a va2 s.c o m // create a list of webapp classloaders // this will help us to associate threads with applications. // List contexts = getContainerWrapper().getTomcatContainer().findContexts(); Map classLoaderMap = new TreeMap(); for (int i = 0; i < contexts.size(); i++) { Context context = (Context) contexts.get(i); if (context.getLoader() != null && context.getLoader().getClassLoader() != null) { classLoaderMap.put(toUID(context.getLoader().getClassLoader()), context.getName()); } } return new ModelAndView(getViewName(), "threads", enumerateThreads(classLoaderMap)); }
From source file:com.lfv.yada.data.server.ServerBundle.java
public ServerBundle(Document doc) { log = LogFactory.getLog(getClass()); this.doc = doc; log.debug("Creating server bundle"); channelMap = new TreeMap<Integer, ServerChannel>(); terminalMap = new TreeMap<Integer, ServerTerminal>(); log.debug("Adding COMMON, PHONE and FORWARD channels"); channelMap.put(CHANNEL_COMMON, new ServerChannel(CHANNEL_COMMON)); channelMap.put(CHANNEL_PHONE, new ServerChannel(CHANNEL_PHONE)); channelMap.put(CHANNEL_FORWARD, new ServerChannel(CHANNEL_FORWARD)); synchronized (doc) { // Add channels from configuration Element egd = doc.getRootElement().getChild("GroupDefs"); Element ecd = doc.getRootElement().getChild("ChannelDefs"); Iterator iter = ecd.getChildren().iterator(); while (iter.hasNext()) { Element ec = (Element) iter.next(); int channelId = DomTools.getAttributeInt(ec, "id", 0, true); if (channelId > 0) { // Add one channel for each group Iterator iter2 = egd.getChildren().iterator(); while (iter2.hasNext()) { Element eg = (Element) iter2.next(); int groupId = DomTools.getAttributeInt(eg, "id", 0, true); if (groupId > 0) { int globalChannelId = (groupId << ID_BITSHIFT) | channelId; log.debug("Adding channel " + globalChannelId); channelMap.put(globalChannelId, new ServerChannel(globalChannelId)); } else { log.warn("Invalid id attribute on group (must be >0), skipping"); }/*from ww w. j a v a 2 s.co m*/ } } else { log.warn("Invalid id attribute on channel (must be >0), skipping"); } } // Add terminals from configuration Element etd = doc.getRootElement().getChild("TerminalDefs"); iter = etd.getChildren().iterator(); while (iter.hasNext()) { Element et = (Element) iter.next(); int terminalId = DomTools.getAttributeInt(et, "id", 0, true); if (terminalId > 0) { log.debug("Adding terminal " + terminalId); ServerTerminal terminal = new ServerTerminal(terminalId); terminalMap.put(terminalId, terminal); } else { log.warn("Invalid id attribute on terminal (must be >0), skipping"); } } } }
From source file:org.shept.util.FileUtils.java
/** * List the file directory as specified by the name filter and the path directory * The maps keys contain name and modification date for comparison *//* w ww .j a v a 2 s . c o m*/ public static SortedMap<FileNameDate, File> fileMapByNameAndDate(String path, String filePattern) { FileUtils fu = new FileUtils(); // needed for inner class SortedMap<FileNameDate, File> newFileMap = new TreeMap<FileNameDate, File>(); File fileDir = new File(path); if (null != path && fileDir.isDirectory()) { FileFilter filter = fu.new Filter(path, filePattern); File[] files = fileDir.listFiles(filter); for (int i = 0; i < files.length; i++) { FileNameDate fk = new FileNameDate(files[i].getName(), files[i].lastModified()); newFileMap.put(fk, files[i]); } } return newFileMap; }
From source file:com.ea.core.base.dto.DynamicDTO.java
public DynamicDTO() { generator = new BeanGenerator(); valueMap = new TreeMap<String, Object>(); }
From source file:net.testdriven.psiprobe.controllers.threads.ListThreadsController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ////from w w w.j ava 2 s . co m // create a list of webapp classloaders // this will help us to associate threads with applications. // List contexts = getContainerWrapper().getTomcatContainer().findContexts(); Map<String, String> classLoaderMap = new TreeMap<>(); for (Object context1 : contexts) { Context context = (Context) context1; if (context.getLoader() != null && context.getLoader().getClassLoader() != null) { classLoaderMap.put(toUID(context.getLoader().getClassLoader()), context.getName()); } } return new ModelAndView(getViewName(), "threads", enumerateThreads(classLoaderMap)); }