lib: sort fixes
authorNiki Roo <niki@nikiroo.be>
Sat, 18 Apr 2020 15:18:02 +0000 (17:18 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 18 Apr 2020 15:18:02 +0000 (17:18 +0200)
src/be/nikiroo/fanfix/data/MetaData.java
src/be/nikiroo/fanfix/library/MetaResultList.java

index 2c40beb1758b36f5b1415b3adf4b7ef86bd42fe6..586196a663fea88aa39fe45111445d76df0d5651 100644 (file)
@@ -390,12 +390,14 @@ public class MetaData implements Cloneable, Comparable<MetaData>, Serializable {
                        return 1;
                }
 
-               String id = (getUuid() == null ? "" : getUuid())
+               String id = (getTitle() == null ? "" : getTitle())
+                               + (getUuid() == null ? "" : getUuid())
                                + (getLuid() == null ? "" : getLuid());
-               String oId = (getUuid() == null ? "" : o.getUuid())
+               String oId = (getTitle() == null ? "" : o.getTitle())
+                               + (getUuid() == null ? "" : o.getUuid())
                                + (o.getLuid() == null ? "" : o.getLuid());
 
-               return id.compareTo(oId);
+               return id.compareToIgnoreCase(oId);
        }
 
        @Override
index 886defe8b1c6a9df42639f04c82ebd87d5396bbd..b5f3312282669624de6474dd7007e7a86c373080 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import be.nikiroo.fanfix.data.MetaData;
@@ -39,8 +40,9 @@ public class MetaResultList {
                                if (!sources.contains(meta.getSource()))
                                        sources.add(meta.getSource());
                        }
+                       sort(sources);
                }
-
+               
                return sources;
        }
 
@@ -60,6 +62,7 @@ public class MetaResultList {
                        }
                }
 
+               sort(linked);
                return linked;
        }
 
@@ -70,8 +73,9 @@ public class MetaResultList {
                                if (!authors.contains(meta.getAuthor()))
                                        authors.add(meta.getAuthor());
                        }
+                       sort(authors);
                }
-
+               
                return authors;
        }
 
@@ -84,9 +88,10 @@ public class MetaResultList {
                                                tags.add(tag);
                                }
                        }
+                       sort(tags);
                }
-
-               return authors;
+               
+               return tags;
        }
 
        // helper
@@ -99,10 +104,12 @@ public class MetaResultList {
        }
 
        // null or empty -> no check, rest = must be included
-       // source: a source ending in "/" means "this or any source starting with this",
+       // source: a source ending in "/" means "this or any source starting with
+       // this",
        // i;e., to enable source hierarchy
        // + sorted
-       public List<MetaData> filter(List<String> sources, List<String> authors, List<String> tags) {
+       public List<MetaData> filter(List<String> sources, List<String> authors,
+                       List<String> tags) {
                if (sources != null && sources.isEmpty())
                        sources = null;
                if (authors != null && authors.isEmpty())
@@ -165,4 +172,19 @@ public class MetaResultList {
                Collections.sort(result);
                return result;
        }
+       
+       /**
+        * Sort the given {@link String} values, ignoring case.
+        * 
+        * @param values
+        *            the values to sort
+        */
+       private void sort(List<String> values) {
+               Collections.sort(values, new Comparator<String>() {
+                       @Override
+                       public int compare(String o1, String o2) {
+                               return ("" + o1).compareToIgnoreCase("" + o2);
+                       }
+               });
+       }
 }