[vlma-devel] commit: Medias are not comparable. (Adrien Grand )
git version control
git at videolan.org
Tue Aug 5 23:30:38 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Tue Aug 5 21:57:55 2008 +0200| [3952cded748d9b4f2a763c1b855f9514d4cb21bb] | committer: Adrien Grand
Medias are not comparable.
To sort medias by name, provide a comparator to the Collections.sort method.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=3952cded748d9b4f2a763c1b855f9514d4cb21bb
---
.../java/org/videolan/vlma/model/media/Media.java | 2 +-
.../java/org/videolan/vlma/VLMaServiceImpl.java | 13 ++++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/media/Media.java b/vlma-api/src/main/java/org/videolan/vlma/model/media/Media.java
index 50f5223..c487225 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/media/Media.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/media/Media.java
@@ -27,7 +27,7 @@ import java.io.Serializable;
*
* @author Sylvain Cadilhac <sylv at videolan.org>
*/
-public abstract class Media implements Serializable, Comparable<Media> {
+public abstract class Media implements Serializable {
protected String name;
diff --git a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
index 33d45f7..afc17a4 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
@@ -31,6 +31,7 @@ import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -704,7 +705,17 @@ public class VLMaServiceImpl implements VLMaService {
synchronized public void sortMedias()
{
- Collections.sort(medias);
+ // Sort medias by Name
+ Collections.sort(medias,
+ new Comparator<Media>() {
+ public int compare(Media m1, Media m2) {
+ if (m1 == null)
+ return -1;
+ if (m2 == null)
+ return 1;
+ return m1.getName().compareTo(m2.getName());
+ }
+ });
}
/* Starts the punctual monitoring controls */
More information about the vlma-devel
mailing list