NOTICKET: Add Javadoc for de.hitec.nhplus.utils
All checks were successful
Quality Check / Linting Check (push) Successful in 12s
Quality Check / Javadoc Check (push) Successful in 20s
Quality Check / Linting Check (pull_request) Successful in 12s
Quality Check / Javadoc Check (pull_request) Successful in 21s

Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
Dominik Säume 2024-05-13 18:27:57 +02:00
parent 0ea3d92cc0
commit e5aaa9afab
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
2 changed files with 118 additions and 29 deletions

View file

@ -4,23 +4,43 @@ import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
/**
* A Utility Class, Holding Utility Methods for Date Conversion.
* @author Bernd Heideman
*/
public class DateConverter { public class DateConverter {
private static final String DATE_FORMAT = "yyyy-MM-dd"; private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String TIME_FORMAT = "HH:mm"; private static final String TIME_FORMAT = "HH:mm";
/**
* @param date A Date-{@link String} in the Format: yyyy-MM-dd.
* @return The Converted Date-{@link String} as {@link LocalDate}.
*/
public static LocalDate convertStringToLocalDate(String date) { public static LocalDate convertStringToLocalDate(String date) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT)); return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT));
} }
/**
* @param time A Time-{@link String} in the Format: HH:mm.
* @return The Converted Time-{@link String} as {@link LocalTime}.
*/
public static LocalTime convertStringToLocalTime(String time) { public static LocalTime convertStringToLocalTime(String time) {
return LocalTime.parse(time, DateTimeFormatter.ofPattern(TIME_FORMAT)); return LocalTime.parse(time, DateTimeFormatter.ofPattern(TIME_FORMAT));
} }
/**
* @param date A {@link LocalDate} which should be converted to a {@link String}.
* @return The Converted {@link LocalDate} in the Format: yyy-MM-dd.
*/
public static String convertLocalDateToString(LocalDate date) { public static String convertLocalDateToString(LocalDate date) {
return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT));
} }
/**
* @param time A {@link LocalTime} which should be converted to a {@link String}.
* @return The Converted {@link LocalTime} in the Format: HH:mm.
*/
public static String convertLocalTimeToString(LocalTime time) { public static String convertLocalTimeToString(LocalTime time) {
return time.format(DateTimeFormatter.ofPattern(TIME_FORMAT)); return time.format(DateTimeFormatter.ofPattern(TIME_FORMAT));
} }

View file

@ -5,8 +5,19 @@ import javafx.scene.control.Alert;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
public class Validator /**
{ * A Utility CLass, For Validating all kind of Data.
*
* @author Dominik Säume
* @author Ole Kück
*/
public class Validator {
/**
* Shows a Modal with a Specific Validation Error.
*
* @param type The Type for which a Validation Error should be shown as {@link String}.
*/
public static void showValidationError(String type) { public static void showValidationError(String type) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error"); alert.setTitle("Error");
@ -14,6 +25,12 @@ public class Validator
alert.setContentText("Invalid " + type + " !"); alert.setContentText("Invalid " + type + " !");
alert.showAndWait(); alert.showAndWait();
} }
/**
* Validate that a {@link String} is a Valid Date.
*
* @param text The Date-{@link String} to Validate.
*/
public static boolean isValidDate(String text) { public static boolean isValidDate(String text) {
if (text.isBlank()) { if (text.isBlank()) {
return false; return false;
@ -25,6 +42,12 @@ public class Validator
} }
return true; return true;
} }
/**
* Validate that a {@link LocalDate} is a Valid Date for Storage in the Database.
*
* @param date The {@link LocalDate} to Validate.
*/
public static boolean isValidDate(LocalDate date) { public static boolean isValidDate(LocalDate date) {
if (date == null) { if (date == null) {
return false; return false;
@ -36,6 +59,12 @@ public class Validator
} }
return true; return true;
} }
/**
* Validate that a {@link String} is a Valid Time.
*
* @param text The Time-{@link String} to Validate.
*/
public static boolean isValidTime(String text) { public static boolean isValidTime(String text) {
if (text.isBlank()) { if (text.isBlank()) {
return false; return false;
@ -47,6 +76,13 @@ public class Validator
} }
return true; return true;
} }
/**
* Validate that two Time-{@link String}s are a Valid Time-Range.
*
* @param start The starting Time-{@link String}.
* @param end The ending Time-{@link String}.
*/
public static boolean isValidTimeRange(String start, String end) { public static boolean isValidTimeRange(String start, String end) {
if ( if (
!isValidTime(start) || !isValidTime(end) !isValidTime(start) || !isValidTime(end)
@ -59,24 +95,57 @@ public class Validator
} }
/**
* Validate that a {@link String} is a Valid Description.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidDescription(String text) { public static boolean isValidDescription(String text) {
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a Valid First-Name.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidFirstName(String text) { public static boolean isValidFirstName(String text) {
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a Valid Sur-Name.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidSurName(String text) { public static boolean isValidSurName(String text) {
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a Valid Phone-Number.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidPhoneNumber(String text) { public static boolean isValidPhoneNumber(String text) {
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a Valid Care-Level.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidCareLevel(String text) { public static boolean isValidCareLevel(String text) {
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a Valid Room-Number.
*
* @param text The {@link String} to Validate.
*/
public static boolean isValidRoomNumber(String text) { public static boolean isValidRoomNumber(String text) {
return !text.isBlank(); return !text.isBlank();
} }
} }