Fileregex must be public, or it will not be serialized to YAML
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / configuration / FileAssociation.java
1 package eu.svjatoslav.instantlauncher.configuration;
2
3 import java.io.File;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 public class FileAssociation implements Comparable<FileAssociation> {
8     public String command;
9     public String fileRegex;
10
11     public FileAssociation() {
12     }
13
14     public FileAssociation(String fileRegex, String command) {
15         this.fileRegex = fileRegex;
16         this.command = command;
17     }
18
19     @Override
20     public int compareTo(FileAssociation o) {
21         return fileRegex.compareTo(o.fileRegex);
22     }
23
24     public boolean matchesFile(File file) {
25         String absolutePath = file.getAbsolutePath();
26
27         Pattern pattern = Pattern.compile(fileRegex);
28         Matcher matcher = pattern.matcher(absolutePath);
29         return matcher.matches();
30     }
31
32 }