OSDN Git Service

FileWatch用ユーティリティ
authoryukihane <yukihane.feather@gmail.com>
Fri, 2 Sep 2011 03:23:00 +0000 (12:23 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 9 Sep 2011 11:39:03 +0000 (20:39 +0900)
frontend/src/yukihane/inqubus/filewatch/FileWatchUtil.java [new file with mode: 0644]

diff --git a/frontend/src/yukihane/inqubus/filewatch/FileWatchUtil.java b/frontend/src/yukihane/inqubus/filewatch/FileWatchUtil.java
new file mode 100644 (file)
index 0000000..5bb709a
--- /dev/null
@@ -0,0 +1,45 @@
+package yukihane.inqubus.filewatch;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.io.FilenameUtils;
+
+/**
+ *
+ * @author user
+ */
+public final class FileWatchUtil {
+    // TODO スレッドID指定の場合の考慮も必要か
+
+    private static final Pattern VIDEO_ID_PATTERN = Pattern.compile("\\w\\w\\d+");
+
+    private FileWatchUtil() {
+    }
+
+    public static SortedSet<String> getVideoIds(Collection<Path> paths) {
+        final SortedSet<String> set = new TreeSet<>();
+        for (Path p : paths) {
+            final String name = FilenameUtils.getBaseName(p.toString());
+            final Matcher m = VIDEO_ID_PATTERN.matcher(name);
+            while (m.find()) {
+                set.add(m.group());
+            }
+        }
+        return set;
+    }
+
+    public static SortedSet<String> contain(Collection<Path> paths, String id) {
+        final SortedSet<String> set = new TreeSet<>();
+        for (Path p : paths) {
+            final String name = FilenameUtils.getBaseName(p.toString());
+            if (name.contains(id)) {
+                set.add(p.toAbsolutePath().toString());
+            }
+        }
+        return set;
+    }
+}