/** * In GMT, the end of 2001 is java.util.Date(1009843199999L). Use this to check the * year constructor. */ public void testDateConstructor1() { final TimeZone zone = TimeZone.getTimeZone("GMT"); final Date d1 = new Date(1009843199999L); final Date d2 = new Date(1009843200000L); final Year y1 = new Year(d1, zone); final Year y2 = new Year(d2, zone); assertEquals(2001, y1.getYear()); assertEquals(1009843199999L, y1.getLastMillisecond(zone)); assertEquals(2002, y2.getYear()); assertEquals(1009843200000L, y2.getFirstMillisecond(zone)); }
/** * Test the setMaximumItemCount() method to ensure that it removes items from the series * if necessary. */ public void testSetMaximumItemCount() { TimeSeries s1 = new TimeSeries("S1", Year.class); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); assertTrue(s1.getItemCount() == 5); s1.setMaximumItemCount(3); assertTrue(s1.getItemCount() == 3); TimeSeriesDataItem item = s1.getDataItem(0); assertTrue(item.getPeriod().equals(new Year(2002))); }
/** * In GMT, the end of 2001 is java.util.Date(1009843199999L). Use this to * check the year constructor. */ public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Date d1 = new Date(1009843199999L); Date d2 = new Date(1009843200000L); Year y1 = new Year(d1, zone); Year y2 = new Year(d2, zone); assertEquals(2001, y1.getYear()); assertEquals(1009843199999L, y1.getLastMillisecond(zone)); assertEquals(2002, y2.getYear()); assertEquals(1009843200000L, y2.getFirstMillisecond(zone)); }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithTimeZone() { Year y = new Year(1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); assertEquals(-631123200000L, y.getFirstMillisecond(zone)); // try null calendar boolean pass = false; try { y.getFirstMillisecond((TimeZone) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); assertEquals(978307200000L, y.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { y.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithTimeZone() { Year y = new Year(1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); assertEquals(-599587200001L, y.getLastMillisecond(zone)); // try null calendar boolean pass = false; try { y.getLastMillisecond((TimeZone) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); assertEquals(1009843199999L, y.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { y.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
/** * Test the setMaximumItemCount() method to ensure that it removes items * from the series if necessary. */ public void testSetMaximumItemCount() { TimeSeries s1 = new TimeSeries("S1", Year.class); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); assertTrue(s1.getItemCount() == 5); s1.setMaximumItemCount(3); assertTrue(s1.getItemCount() == 3); TimeSeriesDataItem item = s1.getDataItem(0); assertTrue(item.getPeriod().equals(new Year(2002))); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); assertEquals(c1, c2); // add a series OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); OHLCSeries s2 = new OHLCSeries("Series"); s2.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new OHLCSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new OHLCSeries("Empty Series")); assertTrue(c1.equals(c2)); }
/** * Creates a new axis. * * @param label the axis label (<code>null</code> permitted). * @param first the first time period in the axis range * (<code>null</code> not permitted). * @param last the last time period in the axis range * (<code>null</code> not permitted). * @param timeZone the time zone (<code>null</code> not permitted). */ public PeriodAxis(String label, RegularTimePeriod first, RegularTimePeriod last, TimeZone timeZone) { super(label, null); this.first = first; this.last = last; this.timeZone = timeZone; this.calendar = Calendar.getInstance(timeZone); this.autoRangeTimePeriodClass = first.getClass(); this.majorTickTimePeriodClass = first.getClass(); this.minorTickMarksVisible = false; this.minorTickTimePeriodClass = RegularTimePeriod.downsize( this.majorTickTimePeriodClass); setAutoRange(true); this.labelInfo = new PeriodAxisLabelInfo[2]; this.labelInfo[0] = new PeriodAxisLabelInfo(Month.class, new SimpleDateFormat("MMM")); this.labelInfo[1] = new PeriodAxisLabelInfo(Year.class, new SimpleDateFormat("yyyy")); }
/** * Confirm that the equals() method can distinguish the locale field (which * is new in version 1.0.13). */ @Test public void testEqualsWithLocale() { PeriodAxis a1 = new PeriodAxis("Test", new Year(2000), new Year(2009), TimeZone.getDefault(), Locale.JAPAN); PeriodAxis a2 = new PeriodAxis("Test", new Year(2000), new Year(2009), TimeZone.getDefault(), Locale.JAPAN); assertTrue(a1.equals(a2)); assertTrue(a2.equals(a1)); a1 = new PeriodAxis("Test", new Year(2000), new Year(2009), TimeZone.getDefault(), Locale.UK); assertFalse(a1.equals(a2)); a2 = new PeriodAxis("Test", new Year(2000), new Year(2009), TimeZone.getDefault(), Locale.UK); assertTrue(a1.equals(a2)); }
@Test public void testDateRangeWithConjunction() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); query.setObjects( dataElements ); Conjunction conjunction = query.conjunction(); conjunction.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); conjunction.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); query.add( conjunction ); List<? extends IdentifiableObject> objects = queryEngine.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
/** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); OHLCSeriesCollection c2 = (OHLCSeriesCollection) c1.clone(); assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); }
/** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("S"); s1.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c1.addSeries(s1); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); OHLCSeries s2 = new OHLCSeries("S"); s2.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c2.addSeries(s2); assertTrue(c1.equals(c2)); int h1 = c1.hashCode(); int h2 = c2.hashCode(); assertEquals(h1, h2); }
/** * Corrects the given tick date for the position setting. * * @param time the tick date/time. * @param unit the tick unit. * @param position the tick position. * * @return The adjusted time. */ private Date correctTickDateForPosition(Date time, DateTickUnit unit, DateTickMarkPosition position) { Date result = time; switch (unit.getUnit()) { case DateTickUnit.MILLISECOND : case DateTickUnit.SECOND : case DateTickUnit.MINUTE : case DateTickUnit.HOUR : case DateTickUnit.DAY : break; case DateTickUnit.MONTH : result = calculateDateForPosition(new Month(time, this.timeZone, this.locale), position); break; case DateTickUnit.YEAR : result = calculateDateForPosition(new Year(time, this.timeZone, this.locale), position); break; default: break; } return result; }
@Test public void testDateRangeWithConjunction() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); Conjunction conjunction = query.conjunction(); conjunction.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); conjunction.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); query.add( conjunction ); List<? extends IdentifiableObject> objects = queryService.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
@Test public void testDateRange() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); query.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); query.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); List<? extends IdentifiableObject> objects = queryService.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
@Test public void testDateRange() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); query.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); query.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); List<? extends IdentifiableObject> objects = queryEngine.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
@Test public void testDateRangeWithConjunction() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); Conjunction conjunction = query.conjunction(); conjunction.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); conjunction.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); query.add( conjunction ); List<? extends IdentifiableObject> objects = queryEngine.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
@Test public void testDateRange() { Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) ); query.setObjects( dataElements ); query.add( Restrictions.ge( "created", Year.parseYear( "2002" ).getStart() ) ); query.add( Restrictions.le( "created", Year.parseYear( "2004" ).getStart() ) ); List<? extends IdentifiableObject> objects = queryEngine.query( query ); assertEquals( 3, objects.size() ); assertTrue( collectionContainsUid( objects, "deabcdefghB" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghC" ) ); assertTrue( collectionContainsUid( objects, "deabcdefghD" ) ); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { PeriodAxis a1 = new PeriodAxis("Test"); PeriodAxis a2 = new PeriodAxis("Test"); assertTrue(a1.equals(a2)); assertTrue(a2.equals(a1)); a1.setFirst(new Year(2000)); assertFalse(a1.equals(a2)); a2.setFirst(new Year(2000)); assertTrue(a1.equals(a2)); a1.setLast(new Year(2004)); assertFalse(a1.equals(a2)); a2.setLast(new Year(2004)); assertTrue(a1.equals(a2)); a1.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland")); assertFalse(a1.equals(a2)); a2.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland")); assertTrue(a1.equals(a2)); a1.setAutoRangeTimePeriodClass(Quarter.class); assertFalse(a1.equals(a2)); a2.setAutoRangeTimePeriodClass(Quarter.class); assertTrue(a1.equals(a2)); PeriodAxisLabelInfo info[] = new PeriodAxisLabelInfo[1]; info[0] = new PeriodAxisLabelInfo(Month.class, "MMM"); a1.setLabelInfo(info); assertFalse(a1.equals(a2)); a2.setLabelInfo(info); assertTrue(a1.equals(a2)); }
/** * Creates a new axis. * * @param label the axis label (<code>null</code> permitted). * @param first the first time period in the axis range (<code>null</code> not permitted). * @param last the last time period in the axis range (<code>null</code> not permitted). * @param timeZone the time zone (<code>null</code> not permitted). */ public PeriodAxis(String label, RegularTimePeriod first, RegularTimePeriod last, TimeZone timeZone) { super(label, null); this.first = first; this.last = last; this.timeZone = timeZone; this.autoRangeTimePeriodClass = Day.class; setAutoRange(true); this.labelInfo = new PeriodAxisLabelInfo[2]; this.labelInfo[0] = new PeriodAxisLabelInfo(Month.class, "MMM"); this.labelInfo[1] = new PeriodAxisLabelInfo(Year.class, "yyyy"); }
/** * Add a value to series A for 1999. It should be added at index 0. */ public void testAddValue() { final TimePeriodValues tpvs = new TimePeriodValues("Test"); try { tpvs.add(new Year(1999), new Integer(1)); } catch (SeriesException e) { System.err.println("TimePeriodValuesTests.testAddValue: problem adding to series."); } final int value = tpvs.getValue(0).intValue(); assertEquals(1, value); }
/** * In Los Angeles, the end of 2001 is java.util.Date(1009871999999L). Use this to check the * year constructor. */ public void testDateConstructor2() { final TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); final Year y1 = new Year(new Date(1009871999999L), zone); final Year y2 = new Year(new Date(1009872000000L), zone); assertEquals(2001, y1.getYear()); assertEquals(1009871999999L, y1.getLastMillisecond(zone)); assertEquals(2002, y2.getYear()); assertEquals(1009872000000L, y2.getFirstMillisecond(zone)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { final Year y1 = new Year(1988); final Year y2 = new Year(1988); assertTrue(y1.equals(y2)); final int h1 = y1.hashCode(); final int h2 = y2.hashCode(); assertEquals(h1, h2); }
/** * Add a value to series A for 1999. It should be added at index 0. */ public void testAddValue() { try { this.seriesA.add(new Year(1999), new Integer(1)); } catch (SeriesException e) { System.err.println("TimeSeriesTests.testAddValue: problem adding to series."); } final int value = this.seriesA.getValue(0).intValue(); assertEquals(1, value); }
/** * Tests the retrieval of values. */ public void testGetValue() { final Number value1 = this.seriesA.getValue(new Year(1999)); assertNull(value1); final int value2 = this.seriesA.getValue(new Year(2000)).intValue(); assertEquals(102000, value2); }
/** * Tests the deletion of values. */ public void testDelete() { this.seriesA.delete(0, 0); assertEquals(5, this.seriesA.getItemCount()); final Number value = this.seriesA.getValue(new Year(2000)); assertNull(value); }
/** * Basic tests for the delete() method. */ public void testDelete2() { TimeSeries s1 = new TimeSeries("Series", Year.class); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.addChangeListener(this); this.gotSeriesChangeEvent = false; s1.delete(new Year(2001)); assertTrue(this.gotSeriesChangeEvent); assertEquals(2, s1.getItemCount()); assertEquals(null, s1.getValue(new Year(2001))); }
/** * Some checks for the addOrUpdate() method. */ public void testAddOrUpdate() { TimeSeries s1 = new TimeSeries("S1", Year.class); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2000), 100.0); assertEquals(1, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 101.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 102.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2002), 103.0); assertEquals(2, s1.getItemCount()); }
/** * A test case for bug 1498805. */ public void testBug1498805() { TimeZone zone = TimeZone.getTimeZone("GMT"); GregorianCalendar gc = new GregorianCalendar(zone); gc.set(2005, Calendar.JANUARY, 1, 12, 0, 0); Week w = new Week(gc.getTime(), zone); assertEquals(53, w.getWeek()); assertEquals(new Year(2004), w.getYear()); }
/** * Add a value to series A for 1999. It should be added at index 0. */ public void testAddValue() { TimePeriodValues tpvs = new TimePeriodValues("Test"); try { tpvs.add(new Year(1999), new Integer(1)); } catch (SeriesException e) { System.err.println("Problem adding to series."); } int value = tpvs.getValue(0).intValue(); assertEquals(1, value); }
/** * In Los Angeles, the end of 2001 is java.util.Date(1009871999999L). Use * this to check the year constructor. */ public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Year y1 = new Year(new Date(1009871999999L), zone); Year y2 = new Year(new Date(1009872000000L), zone); assertEquals(2001, y1.getYear()); assertEquals(1009871999999L, y1.getLastMillisecond(zone)); assertEquals(2002, y2.getYear()); assertEquals(1009872000000L, y2.getFirstMillisecond(zone)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { Year y1 = new Year(1988); Year y2 = new Year(1988); assertTrue(y1.equals(y2)); int h1 = y1.hashCode(); int h2 = y2.hashCode(); assertEquals(h1, h2); }