Skip to content

A utility class which provides parse functions. This functions are designed to be used in the java.util.Optional#flatMap(Function) method as parameter.

License

Notifications You must be signed in to change notification settings

spjoe/optional-parsers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status Optional Parsers

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.

Motivation

Use this parser functions to easily integrate in your optional call chain.

Usage

Example usage:

Optional.ofNullable(System.getProperty("some.property.key"))
        .flatMap(OptionalParsers::parseLong)
        .orElse(DEFAULT_VALUE_OF_SOME_PROPERTY);

API

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);
}

Maven

    <dependency>
        <groupId>com.github.spjoe</groupId>
        <artifactId>optional-parsers</artifactId>
        <version>0.0.1</version>
    </dependency>

Changelog

v0.0.1

Released at 26-03-2016

  • Initial release of this library

About

A utility class which provides parse functions. This functions are designed to be used in the java.util.Optional#flatMap(Function) method as parameter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages