import java.util.List;
class DataValidator {
/**
* Validates a list of strings, checking for nulls and empty strings.
* @param data The list of strings to validate.
* @return True if the list is valid, false otherwise.
*/
public static boolean validateStringList(List<String> data) {
if (data == null) {
return false; // Null list is invalid
}
for (String item : data) {
if (item == null || item.isEmpty()) {
return false; // Null or empty string is invalid
}
}
return true; // All strings are valid
}
/**
* Validates a list of integers, checking for nulls and negative values.
* @param data The list of integers to validate.
* @return True if the list is valid, false otherwise.
*/
public static boolean validateIntegerList(List<Integer> data) {
if (data == null) {
return false;
}
for (Integer item : data) {
if (item == null || item < 0) {
return false; // Null or negative integer is invalid
}
}
return true;
}
/**
* Validates a list of doubles, checking for nulls and NaN values.
* @param data The list of doubles to validate.
* @return True if the list is valid, false otherwise.
*/
public static boolean validateDoubleList(List<Double> data) {
if (data == null) {
return false;
}
for (Double item : data) {
if (item == null || Double.isNaN(item)) {
return false; // Null or NaN double is invalid
}
}
return true;
}
/**
* Validates a list of booleans, checking for nulls.
* @param data The list of booleans to validate.
* @return True if the list is valid, false otherwise.
*/
public static boolean validateBooleanList(List<Boolean> data) {
if (data == null) {
return false;
}
for (Boolean item : data) {
if (item == null) {
return false; // Null boolean is invalid
}
}
return true;
}
/**
* Validates a list of objects, checking for nulls.
* @param data The list of objects to validate.
* @param <T> The type of the objects in the list.
* @return True if the list is valid, false otherwise.
*/
public static <T> boolean validateObjectList(List<T> data) {
if (data == null) {
return false;
}
for (T item : data) {
if (item == null) {
return false; // Null object is invalid
}
}
return true;
}
}
Add your comment