Электронный магазин на Java и XML

         

Метод для сортировки...



Листинг 9.18. Метод для сортировки и другие служебные методы (NewsModel.java)

public void shellSort (String[] srted ) { // h is the separation between items we compare. int h = 1; while ( h < srted.length ) { h = 3 * h + 1; } // now h is optimum while ( h >
0 ) { h = (h - 1)/3; for ( int i = h; i < srted.length; ++i ) { String item = srted[i]; int j=0; for ( j = i - h; j >
= 0 && compare( srted[j], item ) < 0; j -= h ) { srted[j+h] = srted[j]; } // end inner for srted[j+h] = item; } // end outer for } // end while } // end sort // return -1 if a < b , 0 if equal, +1 if a >
b int compare(String a, String b ){ String aa = a.toUpperCase() ; String bb = b.toUpperCase() ; return bb.compareTo( aa ) ; } public String toString() { StringBuffer sb = new StringBuffer( "NewsModel " );
if( !usable ){ sb.append("is not usable due to ");
sb.append( lastErr );
return sb.toString();
} sb.append("count of articles ");
sb.append( Integer.toString( articleNodeList.getLength()) );
sb.append("Unique clusters " + clusterHash.size() );
sb.append("\n");
Enumeration keys = clusterHash.keys();
while( keys.hasMoreElements() ){ String key = (String)keys.nextElement();
Vector v = (Vector)clusterHash.get( key );
sb.append(" Topic: " );
sb.append( key ) ; sb.append(" has " ) ; sb.append(Integer.toString( v.size()));
sb.append("\n");
} return sb.toString();
} }



Содержание раздела