diff options
author | Nils Schwabe | 2014-07-04 10:54:33 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-07-04 10:54:33 +0200 |
commit | b6aa208c55cc090b5c2695889cb551dc2a98755f (patch) | |
tree | 67c5509e2626866cedb7e148e9b86574be3f3e4c /src/main/java/org/openslx/imagemaster/util/Util.java | |
parent | Merge branch 'master' of git.openslx.org:bwlp/masterserver (diff) | |
download | masterserver-b6aa208c55cc090b5c2695889cb551dc2a98755f.tar.gz masterserver-b6aa208c55cc090b5c2695889cb551dc2a98755f.tar.xz masterserver-b6aa208c55cc090b5c2695889cb551dc2a98755f.zip |
Change loading and checking of properties
Remove DbFtpUser
Add NotNullOrEmptyFatal to Utils
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/util/Util.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/util/Util.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java index fb13c86..9d5c5fb 100644 --- a/src/main/java/org/openslx/imagemaster/util/Util.java +++ b/src/main/java/org/openslx/imagemaster/util/Util.java @@ -17,7 +17,7 @@ public class Util * exit code 2. * * This comes in handy if something must not be null, and you want - * user friendsly output. A perfect example would be reading settings + * user friendly output. A perfect example would be reading settings * from a config file. You can use this on mandatory fields. * * @param something the object to compare to null @@ -32,6 +32,25 @@ public class Util System.exit( 2 ); } } + + /** + * Check if String is null or empty, abort program if so. + * An optional message to be printed can be passed. A stack trace + * will be printed, too. Finally the application terminates with + * exit code 2. + * + * @param something The string you want to check + * @param message The message to be printed if "something" is null or empty + */ + public static void notNullOrEmptyFatal( String something, String message) + { + if ( something == null || something.isEmpty() ) { + if ( message != null ) + log.fatal( "[NOTNULL] " + message ); + log.warn( Thread.currentThread().getStackTrace().toString() ); + System.exit( 2 ); + } + } /** * Static {@link Random} instance. @@ -70,5 +89,18 @@ public class Util } folder.delete(); } + + /** + * Tries to parse an int. Returns 0 on error. + * @param s The strig to parse + * @return The parsed int or 0 on error + */ + public static int tryToParseInt(String s) { + try { + return Integer.parseInt( s ); + } catch (NumberFormatException e) { + return 0; + } + } } |