Class TorqueCondition<T>

java.lang.Object
org.texastorque.torquelib.control.TorqueCondition<T>

public final class TorqueCondition<T> extends Object
A replacement for the if else statments to check for conditions that determine the object to pass to a consumer function. Is about 30-50% slower than using chained if else statements, but can be more readable.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    and(Consumer<T> consumer)
    If the internal value is not null, pass it to a consumer function.
    check(boolean condition, T value)
    A wrapper for TorqueCondition#checkIfElse(), checks a condition and sets the value if the internal value has yet to be set (else if logic).
    checkElse(T value)
    A value to set if the value has yet to be set (else logic).
    checkElseIf(boolean condition, T value)
    Checks a condition and sets the value if the internal value has yet to be set (else if logic).
    checkIf(boolean condition, T value)
    Checks a condition and sets the value regardless (if logic).
    final T
    get()
    Get the internal value.
    static final void
    main(String[] arguments)
     
    Resets the conditional chain.
    static final <T> TorqueCondition<T>
    Creates a new chainable instance of the condition.
    static final <T> TorqueCondition<T>
    start(boolean condition, T value)
    Creates a new chainable instance of the condition and checks a condition to determine if it should set the value.

    Methods inherited from class java.lang.Object

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

    • TorqueCondition

      public TorqueCondition()
  • Method Details

    • start

      public static final <T> TorqueCondition<T> start()
      Creates a new chainable instance of the condition.
      Type Parameters:
      T - The type of the determined value.
      Returns:
      A new conditional chain.
    • reset

      public final TorqueCondition<T> reset()
      Resets the conditional chain.
      Returns:
      The conditional chain.
    • check

      public final TorqueCondition<T> check(boolean condition, T value)
      A wrapper for TorqueCondition#checkIfElse(), checks a condition and sets the value if the internal value has yet to be set (else if logic).
      Parameters:
      condition - The condition.
      value - The value.
      Returns:
      The conditional chain.
    • start

      public static final <T> TorqueCondition<T> start(boolean condition, T value)
      Creates a new chainable instance of the condition and checks a condition to determine if it should set the value.
      Type Parameters:
      T - The type of the determined value.
      Parameters:
      condition - The condition.
      value - The value.
      Returns:
      The conditional chain.
    • checkIf

      public final TorqueCondition<T> checkIf(boolean condition, T value)
      Checks a condition and sets the value regardless (if logic).
      Parameters:
      condition - The condition.
      value - The value.
      Returns:
      The conditional chain.
    • checkElseIf

      public final TorqueCondition<T> checkElseIf(boolean condition, T value)
      Checks a condition and sets the value if the internal value has yet to be set (else if logic).
      Parameters:
      condition - The condition.
      value - The value.
      Returns:
      The conditional chain.
    • checkElse

      public final TorqueCondition<T> checkElse(T value)
      A value to set if the value has yet to be set (else logic).
      Parameters:
      condition - The condition.
      value - The value.
      Returns:
      The conditional chain.
    • get

      public final T get()
      Get the internal value.
      Returns:
      The internal value.
    • and

      public final void and(Consumer<T> consumer)
      If the internal value is not null, pass it to a consumer function.
      Parameters:
      consumer - The consumer function.
    • main

      public static final void main(String[] arguments) throws Exception
      Throws:
      Exception