Android List filter -
i have list of file object want filter according rules typology (audio, video, photo) or capture date/time, or exif informations (in case of photos). can cicles example.
there's smart way it? read somewhere solution utilize predicates google guava, can't understand how works. suggestion? thanks
using guava predicates along lines of
import java.io.file; import java.util.collection; import java.util.list; import javax.annotation.nullable; import com.google.common.base.predicate; import com.google.common.collect.collections2; import com.google.common.io.files; public class filefiltering { public static void main(string[] args) { list<file> files = getfiles(); collection<file> audiofiles = collections2.filter(files, new audiopredicate()); collection<file> videofiles = collections2.filter(files, new videopredicate()); } private static list<file> getfiles() { // todo auto-generated method stub homecoming null; } } class audiopredicate implements predicate<file> { @override public boolean apply(@nullable file file) { homecoming files.getfileextension(file.getname()).equalsignorecase("mp3"); } } class videopredicate implements predicate<file> { @override public boolean apply(@nullable file file) { homecoming files.getfileextension(file.getname()).equalsignorecase("mkv"); } }
in apply method(s) need write code homecoming true kind of file want.
android list filtering guava predicates
No comments:
Post a Comment