Package utility
Class Validation
java.lang.Object
utility.Validation
Utility class for performing various validation checks.
This class provides static methods to validate strings and file objects. It includes methods to check if a string represents a percentage or a positive double, and methods to validate file and directory objects.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkDirectory
(File directory) Checks if aFile
object exists, is a directory, and can be read.static void
Checks the validity of aFile
object.static Boolean
Checks if aString
represents a percentage value.static Boolean
Checks if aString
represents a positive double value.
-
Constructor Details
-
Validation
public Validation()
-
-
Method Details
-
isPercentage
Checks if aString
represents a percentage value.This method attempts to parse the input string as a double and checks if the value lies within the range [0.0, 1.0], inclusive. If the parsing fails or the value is out of range, the method returns false.
- Parameters:
s
- TheString
to validate as a percentage.- Returns:
true
if the string represents a valid percentage,false
otherwise.
-
isPositiveDouble
Checks if aString
represents a positive double value.This method attempts to parse the input string as a double and checks if the value is greater than 0.0. If the parsing fails or the value is not positive, the method returns false.
- Parameters:
s
- TheString
to validate as a positive double.- Returns:
true
if the string represents a positive double,false
otherwise.
-
checkFile
Checks the validity of aFile
object.This method validates the given
File
object by ensuring it:- Represents a file (not a directory).
- Exists in the file system.
- Can be read by the application.
- Is not empty.
- Parameters:
file
- TheFile
object to validate.- Throws:
IOException
- If the file is not valid; i.e., one of the conditions is not met.
-
checkDirectory
Checks if aFile
object exists, is a directory, and can be read.This method validates the given
File
object by ensuring it:- Represents a directory (not a file).
- Exists in the file system.
- Can be read by the application.
- Parameters:
directory
- TheFile
object to validate.- Throws:
IOException
- If the file is not valid; i.e., one of the conditions is not met.
-