summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satserver/util/Util.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/satserver/util/Util.java')
-rw-r--r--src/main/java/org/openslx/satserver/util/Util.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/satserver/util/Util.java b/src/main/java/org/openslx/satserver/util/Util.java
index 262fd56..2ffe261 100644
--- a/src/main/java/org/openslx/satserver/util/Util.java
+++ b/src/main/java/org/openslx/satserver/util/Util.java
@@ -118,6 +118,24 @@ public class Util
}
/**
+ * Parse the given String as a base10 long.
+ * If the string does not represent a valid long, return the given
+ * default value.
+ *
+ * @param value string representation to parse to an long
+ * @param defaultValue fallback value if given string can't be parsed
+ * @return
+ */
+ public static long parseLong( String value, long defaultValue )
+ {
+ try {
+ return Long.parseLong( value );
+ } catch ( Exception e ) {
+ return defaultValue;
+ }
+ }
+
+ /**
* Compare two strings for equality.
* null and "" are not considered equal.
*/