diff options
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java index d69b7746..5b36a18c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java @@ -32,4 +32,21 @@ public class FormatHelper { return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } + /** + * Parse the given String as a base10 integer. + * If the string does not represent a valid integer, return the given + * default value. + * + * @param value string representation to parse to an int + * @param defaultValue fallback value if given string can't be parsed + * @return + */ + public static int parseInt(String value, int defaultValue) { + try { + return Integer.parseInt(value); + } catch (Exception e) { + return defaultValue; + } + } + } |