Example usage for org.jfree.data.time Week Week

List of usage examples for org.jfree.data.time Week Week

Introduction

In this page you can find the example usage for org.jfree.data.time Week Week.

Prototype

public Week(Date time, TimeZone zone) 

Source Link

Document

Creates a time period for the week in which the specified date/time falls, calculated relative to the specified time zone.

Usage

From source file:org.jfree.data.time.WeekTest.java

/**
 * Common test setup./*from   w  w  w  . java  2 s . c o m*/
 */
@Before
public void setUp() {
    this.w1Y1900 = new Week(1, 1900);
    this.w2Y1900 = new Week(2, 1900);
    this.w51Y9999 = new Week(51, 9999);
    this.w52Y9999 = new Week(52, 9999);
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * Tests the equals method.//w  w w.j a v a  2s  .c o m
 */
@Test
public void testEquals() {
    Week w1 = new Week(1, 2002);
    Week w2 = new Week(1, 2002);
    assertTrue(w1.equals(w2));
    assertTrue(w2.equals(w1));

    w1 = new Week(2, 2002);
    assertFalse(w1.equals(w2));
    w2 = new Week(2, 2002);
    assertTrue(w1.equals(w2));

    w1 = new Week(2, 2003);
    assertFalse(w1.equals(w2));
    w2 = new Week(2, 2003);
    assertTrue(w1.equals(w2));
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from  ww w.ja  v  a2  s. c  o m
@Test
public void testSerialization() {
    Week w1 = new Week(24, 1999);
    Week w2 = (Week) TestUtilities.serialised(w1);
    assertEquals(w1, w2);
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * Two objects that are equal are required to return the same hashCode.
 *//*from w  w w  . j  av a  2  s  .c om*/
@Test
public void testHashcode() {
    Week w1 = new Week(2, 2003);
    Week w2 = new Week(2, 2003);
    assertTrue(w1.equals(w2));
    int h1 = w1.hashCode();
    int h2 = w2.hashCode();
    assertEquals(h1, h2);
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * The {@link Week} class is immutable, so should not be {@link Cloneable}.
 *///from w ww  .ja  v a  2  s .co  m
@Test
public void testNotCloneable() {
    Week w = new Week(1, 1999);
    assertFalse(w instanceof Cloneable);
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * The first week in 2005 should span the range:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104710400000 | 1105315199999 |  3-Jan-2005 | 9-Jan-2005
 * Europe/Paris     | 1104706800000 | 1105311599999 |  3-Jan-2005 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 *
 * In London and Paris, Monday is the first day of the week, while in the
 * US it is Sunday./* w  ww . j a  v  a 2  s  .  c  om*/
 *
 * Previously, we were using these values, but see Java Bug ID 4960215:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104105600000 | 1104710399999 | 27-Dec-2004 | 2-Jan-2005
 * Europe/Paris     | 1104102000000 | 1104706799999 | 27-Dec-2004 | 2-Jan-2005
 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005
 */
@Test
public void testWeek12005() {
    Week w1 = new Week(1, 2005);
    Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"), Locale.UK);
    c1.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215
    assertEquals(1104710400000L, w1.getFirstMillisecond(c1));
    assertEquals(1105315199999L, w1.getLastMillisecond(c1));
    Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE);
    c2.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215
    assertEquals(1104706800000L, w1.getFirstMillisecond(c2));
    assertEquals(1105311599999L, w1.getLastMillisecond(c2));
    Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"), Locale.US);
    assertEquals(1104037200000L, w1.getFirstMillisecond(c3));
    assertEquals(1104641999999L, w1.getLastMillisecond(c3));
}

From source file:org.infoglue.deliver.util.charts.TimeSeriesDiagram.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset.//from w  w  w  .j ava2s. c om
 */
private XYDataset createDataset() throws Exception {
    TimeSeriesCollection timeSeriesDataset = new TimeSeriesCollection();

    Document document = new DOMBuilder().getDocument(this.xmlData);
    this.writeDebug(document);

    Element headerElement = (Element) document.selectSingleNode("//chartHeader");
    this.header = headerElement.getText();
    Element axisYHeaderElement = (Element) document.selectSingleNode("//axisYHeader");
    this.axisYHeader = axisYHeaderElement.getText();
    Element axisXHeaderElement = (Element) document.selectSingleNode("//axisXHeader");
    this.axisXHeader = axisXHeaderElement.getText();
    Element timeGranularityElement = (Element) document.selectSingleNode("//timeGranularity");
    this.timeGranulariry = timeGranularityElement.getText();
    Element dateFormatElement = (Element) document.selectSingleNode("//dateFormat");
    this.dateFormat = dateFormatElement.getText();

    List series = document.selectNodes("//Series");

    Iterator seriesIterator = series.iterator();
    while (seriesIterator.hasNext()) {
        Element serieElement = (Element) seriesIterator.next();
        String serieName = serieElement.attributeValue("name");

        TimeSeries s1 = null;
        if (this.timeGranulariry.equalsIgnoreCase("Month"))
            s1 = new TimeSeries(serieName, Month.class);
        else if (this.timeGranulariry.equalsIgnoreCase("Week"))
            s1 = new TimeSeries(serieName, Week.class);

        List items = serieElement.selectNodes("Item");
        Iterator itemsIterator = items.iterator();
        while (itemsIterator.hasNext()) {
            Element itemElement = (Element) itemsIterator.next();
            Element yearElement = (Element) itemElement.selectSingleNode("yearId");
            Element timeElement = (Element) itemElement.selectSingleNode("timeId");
            Element valueElement = (Element) itemElement.selectSingleNode("value");
            String year = yearElement.getText();
            String time = timeElement.getText();
            String value = valueElement.getText();

            if (this.timeGranulariry.equalsIgnoreCase("Month"))
                s1.add(new Month(new Integer(time).intValue(), new Integer(year).intValue()), new Float(value));
            else if (this.timeGranulariry.equalsIgnoreCase("Week"))
                s1.add(new Week(new Integer(time).intValue(), new Integer(year).intValue()), new Float(value));
        }

        timeSeriesDataset.addSeries(s1);
        //timeSeriesDataset.addSeries(s2);

        timeSeriesDataset.setDomainIsPointsInTime(true);

    }

    return timeSeriesDataset;

}

From source file:org.jfree.data.time.WeekTest.java

/**
 * The 53rd week in 2004 in London and Paris should span the range:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * Europe/London    | 1104105600000 | 1104710399999 | 27-Dec-2004 | 02-Jan-2005
 * Europe/Paris     | 1104102000000 | 1104706799999 | 27-Dec-2004 | 02-Jan-2005
 *
 * The 53rd week in 2005 in New York should span the range:
 *
 * TimeZone         | Start Millis  | End Millis    | Start Date  | End Date
 * -----------------+---------------+---------------+-------------+------------
 * America/New_York | 1135486800000 | 1136091599999 | 25-Dec-2005 | 31-Dec-2005
 *
 * In London and Paris, Monday is the first day of the week, while in the
 * US it is Sunday.//from  www  .ja  v  a  2s.  co m
 */
@Test
public void testWeek532005() {
    Week w1 = new Week(53, 2004);
    Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"), Locale.UK);
    c1.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215
    assertEquals(1104105600000L, w1.getFirstMillisecond(c1));
    assertEquals(1104710399999L, w1.getLastMillisecond(c1));
    Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE);
    c2.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215
    assertEquals(1104102000000L, w1.getFirstMillisecond(c2));
    assertEquals(1104706799999L, w1.getLastMillisecond(c2));
    w1 = new Week(53, 2005);
    Calendar c3 = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"), Locale.US);
    assertEquals(1135486800000L, w1.getFirstMillisecond(c3));
    assertEquals(1136091599999L, w1.getLastMillisecond(c3));
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * A test case for bug 1448828.//from   w ww .j  a va2s. c o m
 */
@Test
public void testBug1448828() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    try {
        Week w = new Week(new Date(1136109830000l), TimeZone.getTimeZone("GMT"));
        assertEquals(2005, w.getYearValue());
        assertEquals(52, w.getWeek());
    } finally {
        Locale.setDefault(saved);
    }
}

From source file:org.jfree.data.time.WeekTest.java

/**
 * A test case for bug 1498805.//from   ww w.  j  a v a2s.c o  m
 */
@Test
public void testBug1498805() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    try {
        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());
    } finally {
        Locale.setDefault(saved);
    }
}