A simple numbers and boolean parser which returns an Optional and do not raise any Exception.
This library do not have any third party compile time dependencies, the only dependency is Java8.
Use this parser functions to easily integrate in your optional call chain.
Example usage:
Optional.ofNullable(System.getProperty("some.property.key"))
.flatMap(OptionalParsers::parseLong)
.orElse(DEFAULT_VALUE_OF_SOME_PROPERTY);
package com.github.spjoe.optional;
public final class OptionalParsers {
public static Optional<Long> parseLong(final String longString);
public static Optional<Long> parseLong(final String longString, int radix);
public static Optional<Integer> parseInt(final String integerString);
public static Optional<Integer> parseInt(final String integerString, int radix);
public static Optional<BigInteger> parseBigInteger(final String bigIntegerString);
public static Optional<BigInteger> parseBigInteger(final String bigIntegerString, final int radix);
public static Optional<BigDecimal> parseBigDecimal(final String decimalString);
public static Optional<Float> parseFloat(final String floatString);
public static Optional<Double> parseDouble(final String doubleString);
public static Optional<Boolean> parseBoolean(final String booleanString);
}
<dependency>
<groupId>com.github.spjoe</groupId>
<artifactId>optional-parsers</artifactId>
<version>0.0.1</version>
</dependency>
- Initial release of this library