All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blazebit.text.PeriodFormat Maven / Gradle / Ivy

There is a newer version: 1.6.11
Show newest version
/*
 * Copyright 2011 Blazebit
 */
package com.blazebit.text;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * @author Christian Beikov
 * @since 0.1.9
 */
public class PeriodFormat extends AbstractFormat {
    private static final long serialVersionUID = 1L;
    private static final Class PERIOD_CLASS;
    private static final Method PARSE_METHOD;

    static {
        try {
            PERIOD_CLASS = Class.forName("java.time.Period");
            PARSE_METHOD = PERIOD_CLASS.getMethod("parse", CharSequence.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public PeriodFormat() {
        super(PERIOD_CLASS);
    }

    public Serializable parse(String value, ParserContext context) {
        try {
            return (Serializable) PARSE_METHOD.invoke(null, value);
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy