Package ch.pollet.jzic.parser

Source Code of ch.pollet.jzic.parser.ZoneParser

package ch.pollet.jzic.parser;

import ch.pollet.jzic.datetime.DateTime;
import ch.pollet.jzic.timezone.Database;
import ch.pollet.jzic.timezone.Zone;
import ch.pollet.jzic.tokenizer.Tokenizer;

/**
*
* @author Christophe Pollet
*/
class ZoneParser {
    private Database db;
    private String currentZoneName;
   
    public ZoneParser(Database db) {
        this.db = db;
    }

    public void continueParsing(Tokenizer st) throws ParserException {
        if (currentZoneName != null) {
            Zone z = new Zone();
            z.setOffset(Parser.parseOffset(st.nextToken()));
            z.setRule(parseRuleName(st));
            z.setFormat(parseFormat(st));
            z.setUntil(parseUntil(st));
           
            db.addZone(currentZoneName, z);
        }
    }

    public void parse(Tokenizer st) throws ParserException {
        currentZoneName = st.nextToken();

        continueParsing(st);
    }

    private String parseRuleName(Tokenizer st) {
        String name = st.nextToken();
        return (name.equals("-")) ? null : name;
    }

    private String parseFormat(Tokenizer st) {
        return st.nextToken();
    }

    private DateTime parseUntil(Tokenizer st) throws ParserException {
        DateTime dt = new DateTime(st.getFileName(), st.getLineNumber());

        if (!st.hasMoreTokens()) {
            // default max value
            dt.setYear(Integer.MAX_VALUE);
            dt.setMonth(12);
            dt.setDay(31);
            dt.setHour(23);
            dt.setMinute(59);
            dt.setSecond(59);
            dt.setType(DateTime.Type.WALL);
            return dt;
        } else {
            dt.setYear(Integer.parseInt(st.nextToken()));
            dt.setMonth(1);
            dt.setDay(1);
            dt.setHour(0);
            dt.setMinute(0);
            dt.setSecond(0);
            dt.setType(DateTime.Type.WALL);
        }

        return Parser.parseDateTime(st, dt);
    }
}
TOP

Related Classes of ch.pollet.jzic.parser.ZoneParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.