aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/java/jopt-simple/src/main/java/joptsimple/util/PathProperties.java
blob: a7fb04502519cf100329ce1ca1721739954c6526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package joptsimple.util;

import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Enum for checking common conditions of files and directories.
 *
 * @see joptsimple.util.PathConverter
 */
public enum PathProperties {
    FILE_EXISTING( "file.existing" ) {
        @Override
        boolean accept( Path path ) {
            return Files.isRegularFile( path );
        }
    },
    DIRECTORY_EXISTING( "directory.existing" ) {
        @Override
        boolean accept( Path path ) {
            return Files.isDirectory( path );
        }
    },
    NOT_EXISTING( "file.not.existing" ) {
        @Override
        boolean accept( Path path ) {
            return Files.notExists( path );
        }
    },
    FILE_OVERWRITABLE( "file.overwritable" ) {
        @Override
        boolean accept( Path path ) {
            return FILE_EXISTING.accept( path ) && WRITABLE.accept( path );
        }
    },
    READABLE( "file.readable" ) {
        @Override
        boolean accept( Path path ) {
            return Files.isReadable( path );
        }
    },
    WRITABLE( "file.writable" ) {
        @Override
        boolean accept( Path path ) {
            return Files.isWritable( path );
        }
    };

    private final String messageKey;

    private PathProperties( String messageKey ) {
        this.messageKey = messageKey;
    }

    abstract boolean accept( Path path );

    String getMessageKey() {
        return messageKey;
    }
}