java.lang.Object
org.kink_lang.kink.internal.contract.Preconds
Methods for preconditions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks the precondition for an argument.static voidcheckElemIndex(int checkedIndex, int size) Checks that thecheckedIndexargument is a valid element index of a sequence which containssizeelements.static voidcheckPosIndex(int checkedIndex, int size) Checks that thecheckedIndexargument is a valid position index of a sequence which containssizeelements.static voidcheckRange(int from, int to, int size) Checks that the index rangefromandtois valid in the sequence withsize.static voidcheckState(boolean cond, String msg) Checks that precondition for a state.
-
Method Details
-
checkArg
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
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 thecheckedIndexargument is a valid element index of a sequence which containssizeelements. Namely, the method checks thatcheckedIndexis not negative, and smaller thansize.- Parameters:
checkedIndex- the index to be checked.size- the size of a sequence.- Throws:
IndexOutOfBoundsException- whencheckedIndexis not a valid element index.
-
checkPosIndex
public static void checkPosIndex(int checkedIndex, int size) Checks that thecheckedIndexargument is a valid position index of a sequence which containssizeelements. Namely, the method checks thatcheckedIndexis not negative, and smaller than or equal tosize.- Parameters:
checkedIndex- the index to be checked.size- the size of a sequence.- Throws:
IndexOutOfBoundsException- whencheckedIndexis not a valid position index.
-
checkRange
public static void checkRange(int from, int to, int size) Checks that the index rangefromandtois valid in the sequence withsize.- Parameters:
from- the from index.to- the to index.size- the size of sequence.- Throws:
IndexOutOfBoundsException- whenfromortois out of bounds.IllegalArgumentException- whenfromis bigger thanto.
-