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

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

Introduction

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

Prototype

private static int stringToWeek(String s) 

Source Link

Document

Converts a string to a week.

Usage

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

/**
 * Parses the string argument as a week.
 * <P>//from   w  w  w . j  ava 2  s .  co  m
 * This method is required to accept the format "YYYY-Wnn".  It will also
 * accept "Wnn-YYYY". Anything else, at the moment, is a bonus.
 *
 * @param s  string to parse.
 *
 * @return <code>null</code> if the string is not parseable, the week
 *         otherwise.
 */
public static Week parseWeek(String s) {

    Week result = null;
    if (s != null) {

        // trim whitespace from either end of the string
        s = s.trim();

        int i = Week.findSeparator(s);
        if (i != -1) {
            String s1 = s.substring(0, i).trim();
            String s2 = s.substring(i + 1, s.length()).trim();

            Year y = Week.evaluateAsYear(s1);
            int w;
            if (y != null) {
                w = Week.stringToWeek(s2);
                if (w == -1) {
                    throw new TimePeriodFormatException("Can't evaluate the week.");
                }
                result = new Week(w, y);
            } else {
                y = Week.evaluateAsYear(s2);
                if (y != null) {
                    w = Week.stringToWeek(s1);
                    if (w == -1) {
                        throw new TimePeriodFormatException("Can't evaluate the week.");
                    }
                    result = new Week(w, y);
                } else {
                    throw new TimePeriodFormatException("Can't evaluate the year.");
                }
            }

        } else {
            throw new TimePeriodFormatException("Could not find separator.");
        }

    }
    return result;

}