
org.directwebremoting.datasync.DefaultComparatorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwr Show documentation
Show all versions of dwr Show documentation
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boilerplate code between the web browser and your Java code.
This version 4.0.2 works with Jakarta Servlet 4.0.2.
The newest version!
package org.directwebremoting.datasync;
import java.util.Comparator;
/**
* A ComparatorFactory that assumes that
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class DefaultComparatorFactory implements ComparatorFactory
{
/* (non-Javadoc)
* @see org.directwebremoting.datasync.ComparatorFactory#getComparator(java.lang.String, boolean)
*/
public Comparator super T> getComparator(final String property, final boolean ascending)
{
final AttributeValueExtractor extractor = new PojoAttributeValueExtractor();
return new Comparator()
{
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public int compare(T o1, T o2)
{
Object value1 = extractor.getValue(o1, property);
Object value2 = extractor.getValue(o2, property);
if (value1 == null)
{
if (value2 == null)
{
return 0;
}
else
{
return -1;
}
}
else
{
if (value2 == null)
{
return 1;
}
}
Comparable comp1 = (Comparable) value1;
Comparable comp2 = (Comparable) value2;
if (!ascending)
{
return comp2.compareTo(comp1);
}
else
{
return comp1.compareTo(comp2);
}
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy