This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 76578dfa2a197df1dcffb629f193ed4e023aa066 Author: Yannick Martel <martel@©odelutin.com> Date: Fri Jan 29 13:09:36 2016 +0100 refs #7922 extract cleanly map value comparator class --- .../services/StringLongMapValueComparator.java | 25 ++++++++++++++++++++++ .../indexation/TransverseIndexationService.java | 21 ++---------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/StringLongMapValueComparator.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/StringLongMapValueComparator.java new file mode 100644 index 0000000..0482b45 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/StringLongMapValueComparator.java @@ -0,0 +1,25 @@ +package fr.ifremer.coselmar.services; + +import java.util.Comparator; +import java.util.Map; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class StringLongMapValueComparator implements Comparator<String> { + Map<String, Long> base; + + public StringLongMapValueComparator(Map<String, Long> base) { + this.base = base; + } + + // Note: this comparator imposes orderings that are inconsistent with + // equals. + public int compare(String a, String b) { + if (base.get(a) >= base.get(b)) { + return -1; + } else { + return 1; + } // returning 0 would merge keys + } +} diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java index c193ed9..db6ae9b 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java @@ -26,6 +26,7 @@ package fr.ifremer.coselmar.services.indexation; import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.services.CoselmarSimpleServiceSupport; +import fr.ifremer.coselmar.services.StringLongMapValueComparator; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.Term; import org.apache.lucene.misc.HighFreqTerms; @@ -103,7 +104,7 @@ public class TransverseIndexationService extends CoselmarSimpleServiceSupport { } indexReader.close(); - MapValueComparator valueComparator = new MapValueComparator(topWords); + StringLongMapValueComparator valueComparator = new StringLongMapValueComparator(topWords); TreeMap<String, Long> sortedResult = new TreeMap(valueComparator); sortedResult.putAll(topWords); @@ -119,22 +120,4 @@ public class TransverseIndexationService extends CoselmarSimpleServiceSupport { return result; } -} - -class MapValueComparator implements Comparator<String> { - Map<String, Long> base; - - public MapValueComparator(Map<String, Long> base) { - this.base = base; - } - - // Note: this comparator imposes orderings that are inconsistent with - // equals. - public int compare(String a, String b) { - if (base.get(a) >= base.get(b)) { - return -1; - } else { - return 1; - } // returning 0 would merge keys - } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.