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

com.lowagie.text.utils.NumberUtilities Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package com.lowagie.text.utils;

import java.util.Optional;

public final class NumberUtilities {

    private NumberUtilities() {
    }

    /**
     * Try parse float from string and return {@link Optional#empty()} in case of {@link NumberFormatException}
     *
     * @param value string value
     * @return {@link Optional} containing parsed value or empty
     */
    public static Optional parseFloat(String value) {
        try {
            return Optional.of(Float.parseFloat(value));
        } catch (NumberFormatException e) {
            return Optional.empty();
        }
    }

    /**
     * Try parse int from string and return {@link Optional#empty()} in case of {@link NumberFormatException}
     *
     * @param value string value
     * @return {@link Optional} containing parsed value or empty
     */
    public static Optional parseInt(String value) {
        try {
            return Optional.of(Integer.parseInt(value));
        } catch (NumberFormatException e) {
            return Optional.empty();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy