1 25 26 package org.snipsnap.snip; 27 28 import java.util.Comparator ; 29 30 43 44 public class PostNameComparator implements Comparator { 45 public int compare(Object o1, Object o2) { 46 if (! (o1 instanceof String ) || !( o2 instanceof String )) { 47 throw new ClassCastException (); 48 } 49 String name1 = (String ) o1; 50 String name2 = (String ) o2; 51 int index1 = name1.lastIndexOf("/"); 52 int index2 = name2.lastIndexOf("/"); 53 int result = name2.substring(0, index2 != -1 ? index2 : name2.length()) 54 .compareTo(name1.substring(0, index1 != -1 ? index1 : name1.length())); 55 if (0 == result) { 56 int number1 = Integer.parseInt(name1.substring(index1+1)); 57 int number2 = Integer.parseInt(name2.substring(index2+1)); 58 result = number1 > number2 ? -1 : 1; 59 } 60 return result; 61 } 62 } 63 | Popular Tags |