@ -1,19 +1,21 @@
package info.bukova.isspst.sort ;
import info.bukova.isspst.StringUtils ;
import java.lang.reflect.InvocationTargetException ;
import java.lang.reflect.Method ;
import java.text.Collator ;
import java.text.ParseException ;
import java.text.RuleBasedCollator ;
import java.util.Comparator ;
import java.util.List ;
import org.zkoss.zk.ui.util.Clients ;
public class CzechStringComparator implements Comparator < Object > {
private String m_rule ;
private final String m_property ;
private final List< String> m_property Path ;
private final boolean m_ascending ;
private Method m_getter ;
private Comparator < Object > m_comparator ;
public CzechStringComparator ( String property , boolean ascending ) {
@ -47,7 +49,7 @@ public class CzechStringComparator implements Comparator<Object> {
m_rule + = "< Y,y < Ý,ý " ;
m_rule + = "< Z,z < Ź,ź < Ž,ž " ;
m_property = property;
m_property Path = StringUtils. split ( property, "." ) ;
m_ascending = ascending ;
}
@ -72,21 +74,56 @@ public class CzechStringComparator implements Comparator<Object> {
return 0 ;
}
private Object getValue ( Object caller )
{
Object obj = caller ;
for ( String property : m_propertyPath )
{
if ( obj = = null )
{
return null ;
}
Method method = ReflectionTools . getGetterMethod ( obj , property ) ;
try
{
obj = method . invoke ( obj ) ;
}
catch ( IllegalAccessException e )
{
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
catch ( IllegalArgumentException e )
{
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
catch ( InvocationTargetException e )
{
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
}
return obj ;
}
private int internalCompare ( Object argL , Object argR )
throws ParseException , IllegalAccessException ,
IllegalArgumentException , InvocationTargetException {
if ( m_getter = = null ) {
m_getter = ReflectionTools . getGetterMethod ( argL , m_property ) ;
}
if ( m_comparator = = null ) {
if ( m_comparator = = null )
{
Collator c = new RuleBasedCollator ( m_rule ) ;
c . setStrength ( Collator . TERTIARY ) ;
m_comparator = c ;
}
Object valL = m_getter . invoke ( argL ) ;
Object valR = m_getter . invoke ( argR ) ;
Object valL = this . getValu e( argL ) ;
Object valR = this . getValu e( argR ) ;
boolean isNullValL = ( valL = = null ) ;
boolean isNullValR = ( valR = = null ) ;