Added license and copyright notice.
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / configuration / FileAssociation.java
index dc3b5a7..7bac98a 100644 (file)
@@ -1,8 +1,20 @@
+/*
+ * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
 package eu.svjatoslav.instantlauncher.configuration;
 
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 public class FileAssociation implements Comparable<FileAssociation> {
-    public String fileRegex;
     public String command;
+    public String fileRegex;
 
     public FileAssociation() {
     }
@@ -16,4 +28,13 @@ public class FileAssociation implements Comparable<FileAssociation> {
     public int compareTo(FileAssociation o) {
         return fileRegex.compareTo(o.fileRegex);
     }
+
+    public boolean matchesFile(File file) {
+        String absolutePath = file.getAbsolutePath();
+
+        Pattern pattern = Pattern.compile(fileRegex);
+        Matcher matcher = pattern.matcher(absolutePath);
+        return matcher.matches();
+    }
+
 }