
fr.manastria.utils.TryParse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jUtilities Show documentation
Show all versions of jUtilities Show documentation
Tools for programming in JAVA.
/*
* 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