Guava provides a number of precondition checking utilities. It’s Preconditions
class. You can use it into your project.
Usage
checkArgument(boolean)
Checks that the boolean is true. Use for validating arguments to methods.
checkNotNull(T)
Checks that the value is not null. Returns the value directly, so you can use checkNotNull(value) inline.
checkElementIndex(int index, int size)
Checks that index is a valid element index into a list, string, or array with the specified size. An element index may range from 0 inclusive to size exclusive. You don’t pass the list, string, or array directly; you just pass its size.
Returns index.
checkPositionIndex(int index, int size)
Checks that index is a valid position index into a list, string, or array with the specified size. A position index may range from 0 inclusive to size inclusive. You don’t pass the list, string, or array directly; you just pass its size.
Returns index.
Example
1 |
|