Add File.getAt(int) and File.getAt(Range) methods to improve {plex} binding usage

This commit is contained in:
Reinhard Pointner 2016-04-01 08:48:52 +00:00
parent 869a571f2a
commit 20c94f02d2
1 changed files with 10 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package net.filebot.cli;
import static java.nio.charset.StandardCharsets.*; import static java.nio.charset.StandardCharsets.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.media.XattrMetaInfo.*;
@ -26,6 +27,7 @@ import com.cedarsoftware.util.io.JsonReader;
import com.cedarsoftware.util.io.JsonWriter; import com.cedarsoftware.util.io.JsonWriter;
import groovy.lang.Closure; import groovy.lang.Closure;
import groovy.lang.Range;
import net.filebot.MediaTypes; import net.filebot.MediaTypes;
import net.filebot.MetaAttributeView; import net.filebot.MetaAttributeView;
import net.filebot.media.MediaDetection; import net.filebot.media.MediaDetection;
@ -46,6 +48,14 @@ public class ScriptShellMethods {
return new File(self, name); return new File(self, name);
} }
public static String getAt(File self, int index) {
return FileUtilities.listPath(self).get(index).getName();
}
public static File getAt(File self, Range<?> range) {
return new File(DefaultGroovyMethods.getAt(FileUtilities.listPath(self), range).stream().map(File::getName).collect(joining(File.separator)));
}
public static File resolve(File self, String name) { public static File resolve(File self, String name) {
return new File(self, name); return new File(self, name);
} }