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

fr.manastria.utils.TryParse Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.manastria.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.manastria.utils.FormattingTuple;
import fr.manastria.utils.MessageFormatter;

/**
 *
 * @author Jean-Philippe
 */
public class TryParse {
	
	private static final Logger logger = LoggerFactory.getLogger(TryParse.class);

    public static boolean tryParseInteger(String value, Integer result, Integer defaultValue) {
        result = defaultValue;

        if (value == null) {
            return true;
        }

        try {
            result = Integer.parseInt(value.trim());
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
	
	public static boolean tryParseInteger(String value, Integer result) {
        result = null;

        if (value == null) {
            return true;
        }

        try {
            result = Integer.parseInt(value.trim());
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }


    public static boolean tryParseDouble(String value, Double result, Double defaultValue) {
        result = defaultValue;

        if (value == null) {
            return true;
        }

        try {
            result = Double.parseDouble(value.trim());
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy