Class TorqueUtil

java.lang.Object
org.texastorque.torquelib.util.TorqueUtil

public final class TorqueUtil extends Object
Miscellaneous and uncatagorized static functions used throughout the codebase.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
    static final class 
     
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final String
    Splits a camel case string into title case.
    static final <T> T
    conditionalApply(boolean use, T value, Function<T,T> function)
    Apply or don't modify a value based on a condition using a transforming function.
    static final <T> void
    Enumerated For (enumeratedFor) is a class that *trys* to implement similar functionality to Python: for i, element in enumerate(iterable): doSomething(i, element) in the form: enumeratedFor(iterable, (i, element) -> { doSomething(i, element); }); So not that much more verbose, but you do have to specify type!
    static final <T> void
    enumeratedFor(T[] array, BiConsumer<Integer,T> f)
    A wrapper for enumeratedFor that supports static arrays.
    static final void
    errorf(String format, Object... args)
    Kills the program and writes an error message with a printf style in red.
    static final StackTraceElement
    Get a stack trace element.
    static final String
    group(int leading, int trailing, double... values)
    Appends doubles like an ordered pair in parenthesis.
    static final void
    Automatically kills the program and displays that this method is unimplemented to the console.
    static final void
    Automatically kills the program and displays that this method is unimplemented to the console.
    static final void
    Automatically kills the program and displays that we are trying to instantiate the constructor of a static class.
    Returns a throwable exception that notifies the developer that they are attempting to instantiate a static class.
    static final double
    A time method that can be used on the robot and on a computer.
    static final <T> TorqueUtil.TimeResult<T>
    time(Supplier<T> f)
     
    static final void
    warnf(String format, Object... args)
    Writes an error message with a printf style in yellow but doesn't kill the program.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • osName

      public static final String osName
    • onRobot

      public static final boolean onRobot
  • Method Details

    • time

      public static final double time()
      A time method that can be used on the robot and on a computer. Should really only be used for relative use.
    • getStackTraceElement

      public static final StackTraceElement getStackTraceElement(int level)
      Get a stack trace element.
      Parameters:
      level - The stack trace level.
      Returns:
      The stack trace element at the desired elevation level.
    • warnf

      public static final void warnf(String format, Object... args)
      Writes an error message with a printf style in yellow but doesn't kill the program.
    • errorf

      public static final void errorf(String format, Object... args)
      Kills the program and writes an error message with a printf style in red.
    • notImplemented

      public static final void notImplemented()
      Automatically kills the program and displays that this method is unimplemented to the console.
    • outOfDate

      public static final void outOfDate()
      Automatically kills the program and displays that this method is unimplemented to the console.
    • staticConstructor

      public static final void staticConstructor()
      Automatically kills the program and displays that we are trying to instantiate the constructor of a static class.
    • staticConstructorError

      public static final UnsupportedOperationException staticConstructorError()
      Returns a throwable exception that notifies the developer that they are attempting to instantiate a static class. Call this in static constructors like so: throw staticConstructor();
      Returns:
      The throwable exception.
    • enumeratedFor

      public static final <T> void enumeratedFor(Iterable<T> iterable, BiConsumer<Integer,T> f)
      Enumerated For (enumeratedFor) is a class that *trys* to implement similar functionality to Python: for i, element in enumerate(iterable): doSomething(i, element) in the form: enumeratedFor(iterable, (i, element) -> { doSomething(i, element); }); So not that much more verbose, but you do have to specify type!
      Type Parameters:
      T - Type of the iterable.
      Parameters:
      iterable - The iterable to iterate over.
      f - The functional interface to call.
    • enumeratedFor

      public static final <T> void enumeratedFor(T[] array, BiConsumer<Integer,T> f)
      A wrapper for enumeratedFor that supports static arrays.
      Type Parameters:
      T - Type of the iterable.
      Parameters:
      array - The array to iterate over.
      f - The functional interface to call.
    • time

      public static final <T> TorqueUtil.TimeResult<T> time(Supplier<T> f) throws Exception
      Throws:
      Exception
    • conditionalApply

      public static final <T> T conditionalApply(boolean use, T value, Function<T,T> function)
      Apply or don't modify a value based on a condition using a transforming function.
      Type Parameters:
      T - Type or parameter and return.
      Parameters:
      use - To modify or not to modify.
      value - The input value.
      function - The function that modifies the input value.
      Returns:
      The modified or unmodified value.
    • group

      public static final String group(int leading, int trailing, double... values)
      Appends doubles like an ordered pair in parenthesis.
      Parameters:
      values - Doubles to append.
      Returns:
      The resulting string.
    • camelCaseToTitleCase

      public static final String camelCaseToTitleCase(String s)
      Splits a camel case string into title case.
      Parameters:
      s - Camel case string.
      Returns:
      Title case string.