1. import java.util.List;
  2. class DataValidator {
  3. /**
  4. * Validates a list of strings, checking for nulls and empty strings.
  5. * @param data The list of strings to validate.
  6. * @return True if the list is valid, false otherwise.
  7. */
  8. public static boolean validateStringList(List<String> data) {
  9. if (data == null) {
  10. return false; // Null list is invalid
  11. }
  12. for (String item : data) {
  13. if (item == null || item.isEmpty()) {
  14. return false; // Null or empty string is invalid
  15. }
  16. }
  17. return true; // All strings are valid
  18. }
  19. /**
  20. * Validates a list of integers, checking for nulls and negative values.
  21. * @param data The list of integers to validate.
  22. * @return True if the list is valid, false otherwise.
  23. */
  24. public static boolean validateIntegerList(List<Integer> data) {
  25. if (data == null) {
  26. return false;
  27. }
  28. for (Integer item : data) {
  29. if (item == null || item < 0) {
  30. return false; // Null or negative integer is invalid
  31. }
  32. }
  33. return true;
  34. }
  35. /**
  36. * Validates a list of doubles, checking for nulls and NaN values.
  37. * @param data The list of doubles to validate.
  38. * @return True if the list is valid, false otherwise.
  39. */
  40. public static boolean validateDoubleList(List<Double> data) {
  41. if (data == null) {
  42. return false;
  43. }
  44. for (Double item : data) {
  45. if (item == null || Double.isNaN(item)) {
  46. return false; // Null or NaN double is invalid
  47. }
  48. }
  49. return true;
  50. }
  51. /**
  52. * Validates a list of booleans, checking for nulls.
  53. * @param data The list of booleans to validate.
  54. * @return True if the list is valid, false otherwise.
  55. */
  56. public static boolean validateBooleanList(List<Boolean> data) {
  57. if (data == null) {
  58. return false;
  59. }
  60. for (Boolean item : data) {
  61. if (item == null) {
  62. return false; // Null boolean is invalid
  63. }
  64. }
  65. return true;
  66. }
  67. /**
  68. * Validates a list of objects, checking for nulls.
  69. * @param data The list of objects to validate.
  70. * @param <T> The type of the objects in the list.
  71. * @return True if the list is valid, false otherwise.
  72. */
  73. public static <T> boolean validateObjectList(List<T> data) {
  74. if (data == null) {
  75. return false;
  76. }
  77. for (T item : data) {
  78. if (item == null) {
  79. return false; // Null object is invalid
  80. }
  81. }
  82. return true;
  83. }
  84. }

Add your comment