Interface PathValidator

All Superinterfaces:
ObjectComponent<PathValidator, Path>, ValidatorComponent<PathValidator, Path>

public interface PathValidator extends ValidatorComponent<PathValidator, Path>, ObjectComponent<PathValidator, Path>
Validates the state of a Path.
  • Method Details

    • exists

      PathValidator exists()
      Ensures that the path exists.

      The state of the path may change immediately upon returning from this method. Consequently, special care should be taken when using this method in security-sensitive applications.

      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the path does not exist
    • isAbsolute

      PathValidator isAbsolute()
      Ensures that the path is absolute.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the path is relative
    • isRelative

      PathValidator isRelative()
      Ensures that the path is relative.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if value refers to an absolute path
    • isDirectory

      PathValidator isDirectory(LinkOption... options) throws IOException
      Ensures that the path is a directory.
      Parameters:
      options - options indicating how symbolic links are handled
      Returns:
      this
      Throws:
      NullPointerException - if the value or options are null
      IllegalArgumentException - if the path does not exist or is not a directory
      IOException - if an I/O error occurs while reading the file attributes (e.g., the file does not exist or the user lacks the required permissions)
    • isRegularFile

      PathValidator isRegularFile(LinkOption... options) throws IOException
      Ensures that the path is a regular file.
      Parameters:
      options - options indicating how symbolic links are handled
      Returns:
      this
      Throws:
      NullPointerException - if the value or options are null
      IllegalArgumentException - if the path does not exist or is not a file
      IOException - if an I/O error occurs while reading the file attributes (e.g., the file does not exist or the user lacks the required permissions)
    • isExecutable

      PathValidator isExecutable()
      Ensures that the path exists and the JVM has sufficient privileges to execute it.

      This does not imply that the path is an executable file.

      Returns:
      this
      Throws:
      IllegalArgumentException - if the path does not exist, or the JVM does not have sufficient privileges to execute it
      See Also:
    • isEmpty

      PathValidator isEmpty()
      Ensures that the path is empty.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the path is not empty
    • isNotEmpty

      PathValidator isNotEmpty()
      Ensures that the path is not empty.
      Returns:
      this
      Throws:
      NullPointerException - if the value is null
      IllegalArgumentException - if the path is empty
    • contains

      PathValidator contains(Path expected)
      Ensures that the path contains another path.
      Parameters:
      expected - the other path
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected is null
      IllegalArgumentException - if the path does not contain expected
    • contains

      PathValidator contains(Path expected, String name)
      Ensures that the path contains another path.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the other path
      name - the name of the expected value
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected is null
      IllegalArgumentException - if the path does not contain expected
    • doesNotContain

      PathValidator doesNotContain(Path unwanted)
      Ensures that the path does not contain unwanted.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted path
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the path contains unwanted
    • doesNotContain

      PathValidator doesNotContain(Path unwanted, String name)
      Ensures that the path does not contain unwanted.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted path
      name - the name of the path
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path contains unwanted
    • containsExactly

      PathValidator containsExactly(Collection<Path> expected)
      Ensures that the path contains the same paths as expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if:
      • the path is missing any path in expected
      • the path contains any path that is not in expected
    • containsExactly

      PathValidator containsExactly(Collection<Path> expected, String name)
      Ensures that the path consists of the same paths as expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      name - the name of the expected paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path contains any path that is not in expected
    • doesNotContainExactly

      PathValidator doesNotContainExactly(Collection<Path> unwanted)
      Ensures that the path and unwanted consist of different paths.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the path consists of the same paths as unwanted
    • doesNotContainExactly

      PathValidator doesNotContainExactly(Collection<Path> unwanted, String name)
      Ensures that the path and unwanted consist of different paths.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted elements
      name - the name of the unwanted collection
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path consists of the same paths as unwanted
    • containsAny

      PathValidator containsAny(Collection<Path> expected)
      Ensures that the path contains at least one path in expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the path does not contain any path in expected
    • containsAny

      PathValidator containsAny(Collection<Path> expected, String name)
      Ensures that the path contains at least one path in expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      name - the name of the expected paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path does not contain any path in expected
    • doesNotContainAny

      PathValidator doesNotContainAny(Collection<Path> unwanted)
      Ensures that the path does not contain any of the paths in unwanted.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the path contains any of the paths in unwanted
    • doesNotContainAny

      PathValidator doesNotContainAny(Collection<Path> unwanted, String name)
      Ensures that the path does not contain any of the paths in unwanted.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted paths
      name - the name of the unwanted paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path contains any of the paths in unwanted
    • containsAll

      PathValidator containsAll(Collection<Path> expected)
      Ensures that the path contains all the paths in expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the path does not contain all the paths in expected
    • containsAll

      PathValidator containsAll(Collection<Path> expected, String name)
      Ensures that the path contains all the paths in expected.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      expected - the desired paths
      name - the name of the expected paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path does not contain all the paths in expected
    • doesNotContainAll

      PathValidator doesNotContainAll(Collection<Path> unwanted)
      Allows the path to contain some, but not all, paths from another collection.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the path contains all the paths in unwanted
    • doesNotContainAll

      PathValidator doesNotContainAll(Collection<Path> unwanted, String name)
      Allows the path to contain some, but not all, paths from another collection.

      Note: This method only verifies direct (one-level deep) descendants and does not perform a recursive check.

      Parameters:
      unwanted - the unwanted paths
      name - the name of the unwanted paths
      Returns:
      this
      Throws:
      NullPointerException - if the value or any of the arguments are null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the path contains all the paths in unwanted