Example usage for org.jfree.data.time Year parseYear

List of usage examples for org.jfree.data.time Year parseYear

Introduction

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

Prototype

public static Year parseYear(String s) 

Source Link

Document

Parses the string argument as a year.

Usage

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

/**
 * Tests the year string parser./*w  w w  . j av  a2s.  c o  m*/
 */
@Test
public void testParseYear() {

    Year year = null;

    // test 1...
    try {
        year = Year.parseYear("2000");
    } catch (TimePeriodFormatException e) {
        year = new Year(1900);
    }
    assertEquals(2000, year.getYear());

    // test 2...
    try {
        year = Year.parseYear(" 2001 ");
    } catch (TimePeriodFormatException e) {
        year = new Year(1900);
    }
    assertEquals(2001, year.getYear());

    // test 3...
    try {
        year = Year.parseYear("99");
    } catch (TimePeriodFormatException e) {
        year = new Year(1900);
    }
    assertEquals(99, year.getYear());

}

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

/**
 * Parses the string argument as a quarter.
 * <P>/*  ww  w  .j a  v  a2s  . co m*/
 * This method should accept the following formats: "YYYY-QN" and "QN-YYYY",
 * where the "-" can be a space, a forward-slash (/), comma or a dash (-).
 * @param s A string representing the quarter.
 *
 * @return The quarter.
 */
public static Quarter parseQuarter(String s) {

    // find the Q and the integer following it (remove both from the
    // string)...
    int i = s.indexOf("Q");
    if (i == -1) {
        throw new TimePeriodFormatException("Missing Q.");
    }

    if (i == s.length() - 1) {
        throw new TimePeriodFormatException("Q found at end of string.");
    }

    String qstr = s.substring(i + 1, i + 2);
    int quarter = Integer.parseInt(qstr);
    String remaining = s.substring(0, i) + s.substring(i + 2, s.length());

    // replace any / , or - with a space
    remaining = remaining.replace('/', ' ');
    remaining = remaining.replace(',', ' ');
    remaining = remaining.replace('-', ' ');

    // parse the string...
    Year year = Year.parseYear(remaining.trim());
    Quarter result = new Quarter(quarter, year);
    return result;

}

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

/**
 * Creates a year from a string, or returns <code>null</code> (format
 * exceptions suppressed).// ww  w.java2  s. co  m
 *
 * @param s  the string to parse.
 *
 * @return <code>null</code> if the string is not parseable, the year
 *         otherwise.
 */
private static Year evaluateAsYear(String s) {
    Year result = null;
    try {
        result = Year.parseYear(s);
    } catch (TimePeriodFormatException e) {
        // suppress
    }
    return result;
}

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

/**
 * Creates a year from a string, or returns null (format exceptions
 * suppressed).//from   w  ww . j  av  a  2  s . c  o  m
 *
 * @param s  string to parse.
 *
 * @return <code>null</code> if the string is not parseable, the year
 *         otherwise.
 */
private static Year evaluateAsYear(String s) {

    Year result = null;
    try {
        result = Year.parseYear(s);
    } catch (TimePeriodFormatException e) {
        // suppress
    }
    return result;

}