dev.marksman.collectionviews.Validation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collection-views Show documentation
Show all versions of collection-views Show documentation
Low overhead, protected views over Java collections
package dev.marksman.collectionviews;
import java.util.Objects;
final class Validation {
private Validation() {
}
static void requirePositive(String paramName, int value) {
if (value < 1) {
throw new IllegalArgumentException(paramName + " must be >= 1");
}
}
static void requireNonNegative(String paramName, int value) {
if (value < 0) {
throw new IllegalArgumentException(paramName + " must be >= 0");
}
}
static void validateSlice(int startIndex, int endIndexExclusive) {
requireNonNegative("startIndex", startIndex);
requireNonNegative("endIndexExclusive", endIndexExclusive);
}
static void validateSlice(int startIndex, int endIndexExclusive, A source) {
validateSlice(startIndex, endIndexExclusive);
Objects.requireNonNull(source);
}
static void validateCopyFrom(int maxCount, A source) {
Validation.requireNonNegative("maxCount", maxCount);
Objects.requireNonNull(source);
}
static void validateTake(int count, A source) {
validateTake(count);
Objects.requireNonNull(source);
}
static void validateTake(int count) {
Validation.requireNonNegative("count", count);
}
static void validateDrop(int count, A source) {
validateDrop(count);
Objects.requireNonNull(source);
}
static void validateDrop(int count) {
Validation.requireNonNegative("count", count);
}
static void validateFill(int count) {
Validation.requireNonNegative("count", count);
}
static void validateNonEmptyFill(int count) {
Validation.requirePositive("count", count);
}
}