Class Utils

java.lang.Object
org.tweetyproject.web.services.Utils

public final class Utils extends Object
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 Details

    • getDungTheory

      public static DungTheory getDungTheory(int nr_of_arguments, List<List<Integer>> atttacks)
      Creates a DungTheory from the given number of arguments and attack relations.
      Parameters:
      nr_of_arguments - The number of arguments in the DungTheory.
      atttacks - The attack relations represented as a list of lists of integers.
      Returns:
      A DungTheory constructed from the given arguments and attacks.
    • returnLowerCase

      public static String returnLowerCase(String stringInput)
      Converts the input string to lowercase.
      Parameters:
      stringInput - The input string to be converted.
      Returns:
      The input string in lowercase.
    • splitStringInput

      public static String[] splitStringInput(String stringInput, String delimiter)
      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.
    • getTimoutUnit

      public static TimeUnit getTimoutUnit(String unit)
      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

      public static int checkUserTimeout(int user_timeout, int server_timeout, TimeUnit unit)
      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.