From add28711995cef25a9780996fcd8945157c28327 Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 9 Feb 2010 20:32:45 +0000 Subject: [PATCH] To make something Comparable implies that you could do something like stick it into a collection that keeps things sorted. Doing so without implementing hashCode() and equals() is a recipe for breakage. Instead we'll just define a comparator that does the one sorting we need, and use that, rather than give the wrong impression. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2719 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../servlet/JDBCTableSiteIdentifier.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java b/src/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java index 51394e1a..01e05076 100644 --- a/src/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java +++ b/src/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java @@ -28,6 +28,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -231,7 +232,7 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier } // sort the mappings in order of specificity - Collections.sort(mappings); + Collections.sort(mappings, SiteMapping.BY_SPECIFICITY); _mappings = mappings; // Log.info("Loaded site mappings " + StringUtil.toString(_mappings) + "."); @@ -275,16 +276,24 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier /** * Used to track domain to site identifier mappings. */ - protected static class SiteMapping implements Comparable + protected static class SiteMapping { + /** + * Sorts site mappings from most specific (www.yahoo.com) to least specific (yahoo.com). + */ + public static final Comparator BY_SPECIFICITY = new Comparator() { + public int compare (SiteMapping one, SiteMapping two) { + return one._rdomain.compareTo(two._rdomain); + } + }; + /** The domain to match. */ public String domain; /** The site identifier for the associated domain. */ public int siteId; - public SiteMapping (int siteId, String domain) - { + public SiteMapping (int siteId, String domain) { this.siteId = siteId; this.domain = domain; byte[] bytes = domain.getBytes(); @@ -292,17 +301,8 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier _rdomain = new String(bytes); } - /** - * Site mappings sort from most specific (www.yahoo.com) to least specific (yahoo.com). - */ - public int compareTo (SiteMapping other) - { - return other._rdomain.compareTo(_rdomain); - } - @Override // from Object - public String toString () - { + public String toString () { return "[" + domain + " => " + siteId + "]"; }