java.lang.Object
org.kink_lang.kink.internal.contract.Preconds

public final class Preconds extends Object
Methods for preconditions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkArg(boolean cond, String msg)
    Checks the precondition for an argument.
    static void
    checkElemIndex(int checkedIndex, int size)
    Checks that the checkedIndex argument is a valid element index of a sequence which contains size elements.
    static void
    checkPosIndex(int checkedIndex, int size)
    Checks that the checkedIndex argument is a valid position index of a sequence which contains size elements.
    static void
    checkRange(int from, int to, int size)
    Checks that the index range from and to is valid in the sequence with size.
    static void
    checkState(boolean cond, String msg)
    Checks that precondition for a state.

    Methods inherited from class java.lang.Object

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

    • checkArg

      public static void checkArg(boolean cond, String msg)
      Checks the precondition for an argument.

      If the condition is not met, it throws an IllegalArgumentException with the given message.

      Parameters:
      cond - the precondition.
      msg - the message of the IllegalArgumentException.
      Throws:
      IllegalArgumentException - when the condition is not met.
    • checkState

      public static void checkState(boolean cond, String msg)
      Checks that precondition for a state.

      If the condition is not met, it throws an IllegalStateException with the given message.

      Parameters:
      cond - the precondition.
      msg - the mesage of the IllegalStateException.
      Throws:
      IllegalStateException - when the condition is not met.
    • checkElemIndex

      public static void checkElemIndex(int checkedIndex, int size)
      Checks that the checkedIndex argument is a valid element index of a sequence which contains size elements. Namely, the method checks that checkedIndex is not negative, and smaller than size.
      Parameters:
      checkedIndex - the index to be checked.
      size - the size of a sequence.
      Throws:
      IndexOutOfBoundsException - when checkedIndex is not a valid element index.
    • checkPosIndex

      public static void checkPosIndex(int checkedIndex, int size)
      Checks that the checkedIndex argument is a valid position index of a sequence which contains size elements. Namely, the method checks that checkedIndex is not negative, and smaller than or equal to size.
      Parameters:
      checkedIndex - the index to be checked.
      size - the size of a sequence.
      Throws:
      IndexOutOfBoundsException - when checkedIndex is not a valid position index.
    • checkRange

      public static void checkRange(int from, int to, int size)
      Checks that the index range from and to is valid in the sequence with size.
      Parameters:
      from - the from index.
      to - the to index.
      size - the size of sequence.
      Throws:
      IndexOutOfBoundsException - when from or to is out of bounds.
      IllegalArgumentException - when from is bigger than to.