/* * [HTMLArrayComparator.java] * * Summary: Compares two arrays of Strings of HTML, ignoring embedded tags. * * 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.4 2007-05-22 add icon and PAD. */ package com.mindprod.comparators; import com.mindprod.entities.DeEntifyStrings; import java.util.Comparator; /** * Compares two arrays of Strings of HTML, ignoring embedded tags. *

* Defines an alternate sort order for String[]. * * @author Roedy Green, Canadian Mind Products * @version 1.4 2007-05-22 add icon and PAD. * @since 2005-12-10 */ public class HTMLArrayComparator 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 contataining html tags * * @return key with tags stripped out */ private static String flatten( String key ) { return DeEntifyStrings.flattenHTML( key, ' ' ).trim(); } // end flatten /** * Compares two arrays of Strings of HTML, ignoring embedded tags. * 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 ) { int diff = 0; for ( int i = 0; i < a.length; i++ ) { String aa = flatten( a[ i ] ); String bb = flatten( b[ i ] ); diff = aa.compareToIgnoreCase( bb ); if ( diff != 0 ) { return diff; } } // end for return diff; } }