/* * [HTMLComparator.java] * * Summary: Compare keys containing HTML tags and entities. * * Copyright: (c) 2005-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2005-07-02 converted to Java 1.5 */ package com.mindprod.comparators; import com.mindprod.entities.DeEntifyStrings; import java.util.Comparator; /** * Compare keys containing HTML tags and entities. *

* Defines an alternate sort order for String. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2005-07-02 converted to Java 1.5 * @since 2005-07-02 */ public class HTMLComparator implements Comparator { /** * strip out anything inside < .... > Then strip lead/trail spaces, but not embedded spaces. Does not * covert to * lower case. Does not convert entities to Unicode. * * @param key string conttaining html tags. * * @return key with tags stripped out. */ public static String flatten( String key ) { // trim later so that lead/trail   will be trimmed. return DeEntifyStrings.flattenHTML( key, ' ' ).trim(); } // end flatten /** * Compare keys containing HTML tags and entities. * Defines an alternate sort order for String. * Compare two String Objects. * Informally, returns (a-b), or +ve if a is more positive than b. * * @param a first String to compare * @param b second String to compare * * @return +ve if a>b, 0 if a==b, -ve if a<b */ public final int compare( String a, String b ) { return flatten( a ).compareToIgnoreCase( flatten( b ) ); } }