/***************************************************************************** * MediaComparators.java ***************************************************************************** * Copyright © 2013 VLC authors and VideoLAN * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ package org.videolan.vlc.gui.audio; import java.util.Comparator; import org.videolan.libvlc.Media; public class MediaComparators { public static final Comparator<Media> byName = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { return String.CASE_INSENSITIVE_ORDER.compare(m1.getTitle(), m2.getTitle()); }; }; public static final Comparator<Media> byMRL = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { return String.CASE_INSENSITIVE_ORDER.compare(m1.getLocation(), m2.getLocation()); }; }; public static final Comparator<Media> byLength = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { if(m1.getLength() > m2.getLength()) return -1; if(m1.getLength() < m2.getLength()) return 1; else return 0; }; }; public static final Comparator<Media> byAlbum = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getAlbum(), m2.getAlbum()); if (res == 0) res = byMRL.compare(m1, m2); return res; }; }; public static final Comparator<Media> byArtist = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getArtist(), m2.getArtist()); if (res == 0) res = byAlbum.compare(m1, m2); return res; }; }; public static final Comparator<Media> byGenre = new Comparator<Media>() { @Override public int compare(Media m1, Media m2) { int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getGenre(), m2.getGenre()); if (res == 0) res = byArtist.compare(m1, m2); return res; }; }; }