org.jfree.data.time.Hour Java Examples

The following examples show how to use org.jfree.data.time.Hour. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithTimeZone() {
    Hour h = new Hour(15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-623293200000L, h.getFirstMillisecond(c));
    
    // try null calendar
    boolean pass = false;
    try {
        h.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);            
}
 
Example #2
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #3
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #4
Source File: ChartConstants.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #5
Source File: TimeSeriesCollectorFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #6
Source File: XYAreaLineChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #7
Source File: OffspringChartComposite.java    From offspring with MIT License 6 votes vote down vote up
private IntervalXYDataset createVolumeDataset() {
  List<IRate> rates = rateProvider.getRates(base, quote);
  TimeSeries series = new TimeSeries("Volume");
  boolean non_zero_found = false;
  if (rates != null) {
    for (IRate rate : rates) {
      Date date = new Date(rate.getTimestamp());
      double vol = rate.getTotalVol();
      series.addOrUpdate(new Hour(date), vol);
      if (vol > 0)
        non_zero_found = true;
    }
  }
  if (non_zero_found == false)
    return null;

  TimeSeriesCollection dataset = new TimeSeriesCollection(series);
  dataset.setDomainIsPointsInTime(true);
  return dataset;
}
 
Example #8
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Hour h = new Hour(2, 15, 4, 2000);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(955764000000L, h.getFirstMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        h.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #9
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Hour h = new Hour(21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(987890399999L, h.getLastMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        h.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #10
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Hour h = new Hour(21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(987890399999L, h.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        h.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #11
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithTimeZone() {
    Hour h = new Hour(2, 7, 7, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-614959200001L, h.getLastMillisecond(c));

    // try null calendar
    boolean pass = false;
    try {
        h.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #12
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Hour h = new Hour(2, 15, 4, 2000);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(955764000000L, h.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        h.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #13
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithTimeZone() {
    Hour h = new Hour(15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-623293200000L, h.getFirstMillisecond(c));

    // try null calendar
    boolean pass = false;
    try {
        h.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #14
Source File: HourTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithTimeZone() {
    Hour h = new Hour(2, 7, 7, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-614959200001L, h.getLastMillisecond(c));
    
    // try null calendar
    boolean pass = false;
    try {
        h.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);            
}
 
Example #15
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    Hour h1 = new Hour(7, 9, 10, 1999);
    Hour h2 = new Hour(7, 9, 10, 1999);
    assertTrue(h1.equals(h2));
    int hash1 = h1.hashCode();
    int hash2 = h2.hashCode();
    assertEquals(hash1, hash2);
}
 
Example #16
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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"));
    Hour h = new Hour(15, 1, 4, 2006);
    assertEquals(1143900000000L, h.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #17
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    assertTrue(minute1.equals(minute2));
}
 
Example #18
Source File: SecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #19
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up an hour equal to hour zero, 1 January 1900.  Request the 
 * previous hour, it should be null.
 */
public void testFirstHourPrevious() {

    Hour first = new Hour(0, new Day(1, MonthConstants.JANUARY, 1900));
    Hour previous = (Hour) first.previous();
    assertNull(previous);

}
 
Example #20
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Problem for date parsing.
 */
public void testParseHour() {

    // test 1...
    Hour h = Hour.parseHour("2002-01-29 13");
    assertEquals(13, h.getHour());

}
 
Example #21
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * In GMT, the 4pm on 21 Mar 2002 is java.util.Date(1,014,307,200,000L).  
 * Use this to check the hour constructor.
 */
public void testDateConstructor1() {

    TimeZone zone = TimeZone.getTimeZone("GMT");
    Calendar c = new GregorianCalendar(zone);
    Hour h1 = new Hour(new Date(1014307199999L), zone);
    Hour h2 = new Hour(new Date(1014307200000L), zone);

    assertEquals(15, h1.getHour());
    assertEquals(1014307199999L, h1.getLastMillisecond(c));

    assertEquals(16, h2.getHour());
    assertEquals(1014307200000L, h2.getFirstMillisecond(c));

}
 
Example #22
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * In Sydney, the 4pm on 21 Mar 2002 is java.util.Date(1,014,267,600,000L).
 * Use this to check the hour constructor.
 */
public void testDateConstructor2() {

    TimeZone zone = TimeZone.getTimeZone("Australia/Sydney");
    Calendar c = new GregorianCalendar(zone);
    Hour h1 = new Hour(new Date(1014267599999L), zone);
    Hour h2 = new Hour (new Date(1014267600000L), zone);

    assertEquals(15, h1.getHour());
    assertEquals(1014267599999L, h1.getLastMillisecond(c));

    assertEquals(16, h2.getHour());
    assertEquals(1014267600000L, h2.getFirstMillisecond(c));

}
 
Example #23
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up an hour equal to hour zero, 1 January 1900.  Request the previous
 * hour, it should be null.
 */
public void testLastHourPrevious() {

    Hour last = new Hour(23, new Day(31, MonthConstants.DECEMBER, 9999));
    Hour previous = (Hour) last.previous();
    assertEquals(22, previous.getHour());
    assertEquals(9999, previous.getYear());

}
 
Example #24
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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, 8, 1, 59, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Hour h = new Hour(1, 8, 1, 2006);
    assertEquals(cal.getTime(), h.getEnd());
    Locale.setDefault(saved);
}
 
Example #25
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getStart() method.
 */
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Hour h = new Hour(3, 16, 1, 2006);
    assertEquals(cal.getTime(), h.getStart());
    Locale.setDefault(saved);
}
 
Example #26
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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"));
    Hour h = new Hour(1, 1, 1, 1970);
    assertEquals(3599999L, h.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #27
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up an hour equal to hour zero, 1 January 1900.  Request the next 
 * hour, it should be null.
 */
public void testFirstHourNext() {
    Hour first = new Hour(0, new Day(1, MonthConstants.JANUARY, 1900));
    Hour next = (Hour) first.next();
    assertEquals(1, next.getHour());
    assertEquals(1900, next.getYear());
}
 
Example #28
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up an hour equal to hour zero, 1 January 1900.  Request the previous
 * hour, it should be null.
 */
public void testLastHourPrevious() {

    Hour last = new Hour(23, new Day(31, MonthConstants.DECEMBER, 9999));
    Hour previous = (Hour) last.previous();
    assertEquals(22, previous.getHour());
    assertEquals(9999, previous.getYear());

}
 
Example #29
Source File: HourTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up an hour equal to hour zero, 1 January 1900.  Request the next 
 * hour, it should be null.
 */
public void testLastHourNext() {

    Hour last = new Hour(23, new Day(31, MonthConstants.DECEMBER, 9999));
    Hour next = (Hour) last.next();
    assertNull(next);

}
 
Example #30
Source File: MillisecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    Millisecond milli1 = new Millisecond(999, second1);
    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);
    Millisecond milli2 = new Millisecond(999, second2);
    assertTrue(milli1.equals(milli2));
}