Skip to content

Commit

Permalink
Feat: Updated Validator Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 25, 2026
1 parent ada261d commit 5e9017c
Showing 1 changed file with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package edu.ntnu.idi.idatt2003.g40.mappe.utils;

import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -58,29 +56,11 @@ public enum Validator {
VALID_STOCK_SYMBOL(NOT_EMPTY.validationRule.and(s ->
s.length() == 4), "Invalid stock symbol!"),

/**
* Rule that checks if a string represents a positive integer.
* */
VALID_POSITIVE_INT(VALID_INT.validationRule.and(s ->
Integer.parseInt(s) >= 0), "Number is not positive!"),

/**
* Rule that checks if a string represents a valid week. (Greater than 1).
* */
VALID_WEEK(VALID_POSITIVE_INT.validationRule.and(s ->
Integer.parseInt(s) > 0), "Invalid week"),
/**
* Rule that checks if string is not empty,
* and if it can be parsed into a {@link LocalDate} object.
*/
VALID_DATE(NOT_EMPTY.validationRule.and(s -> {
try {
LocalDate.parse(s);
return true;
} catch (DateTimeParseException e) {
return false;
}
}), "Invalid Date!");
VALID_WEEK(VALID_INT.validationRule.and(s ->
Integer.parseInt(s) > 0), "Invalid week");

/** The predicate field set when creating constants. */
private final Predicate<String> validationRule;
Expand Down

0 comments on commit 5e9017c

Please sign in to comment.