/** * A test for bug report 697153. */ public void test697153() { final TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); final TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 4", new SimpleTimePeriod(new Date(), new Date()))); final TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); tsc.add(s2); s1.removeAll(); final int taskCount = tsc.getColumnCount(); assertEquals(3, taskCount); }
/** * A test for bug report 800324. */ public void test800324() { final TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); final TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); // these methods should return null since the column number is too high... final Number start = tsc.getStartValue(0, 3); assertEquals(start, null); final Number end = tsc.getEndValue(0, 3); assertEquals(end, null); final int count = tsc.getSubIntervalCount(0, 3); assertEquals(0, count); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = new Task("T", new Date(1), new Date(2)); assertTrue(t1.equals(t2)); assertTrue(t2.equals(t1)); t1.setDescription("X"); assertFalse(t1.equals(t2)); t2.setDescription("X"); assertTrue(t1.equals(t2)); t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertFalse(t1.equals(t2)); t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertTrue(t1.equals(t2)); t1.setPercentComplete(0.5); assertFalse(t1.equals(t2)); t2.setPercentComplete(0.5); assertTrue(t1.equals(t2)); }
/** * Some checks for the add() methods. */ public void testAdd() { TimePeriodValues tpv = new TimePeriodValues("Test"); MySeriesChangeListener listener = new MySeriesChangeListener(); tpv.addChangeListener(listener); tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), new Date(3L)), 99.0)); assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON); assertEquals(tpv, listener.getLastEvent().getSource()); // a null item should throw an IllegalArgumentException boolean pass = false; try { tpv.add((TimePeriodValue) null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
/** * Resets the display. */ @Override void resetUI() { super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); AbstractXYItemRenderer br = new XYBarRenderer(); mDatasetsSyncHist = new TimePeriodValues[NUM_AUTHS+1]; @SuppressWarnings("unchecked") Map<SimpleTimePeriod, Integer> mTimePeriodMapTmp[] = new HashMap[NUM_AUTHS + 1]; mTimePeriodMap = mTimePeriodMapTmp; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); xyPlot.setDataset(tpvc); xyPlot.setRenderer(br); for (int i = 0; i < NUM_AUTHS + 1; i++) { br.setSeriesPaint(i, AUTH_COLORS[i]); mDatasetsSyncHist[i] = new TimePeriodValues(AUTH_NAMES[i]); tpvc.addSeries(mDatasetsSyncHist[i]); mTimePeriodMap[i] = new HashMap<SimpleTimePeriod, Integer>(); } }
/** * Callback to process a sync event. */ @Override void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, String details, boolean newEvent, int syncSource) { if (!newEvent) { // Details arrived for a previous sync event // Remove event before reinserting. int lastItem = mDatasetsSync[auth].getItemCount(); mDatasetsSync[auth].delete(lastItem-1, lastItem-1); mTooltipsSync[auth].remove(lastItem-1); } double height = getHeightFromDetails(details); height = height / (stopTime - startTime + 1) * 10000; if (height > 30) { height = 30; } mDatasetsSync[auth].add(new SimpleTimePeriod(startTime, stopTime), height); mTooltipsSync[auth].add(getTextFromDetails(auth, details, syncSource)); mTooltipGenerators[auth].addToolTipSeries(mTooltipsSync[auth]); if (details.indexOf('x') >= 0 || details.indexOf('X') >= 0) { long msec = event.sec * 1000L + (event.nsec / 1000000L); mDatasetError.addOrUpdate(new FixedMillisecond(msec), -1); } }
/** * Some checks for the getDomainBounds() method. */ public void testGetDomainBoundsWithoutInterval() { // check empty dataset TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); Range r = dataset.getDomainBounds(false); assertNull(r); // check dataset with one time period TimePeriodValues s1 = new TimePeriodValues("S1"); s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0); dataset.addSeries(s1); r = dataset.getDomainBounds(false); assertEquals(1500.0, r.getLowerBound(), EPSILON); assertEquals(1500.0, r.getUpperBound(), EPSILON); // check dataset with two time periods s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0); r = dataset.getDomainBounds(false); assertEquals(1500.0, r.getLowerBound(), EPSILON); assertEquals(2250.0, r.getUpperBound(), EPSILON); }
private XYDataset createBarDataset() { final TimePeriodValuesCollection result = new TimePeriodValuesCollection(); Set<String> nameSet = this.m_dataSetMap.keySet(); for (String name : nameSet) { final TimePeriodValues series = new TimePeriodValues(name); Map<Date, ? extends Number> map = m_dataSetMap.get(name); Iterator<Date> ir = map.keySet().iterator(); while (ir.hasNext()) { Date key = ir.next(); series.add(new SimpleTimePeriod(key, new Date(key.getTime() + (m_interval * OneDay))), map.get(key)); } result.addSeries(series); } return result; }
/** * Test the equals() method. */ public void testEquals() { final SimpleTimePeriod p1 = new SimpleTimePeriod(new Date(1000L), new Date(1001L)); final SimpleTimePeriod p2 = new SimpleTimePeriod(new Date(1000L), new Date(1001L)); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { final SimpleTimePeriod s1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); final SimpleTimePeriod s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertTrue(s1.equals(s2)); final int h1 = s1.hashCode(); final int h2 = s2.hashCode(); assertEquals(h1, h2); }
/** * Check that an instance is equal to itself. * * SourceForge Bug ID: 558850. */ public void testEqualsSelf() { SimpleTimePeriod p = new SimpleTimePeriod( new Date(1000L), new Date(1001L) ); assertTrue(p.equals(p)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { SimpleTimePeriod s1 = new SimpleTimePeriod( new Date(10L), new Date(20L) ); SimpleTimePeriod s2 = new SimpleTimePeriod( new Date(10L), new Date(20L) ); assertTrue(s1.equals(s2)); int h1 = s1.hashCode(); int h2 = s2.hashCode(); assertEquals(h1, h2); }
/** * This class is immutable, so it should not implement Cloneable. */ public void testClone() { SimpleTimePeriod s1 = new SimpleTimePeriod( new Date(10L), new Date(20L) ); assertFalse(s1 instanceof Cloneable); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = new Task("T", new Date(1), new Date(2)); assertTrue(t1.equals(t2)); assertTrue(t2.equals(t1)); t1.setDescription("X"); assertFalse(t1.equals(t2)); t2.setDescription("X"); assertTrue(t1.equals(t2)); t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertFalse(t1.equals(t2)); t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertTrue(t1.equals(t2)); t1.setPercentComplete(0.5); assertFalse(t1.equals(t2)); t2.setPercentComplete(0.5); assertTrue(t1.equals(t2)); t1.addSubtask(new Task("T", new Date(22), new Date(33))); assertFalse(t1.equals(t2)); t2.addSubtask(new Task("T", new Date(22), new Date(33))); assertTrue(t1.equals(t2)); }
/** * A test for bug report 697153. */ public void test697153() { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 4", new SimpleTimePeriod(new Date(), new Date()))); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); tsc.add(s2); s1.removeAll(); int taskCount = tsc.getColumnCount(); assertEquals(3, taskCount); }
/** * A test for bug report 697153. */ @Test public void test697153() { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 4", new SimpleTimePeriod(new Date(), new Date()))); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); tsc.add(s2); s1.removeAll(); int taskCount = tsc.getColumnCount(); assertEquals(3, taskCount); }
/** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = new Task("T", new Date(1), new Date(2)); assertTrue(t1.equals(t2)); assertTrue(t2.equals(t1)); t1.setDescription("X"); assertFalse(t1.equals(t2)); t2.setDescription("X"); assertTrue(t1.equals(t2)); t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertFalse(t1.equals(t2)); t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertTrue(t1.equals(t2)); t1.setPercentComplete(0.5); assertFalse(t1.equals(t2)); t2.setPercentComplete(0.5); assertTrue(t1.equals(t2)); t1.addSubtask(new Task("T", new Date(22), new Date(33))); assertFalse(t1.equals(t2)); t2.addSubtask(new Task("T", new Date(22), new Date(33))); assertTrue(t1.equals(t2)); }
private XYDataset createTimePeriodDataset() { if (sampleTimePeriodDataset == null) { TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); Day today = new Day(); TimePeriodValues series1 = new TimePeriodValues("First"); TimePeriodValues series2 = new TimePeriodValues("Second"); for (int i = 0; i < 24; i++) { Minute m0 = new Minute(0, new Hour(i, today)); Minute m1 = new Minute(15, new Hour(i, today)); Minute m2 = new Minute(30, new Hour(i, today)); Minute m3 = new Minute(45, new Hour(i, today)); Minute m4 = new Minute(0, new Hour(i + 1, today)); series1.add(new SimpleTimePeriod(m0.getStart(), m1.getStart()), Math.random()); series2.add(new SimpleTimePeriod(m1.getStart(), m2.getStart()), Math.random()); series1.add(new SimpleTimePeriod(m2.getStart(), m3.getStart()), Math.random()); series2.add(new SimpleTimePeriod(m3.getStart(), m4.getStart()), Math.random()); } dataset.addSeries(series1); dataset.addSeries(series2); sampleTimePeriodDataset = dataset; } return sampleTimePeriodDataset; }
/** * Helper to add an event to the data series. * Also updates error series if appropriate (x or X in details). * @param stopTime Time event ends * @param auth Sync authority * @param value Value to graph for event */ private void addHistEvent(long stopTime, int auth, double value) { SimpleTimePeriod hour = getTimePeriod(stopTime, mHistWidth); // Loop over all datasets to do the stacking. for (int i = auth; i <= ERRORS; i++) { addToPeriod(mDatasetsSyncHist, i, hour, value); } }
private void addToPeriod(TimePeriodValues tpv[], int auth, SimpleTimePeriod period, double value) { int index; if (mTimePeriodMap[auth].containsKey(period)) { index = mTimePeriodMap[auth].get(period); double oldValue = tpv[auth].getValue(index).doubleValue(); tpv[auth].update(index, oldValue + value); } else { index = tpv[auth].getItemCount(); mTimePeriodMap[auth].put(period, index); tpv[auth].add(period, value); } }
/** * Creates a multiple-hour time period for the histogram. * @param time Time in milliseconds. * @param numHoursWide: should divide into a day. * @return SimpleTimePeriod covering the number of hours and containing time. */ private SimpleTimePeriod getTimePeriod(long time, long numHoursWide) { Date date = new Date(time); TimeZone zone = RegularTimePeriod.DEFAULT_TIME_ZONE; Calendar calendar = Calendar.getInstance(zone); calendar.setTime(date); long hoursOfYear = calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.DAY_OF_YEAR) * 24; int year = calendar.get(Calendar.YEAR); hoursOfYear = (hoursOfYear / numHoursWide) * numHoursWide; calendar.clear(); calendar.set(year, 0, 1, 0, 0); // Jan 1 long start = calendar.getTimeInMillis() + hoursOfYear * 3600 * 1000; return new SimpleTimePeriod(start, start + numHoursWide * 3600 * 1000); }
/** * Some tests for the getMinStartIndex() method. */ public void testGetMinStartIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMinStartIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMinStartIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(0, s.getMinStartIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(2, s.getMinStartIndex()); }
/** * Some tests for the getMaxStartIndex() method. */ public void testGetMaxStartIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(1, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(1, s.getMaxStartIndex()); }
/** * Some tests for the getMinMiddleIndex() method. */ public void testGetMinMiddleIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(0, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(2, s.getMinMiddleIndex()); }