Class Utilities
java.lang.Object
org.eu.zajc.akiwrapper.core.utils.Utilities
Note: This is an internal class and its internals are subject to change
without prior deprecation. Use with caution.
Various general utilities for use within Akiwrapper.
Various general utilities for use within Akiwrapper.
- Author:
- Marko Zajc
-
Method Summary
Modifier and TypeMethodDescriptionstatic <X extends Throwable>
RuntimeExceptionasUnchecked(Throwable ex) Rethrows a checked exception as unchecked using generics trickery (the exception is not changed or wrapped in aRuntimeException- it is thrown as-is).static doubleAttempts to parse a string usingDouble.parseDouble(String), throwing aMalformedResponseExceptionon failure.static intAttempts to parse a string usingInteger.parseInt(String), throwing aMalformedResponseExceptionon failure.static longAttempts to parse a string usingLong.parseLong(String), throwing aMalformedResponseExceptionon failure.static voidsleepUnchecked(long millis) AThread.sleep(long)-like method that throwsInterruptedException.
-
Method Details
-
asUnchecked
Rethrows a checked exception as unchecked using generics trickery (the exception is not changed or wrapped in aRuntimeException- it is thrown as-is).- Type Parameters:
X- the exception type- Parameters:
ex- the exception to throw as unchecked- Returns:
- the exception itself to support
throws asUnchecked(e);. Note that it is thrown in this method and nothing is ever returned - Throws:
X- the exception you provide. Always thrown.
-
parseInt
Attempts to parse a string usingInteger.parseInt(String), throwing aMalformedResponseExceptionon failure.- Parameters:
s- the string to parse.- Returns:
- the parsed int.
- Throws:
MalformedResponseException- if aNumberFormatExceptionis thrown.
-
parseLong
Attempts to parse a string usingLong.parseLong(String), throwing aMalformedResponseExceptionon failure.- Parameters:
s- the string to parse.- Returns:
- the parsed long.
- Throws:
MalformedResponseException- if aNumberFormatExceptionis thrown.
-
parseDouble
Attempts to parse a string usingDouble.parseDouble(String), throwing aMalformedResponseExceptionon failure.- Parameters:
s- the string to parse.- Returns:
- the parsed double.
- Throws:
MalformedResponseException- if aNumberFormatExceptionis thrown.
-
sleepUnchecked
public static void sleepUnchecked(long millis) AThread.sleep(long)-like method that throwsInterruptedException. The exception is not suppressed or wrapped in aRuntimeException, but rather thrown withasUnchecked(Throwable).- Parameters:
millis-
-