From 58701825851d5533ec28b0ecd6c0c5ed645655c5 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 18 Apr 2020 17:18:02 +0200 Subject: [PATCH] lib: sort fixes --- src/be/nikiroo/fanfix/data/MetaData.java | 8 +++-- .../fanfix/library/MetaResultList.java | 34 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/be/nikiroo/fanfix/data/MetaData.java b/src/be/nikiroo/fanfix/data/MetaData.java index 2c40beb..586196a 100644 --- a/src/be/nikiroo/fanfix/data/MetaData.java +++ b/src/be/nikiroo/fanfix/data/MetaData.java @@ -390,12 +390,14 @@ public class MetaData implements Cloneable, Comparable, 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 diff --git a/src/be/nikiroo/fanfix/library/MetaResultList.java b/src/be/nikiroo/fanfix/library/MetaResultList.java index 886defe..b5f3312 100644 --- a/src/be/nikiroo/fanfix/library/MetaResultList.java +++ b/src/be/nikiroo/fanfix/library/MetaResultList.java @@ -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 filter(List sources, List authors, List tags) { + public List filter(List sources, List authors, + List 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 values) { + Collections.sort(values, new Comparator() { + @Override + public int compare(String o1, String o2) { + return ("" + o1).compareToIgnoreCase("" + o2); + } + }); + } } -- 2.27.0