Added license and copyright notice.
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / configuration / FileAssociation.java
1 /*
2  * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.instantlauncher.configuration;
10
11 import java.io.File;
12 import java.util.regex.Matcher;
13 import java.util.regex.Pattern;
14
15 public class FileAssociation implements Comparable<FileAssociation> {
16     public String command;
17     public String fileRegex;
18
19     public FileAssociation() {
20     }
21
22     public FileAssociation(String fileRegex, String command) {
23         this.fileRegex = fileRegex;
24         this.command = command;
25     }
26
27     @Override
28     public int compareTo(FileAssociation o) {
29         return fileRegex.compareTo(o.fileRegex);
30     }
31
32     public boolean matchesFile(File file) {
33         String absolutePath = file.getAbsolutePath();
34
35         Pattern pattern = Pattern.compile(fileRegex);
36         Matcher matcher = pattern.matcher(absolutePath);
37         return matcher.matches();
38     }
39
40 }