Package org.tweetyproject.web.services
Class Utils
java.lang.Object
org.tweetyproject.web.services.Utils
Utility class providing various helper methods for common operations.
This class includes methods for creating DungTheory from attack relations,
manipulating strings, handling timeouts, and converting time units.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckUserTimeout(int user_timeout, int server_timeout, TimeUnit unit) Checks and adjusts the user-defined timeout based on the server timeout and time unit.static TimeUnitgetTimeoutUnit(String unit) Gets the corresponding TimeUnit based on the provided string representation.static StringreturnLowerCase(String stringInput) Converts the input string to lowercase.static <T> javafx.util.Pair<T,Long> runServicesWithTimeout(Future<T> future, long timeout, TimeUnit unit) Runs a service with a specified timeout and returns the result along with the execution time.static String[]splitStringInput(String stringInput, String delimiter) Splits the input string using the specified delimiter.
-
Method Details
-
returnLowerCase
Converts the input string to lowercase.- Parameters:
stringInput- The input string to be converted.- Returns:
- The input string in lowercase.
-
splitStringInput
Splits the input string using the specified delimiter.- Parameters:
stringInput- The input string to be split.delimiter- The delimiter used for splitting the string.- Returns:
- An array of strings resulting from the split operation.
-
getTimeoutUnit
Gets the corresponding TimeUnit based on the provided string representation.- Parameters:
unit- The string representation of the time unit ("ms" for milliseconds, "sec" for seconds).- Returns:
- The TimeUnit corresponding to the input string.
-
runServicesWithTimeout
public static <T> javafx.util.Pair<T,Long> runServicesWithTimeout(Future<T> future, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Runs a service with a specified timeout and returns the result along with the execution time.- Type Parameters:
T- The type of the result.- Parameters:
future- The Future representing the result of an asynchronous computation.timeout- The timeout duration.unit- The TimeUnit of the timeout.- Returns:
- A Pair containing the result and the execution time.
- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If the computation threw an exception.TimeoutException- If the computation did not complete before the timeout.
-
checkUserTimeout
Checks and adjusts the user-defined timeout based on the server timeout and time unit.- Parameters:
user_timeout- The user-defined timeout.server_timeout- The server-defined timeout.unit- The TimeUnit of the timeouts.- Returns:
- The adjusted user-defined timeout.
-