[vlma-devel] commit: Sort medias on the main page. (Adrien Grand )

git version control git at videolan.org
Sat Nov 15 20:22:46 CET 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Nov 15 18:45:02 2008 +0100| [27442d3abcf77d44bd525ad2b32d53bc2ebce496] | committer: Adrien Grand 

Sort medias on the main page.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=27442d3abcf77d44bd525ad2b32d53bc2ebce496
---

 .../vlma/web/welcome/WelcomeController.java        |   34 ++++++++++++++++---
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/vlma-webapp/src/main/java/org/videolan/vlma/web/welcome/WelcomeController.java b/vlma-webapp/src/main/java/org/videolan/vlma/web/welcome/WelcomeController.java
index ad958cd..7f5ff68 100644
--- a/vlma-webapp/src/main/java/org/videolan/vlma/web/welcome/WelcomeController.java
+++ b/vlma-webapp/src/main/java/org/videolan/vlma/web/welcome/WelcomeController.java
@@ -21,6 +21,8 @@
 package org.videolan.vlma.web.welcome;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -39,12 +41,14 @@ public class WelcomeController implements Controller {
 
     public ModelAndView handleRequest(HttpServletRequest arg0,
             HttpServletResponse arg1) throws Exception {
+
         List<SatChannel> satChannels = new ArrayList<SatChannel>();
         List<DTTChannel> dttChannels = new ArrayList<DTTChannel>();
         List<FilesChannel> fileChannels = new ArrayList<FilesChannel>();
         List<StreamChannel> streamChannels = new ArrayList<StreamChannel>();
-        for (Media media : data.getMedias())
-            if (media.getProgram() != null)
+
+        for (Media media : data.getMedias()) {
+            if (media.getProgram() != null) {
                 if (media.getClass().equals(SatChannel.class)) {
                     SatChannel channel = (SatChannel) media;
                     satChannels.add(channel);
@@ -58,6 +62,28 @@ public class WelcomeController implements Controller {
                     StreamChannel channel = (StreamChannel) media;
                     streamChannels.add(channel);
                 }
+            }
+        }
+
+        Comparator<Media> comparator = new Comparator<Media>() {
+
+            // Sort medias according to their priority
+            public int compare(Media media0, Media media1) {
+                int result = media1.getProgram().getPriority() - media0.getProgram().getPriority();
+                if(result == 0) {
+                    return media0.getName().compareTo(media1.getName());
+                } else {
+                    return result;
+                }
+            }
+
+        };
+
+        Collections.sort(satChannels, comparator);
+        Collections.sort(dttChannels, comparator);
+        Collections.sort(fileChannels, comparator);
+        Collections.sort(streamChannels, comparator);
+
         ModelAndView mav = new ModelAndView();
         mav.addObject("satChannels", satChannels);
         mav.addObject("dttChannels", dttChannels);
@@ -69,10 +95,6 @@ public class WelcomeController implements Controller {
 
     private Data data;
 
-    public Data getData() {
-        return data;
-    }
-
     public void setData(Data data) {
         this.data = data;
     }



More information about the vlma-devel mailing list