NOTICKET: Add Javadoc for de.hitec.nhplus.utils
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
0ea3d92cc0
commit
e5aaa9afab
2 changed files with 118 additions and 29 deletions
|
@ -4,23 +4,43 @@ import java.time.LocalDate;
|
|||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* A Utility Class, Holding Utility Methods for Date Conversion.
|
||||
* @author Bernd Heideman
|
||||
*/
|
||||
public class DateConverter {
|
||||
|
||||
private static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
return time.format(DateTimeFormatter.ofPattern(TIME_FORMAT));
|
||||
}
|
||||
|
|
|
@ -5,17 +5,34 @@ import javafx.scene.control.Alert;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class Validator
|
||||
{
|
||||
public static void showValidationError(String type){
|
||||
/**
|
||||
* 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) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Error");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Invalid " + type + " !");
|
||||
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) {
|
||||
if(text.isBlank()){
|
||||
if (text.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -25,8 +42,14 @@ public class Validator
|
|||
}
|
||||
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) {
|
||||
if(date == null){
|
||||
if (date == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -36,21 +59,34 @@ public class Validator
|
|||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isValidTime(String text){
|
||||
if(text.isBlank()){
|
||||
|
||||
/**
|
||||
* Validate that a {@link String} is a Valid Time.
|
||||
*
|
||||
* @param text The Time-{@link String} to Validate.
|
||||
*/
|
||||
public static boolean isValidTime(String text) {
|
||||
if (text.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
DateConverter.convertStringToLocalTime(text);
|
||||
}catch (Exception exception){
|
||||
} catch (Exception exception) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isValidTimeRange(String start, String end){
|
||||
if(
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (
|
||||
!isValidTime(start) || !isValidTime(end)
|
||||
){
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
LocalTime startTime = DateConverter.convertStringToLocalTime(start);
|
||||
|
@ -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) {
|
||||
return !text.isBlank();
|
||||
}
|
||||
public static boolean isValidFirstName(String text){
|
||||
return !text.isBlank();
|
||||
}
|
||||
public static boolean isValidSurName(String text){
|
||||
return !text.isBlank();
|
||||
}
|
||||
public static boolean isValidPhoneNumber(String text){
|
||||
return !text.isBlank();
|
||||
}
|
||||
public static boolean isValidCareLevel(String text){
|
||||
return !text.isBlank();
|
||||
}
|
||||
public static boolean isValidRoomNumber(String text){
|
||||
|
||||
/**
|
||||
* Validate that a {@link String} is a Valid First-Name.
|
||||
*
|
||||
* @param text The {@link String} to Validate.
|
||||
*/
|
||||
public static boolean isValidFirstName(String text) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
return !text.isBlank();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue