/** Two objects that are equal are required to return the same hashCode. */
 public void testHashcode() {
   Second s1 = new Second(13, 45, 5, 1, 2, 2003);
   Second s2 = new Second(13, 45, 5, 1, 2, 2003);
   assertTrue(s1.equals(s2));
   int h1 = s1.hashCode();
   int h2 = s2.hashCode();
   assertEquals(h1, h2);
 }
 /** Some checks for the getEnd() method. */
 public void testGetEnd() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.ITALY);
   Calendar cal = Calendar.getInstance(Locale.ITALY);
   cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55);
   cal.set(Calendar.MILLISECOND, 999);
   Second s = new Second(55, 47, 3, 16, 1, 2006);
   assertEquals(cal.getTime(), s.getEnd());
   Locale.setDefault(saved);
 }
 /** Some checks for the getLastMillisecond() method. */
 public void testGetLastMillisecond() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.UK);
   TimeZone savedZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
   Second s = new Second(1, 1, 1, 1, 1, 1970);
   assertEquals(61999L, s.getLastMillisecond());
   Locale.setDefault(saved);
   TimeZone.setDefault(savedZone);
 }
 /** Some checks for the getFirstMillisecond() method. */
 public void testGetFirstMillisecond() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.UK);
   TimeZone savedZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
   Second s = new Second(15, 43, 15, 1, 4, 2006);
   assertEquals(1143902595000L, s.getFirstMillisecond());
   Locale.setDefault(saved);
   TimeZone.setDefault(savedZone);
 }
 /** Tests the equals method. */
 public void testEquals() {
   Day day1 = new Day(29, MonthConstants.MARCH, 2002);
   Hour hour1 = new Hour(15, day1);
   Minute minute1 = new Minute(15, hour1);
   Second second1 = new Second(34, minute1);
   Day day2 = new Day(29, MonthConstants.MARCH, 2002);
   Hour hour2 = new Hour(15, day2);
   Minute minute2 = new Minute(15, hour2);
   Second second2 = new Second(34, minute2);
   assertTrue(second1.equals(second2));
 }
  /** Some checks for the getLastMillisecond(TimeZone) method. */
  public void testGetLastMillisecondWithTimeZone() {
    Second s = new Second(55, 1, 2, 7, 7, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    assertEquals(-614962684001L, s.getLastMillisecond(zone));

    // try null calendar
    boolean pass = false;
    try {
      s.getLastMillisecond((TimeZone) null);
    } catch (NullPointerException e) {
      pass = true;
    }
    assertTrue(pass);
  }
  /** Some checks for the getFirstMillisecond(TimeZone) method. */
  public void testGetFirstMillisecondWithTimeZone() {
    Second s = new Second(50, 59, 15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    assertEquals(-623289610000L, s.getFirstMillisecond(zone));

    // try null calendar
    boolean pass = false;
    try {
      s.getFirstMillisecond((TimeZone) null);
    } catch (NullPointerException e) {
      pass = true;
    }
    assertTrue(pass);
  }
Exemple #8
0
  public JFreeChart makegraph(Second g_start, Second g_end) {
    // read
    XYDataset readset = this.createread();
    XYItemRenderer minichart1 = new StandardXYItemRenderer();
    minichart1.setSeriesPaint(0, kSarConfig.color1);
    minichart1.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot1 = new XYPlot(readset, null, new NumberAxis("Read"), minichart1);
    // writ
    XYDataset writset = this.createwrit();
    XYItemRenderer minichart2 = new StandardXYItemRenderer();
    minichart2.setSeriesPaint(0, kSarConfig.color2);
    minichart1.setSeriesPaint(1, kSarConfig.color3);
    minichart2.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot2 = new XYPlot(writset, null, new NumberAxis("Write"), minichart2);
    // wcache
    XYDataset wcacheset = this.createwcache();
    XYItemRenderer minichart3 = new StandardXYItemRenderer();
    minichart3.setSeriesPaint(0, kSarConfig.color4);
    minichart3.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot3 = new XYPlot(wcacheset, null, new NumberAxis("%wcache"), minichart3);
    // rcache
    XYDataset rcacheset = this.creatercache();
    XYItemRenderer minichart4 = new StandardXYItemRenderer();
    minichart4.setSeriesPaint(0, kSarConfig.color5);
    minichart4.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot4 = new XYPlot(rcacheset, null, new NumberAxis("%rcache"), minichart4);
    // PANEL
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(""));
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.add(subplot3, 1);
    plot.add(subplot4, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart mychart = new JFreeChart(this.getGraphTitle(), kSarConfig.DEFAULT_FONT, plot, true);
    if (setbackgroundimage(mychart) == 1) {
      subplot1.setBackgroundPaint(null);
      subplot2.setBackgroundPaint(null);
      subplot3.setBackgroundPaint(null);
      subplot4.setBackgroundPaint(null);
    }
    if (g_start != null) {
      DateAxis dateaxis1 = (DateAxis) mychart.getXYPlot().getDomainAxis();
      dateaxis1.setRange(g_start.getStart(), g_end.getEnd());
    }

    bufferrcachetrigger.setTriggerValue(kSarConfig.hpuxbufferrcachetrigger);
    bufferrcachetrigger.tagMarker(subplot4);

    return mychart;
  }
  /** Some checks for the getLastMillisecond(TimeZone) method. */
  public void testGetLastMillisecondWithCalendar() {
    Second s = new Second(50, 45, 21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(987889550999L, s.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
      s.getLastMillisecond((Calendar) null);
    } catch (NullPointerException e) {
      pass = true;
    }
    assertTrue(pass);
  }
 /** Some checks for the testNext() method. */
 public void testNext() {
   Second s = new Second(55, 30, 1, 12, 12, 2000);
   s = (Second) s.next();
   assertEquals(2000, s.getMinute().getHour().getYear());
   assertEquals(12, s.getMinute().getHour().getMonth());
   assertEquals(12, s.getMinute().getHour().getDayOfMonth());
   assertEquals(1, s.getMinute().getHour().getHour());
   assertEquals(30, s.getMinute().getMinute());
   assertEquals(56, s.getSecond());
   s = new Second(59, 59, 23, 31, 12, 9999);
   assertNull(s.next());
 }
  /**
   * In Chicago, the 4.55:59pm on 21 Mar 2002 is java.util.Date(1016751359000L). Use this to check
   * the Second constructor.
   */
  public void testDateConstructor2() {
    TimeZone zone = TimeZone.getTimeZone("America/Chicago");
    Locale locale = Locale.getDefault(); // locale shouldn't matter here
    Second s1 = new Second(new Date(1016751358999L), zone, locale);
    Second s2 = new Second(new Date(1016751359000L), zone, locale);

    assertEquals(58, s1.getSecond());
    assertEquals(1016751358999L, s1.getLastMillisecond(zone));

    assertEquals(59, s2.getSecond());
    assertEquals(1016751359000L, s2.getFirstMillisecond(zone));
  }
Exemple #12
0
  public JFreeChart makegraph(Second g_start, Second g_end) {
    // used
    XYDataset xydataset1 = this.createused();
    XYPlot subplot1;
    NumberAxis usedaxis = new NumberAxis("% used cpu");
    if (mysar.show100axiscpu) {
      usedaxis.setRange(0.0D, 100D);
    }

    if (mysar.showstackedcpu) {
      StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
      renderer.setSeriesPaint(0, kSarConfig.color1);
      renderer.setSeriesPaint(1, kSarConfig.color2);
      renderer.setSeriesPaint(2, kSarConfig.color3);
      renderer.setSeriesPaint(3, kSarConfig.color4);
      subplot1 = new XYPlot(stacked_used, new DateAxis(null), usedaxis, renderer);

    } else {
      XYItemRenderer minichart1 = new StandardXYItemRenderer();
      minichart1.setBaseStroke(kSarConfig.DEFAULT_STROKE);
      minichart1.setSeriesPaint(0, kSarConfig.color1);
      minichart1.setSeriesPaint(1, kSarConfig.color2);
      minichart1.setSeriesPaint(2, kSarConfig.color3);
      minichart1.setSeriesPaint(2, kSarConfig.color4);
      subplot1 = new XYPlot(xydataset1, null, usedaxis, minichart1);
    }
    // idle
    XYDataset idleset = this.createidle();
    XYItemRenderer minichart2 = new StandardXYItemRenderer();
    minichart2.setSeriesPaint(0, kSarConfig.color5);
    minichart2.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot2 = new XYPlot(idleset, null, new NumberAxis("% idle"), minichart2);
    // nice
    XYDataset niceset = this.createnice();
    XYItemRenderer minichart3 = new StandardXYItemRenderer();
    minichart3.setSeriesPaint(0, kSarConfig.color6);
    minichart3.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot3 = new XYPlot(niceset, null, new NumberAxis("% niced"), minichart3);

    // the graph
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(""));
    plot.add(subplot1, 2);
    plot.add(subplot3, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    // the graph
    JFreeChart mychart = new JFreeChart(this.getGraphTitle(), kSarConfig.DEFAULT_FONT, plot, true);
    if (g_start != null) {
      DateAxis dateaxis1 = (DateAxis) mychart.getXYPlot().getDomainAxis();
      dateaxis1.setRange(g_start.getStart(), g_end.getEnd());
    }
    if (setbackgroundimage(mychart) == 1) {
      subplot1.setBackgroundPaint(null);
      subplot2.setBackgroundPaint(null);
      subplot3.setBackgroundPaint(null);
    }

    // idle trigger
    cpuidletrigger.setTriggerValue(kSarConfig.linuxcpuidletrigger);
    cpuidletrigger.tagMarker(subplot2);
    // system trigger
    cpusystemtrigger.setTriggerValue(kSarConfig.linuxcpusystemtrigger);
    cpusystemtrigger.tagMarker(subplot1);
    // wio trigger
    if (cpuOpt.equals("%iowait") || cpuOpt.equals("%steal")) {
      cpuwiotrigger.setTriggerValue(kSarConfig.linuxcpuwiotrigger);
      cpuwiotrigger.tagMarker(subplot1);
    }
    // usr trigger
    cpuusrtrigger.setTriggerValue(kSarConfig.linuxcpuusrtrigger);
    cpuusrtrigger.tagMarker(subplot1);
    //
    return mychart;
  }
Exemple #13
0
  /**
   * A basic check for the testPreviousStandardDate() method when the tick unit is 5 seconds (just
   * for the sake of having a multiple).
   */
  @Test
  public void testPreviousStandardDateSecondB() {
    MyDateAxis axis = new MyDateAxis("Second");
    Second s0 = new Second(58, 31, 12, 1, 4, 2007);
    Second s1 = new Second(59, 31, 12, 1, 4, 2007);

    // five dates to check...
    Date d0 = new Date(s0.getFirstMillisecond());
    Date d1 = new Date(s0.getFirstMillisecond() + 50L);
    Date d2 = new Date(s0.getMiddleMillisecond());
    Date d3 = new Date(s0.getMiddleMillisecond() + 50L);
    Date d4 = new Date(s0.getLastMillisecond());

    Date end = new Date(s1.getLastMillisecond());

    DateTickUnit unit = new DateTickUnit(DateTickUnit.SECOND, 5);
    axis.setTickUnit(unit);

    // START: check d0 and d1
    axis.setTickMarkPosition(DateTickMarkPosition.START);

    axis.setRange(d0, end);
    Date psd = axis.previousStandardDate(d0, unit);
    Date nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d0.getTime());
    assertTrue(nsd.getTime() >= d0.getTime());

    axis.setRange(d1, end);
    psd = axis.previousStandardDate(d1, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d1.getTime());
    assertTrue(nsd.getTime() >= d1.getTime());

    // MIDDLE: check d1, d2 and d3
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    axis.setRange(d1, end);
    psd = axis.previousStandardDate(d1, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d1.getTime());
    assertTrue(nsd.getTime() >= d1.getTime());

    axis.setRange(d2, end);
    psd = axis.previousStandardDate(d2, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d2.getTime());
    assertTrue(nsd.getTime() >= d2.getTime());

    axis.setRange(d3, end);
    psd = axis.previousStandardDate(d3, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d3.getTime());
    assertTrue(nsd.getTime() >= d3.getTime());

    // END: check d3 and d4
    axis.setTickMarkPosition(DateTickMarkPosition.END);

    axis.setRange(d3, end);
    psd = axis.previousStandardDate(d3, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d3.getTime());
    assertTrue(nsd.getTime() >= d3.getTime());

    axis.setRange(d4, end);
    psd = axis.previousStandardDate(d4, unit);
    nsd = unit.addToDate(psd);
    assertTrue(psd.getTime() < d4.getTime());
    assertTrue(nsd.getTime() >= d4.getTime());
  }
 /** Some checks for the getSerialIndex() method. */
 public void testGetSerialIndex() {
   Second s = new Second(1, 1, 1, 1, 1, 2000);
   assertEquals(3155850061L, s.getSerialIndex());
   s = new Second(1, 1, 1, 1, 1, 1900);
   assertEquals(176461L, s.getSerialIndex());
 }
 /**
  * Test that a Second instance is equal to itself.
  *
  * <p>SourceForge Bug ID: 558850.
  */
 public void testEqualsSelf() {
   Second second = new Second();
   assertTrue(second.equals(second));
 }