Package com.vaadin.data.util
Class DefaultItemSorter
- java.lang.Object
-
- com.vaadin.data.util.DefaultItemSorter
-
- All Implemented Interfaces:
ItemSorter
,Serializable
,Cloneable
,Comparator<Object>
public class DefaultItemSorter extends Object implements ItemSorter
Provides a default implementation of an ItemSorter. TheDefaultItemSorter
adheres to theContainer.Sortable.sort(Object[], boolean[])
rules and sorts the container according to the properties given usingsetSortProperties(Sortable, Object[], boolean[])
.A Comparator is used for comparing the individual
Property
values. The comparator can be set using the constructor. If no comparator is provided a default comparator is used.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultItemSorter.DefaultPropertyValueComparator
Provides a default comparator used for comparingProperty
values.
-
Constructor Summary
Constructors Constructor Description DefaultItemSorter()
Constructs a DefaultItemSorter using the defaultComparator
for comparingProperty
values.DefaultItemSorter(Comparator<Object> propertyValueComparator)
Constructs a DefaultItemSorter which uses theComparator
indicated by thepropertyValueComparator
parameter for comparingProperty
values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(Object o1, Object o2)
Compares its two arguments for order.protected int
compareProperty(Object propertyId, boolean sortDirection, Item item1, Item item2)
Compares the property indicated bypropertyId
in the items indicated byitem1
anditem2
for order.void
setSortProperties(Container.Sortable container, Object[] propertyId, boolean[] ascending)
Sets the parameters for an upcoming sort operation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals
-
-
-
-
Constructor Detail
-
DefaultItemSorter
public DefaultItemSorter()
Constructs a DefaultItemSorter using the defaultComparator
for comparingProperty
values.
-
DefaultItemSorter
public DefaultItemSorter(Comparator<Object> propertyValueComparator)
Constructs a DefaultItemSorter which uses theComparator
indicated by thepropertyValueComparator
parameter for comparingProperty
values.- Parameters:
propertyValueComparator
- The comparator to use when comparing individualProperty
values
-
-
Method Detail
-
compare
public int compare(Object o1, Object o2)
Description copied from interface:ItemSorter
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.The parameters for the
ItemSorter
compare()
method must always be item ids which exist in the container set usingItemSorter.setSortProperties(Sortable, Object[], boolean[])
.- Specified by:
compare
in interfaceComparator<Object>
- Specified by:
compare
in interfaceItemSorter
- See Also:
Comparator.compare(Object, Object)
-
compareProperty
protected int compareProperty(Object propertyId, boolean sortDirection, Item item1, Item item2)
Compares the property indicated bypropertyId
in the items indicated byitem1
anditem2
for order. Returns a negative integer, zero, or a positive integer as the property value in the first item is less than, equal to, or greater than the property value in the second item. If thesortDirection
is false the returned value is negated.The comparator set for this
DefaultItemSorter
is used for comparing the two property values.- Parameters:
propertyId
- The property id for the property that is used for comparison.sortDirection
- The direction of the sort. A false value negates the result.item1
- The first item to compare.item2
- The second item to compare.- Returns:
- a negative, zero, or positive integer if the property value in
the first item is less than, equal to, or greater than the
property value in the second item. Negated if
sortDirection
is false.
-
setSortProperties
public void setSortProperties(Container.Sortable container, Object[] propertyId, boolean[] ascending)
Description copied from interface:ItemSorter
Sets the parameters for an upcoming sort operation. The parameters determine what container to sort and how theItemSorter
sorts the container.- Specified by:
setSortProperties
in interfaceItemSorter
- Parameters:
container
- The container that will be sorted. The container must contain the propertyIds given in thepropertyId
parameter.propertyId
- The property ids used for sorting. The property ids must exist in the container and should only be used if they are also sortable, i.e include in the collection returned bycontainer.getSortableContainerPropertyIds()
. SeeContainer.Sortable.sort(Object[], boolean[])
for more information.ascending
- Sorting order flags for each property id. SeeContainer.Sortable.sort(Object[], boolean[])
for more information.
-
-