--- /dev/null
+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;
+ }
+}