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

com.poiji.parser.BooleanParser Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package com.poiji.parser;

public class BooleanParser implements Parser {

    @Override
    public Boolean parse(String value) {
        if ("true".equalsIgnoreCase(value.trim())) {
            return true;
        }

        if ("false".equalsIgnoreCase(value.trim())) {
            return false;
        }

        /* LibreOffice compatibility:
         *
         * LibreOffice booleans are stored as formula =TRUE() or =FALSE() which is parsed by POI to 1 or 0.
         */
        if ("1".equals(value.trim())) {
            return true;
        }

        if ("0".equals(value.trim())) {
            return false;
        }

        throw new BooleanParseException(value);
    }
    @SuppressWarnings("serial")
    public static class BooleanParseException extends RuntimeException {
        public BooleanParseException(String value) {
            super("Can't parse value to Boolean: " + value);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy