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: 1.2.2.1-jre17
Show newest version
package com.lowagie.text.utils;

import java.util.Optional;
import javax.annotation.Nonnull;

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
     */
    @Nonnull
    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
     */
    @Nonnull
    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