Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.cdlflex.ui.markup.html.repeater.data.table;
 
 import java.util.List;
 
Extends a ListDataProvider and provides the ISortableDataProvider interface. It uses a very primitive sorting technique namely by comparing the string values of the respective columns (which will work for most data).

Parameters:
<T> the type of the provided data model
<S> the type of the sorting parameter
 
 public class SortableListDataProvider<T extends Serializable, S> extends ListDataProvider<T> implements
         ISortableDataProvider<T, S> {
 
     private static final long serialVersionUID = 1L;
 
     private final SingleSortState<S> sortState = new SingleSortState<>();
 
     public SortableListDataProvider() {
         super(new ArrayList<T>());
     }
 
     public SortableListDataProvider(List<T> list) {
         super(list);
     }
 
     @Override
     public ISortState<S> getSortState() {
         return ;
     }

    
Returns the SortParam of the current SortState.

Returns:
the sort parameter
 
     public SortParam<S> getSort() {
         return .getSort();
     }
 
     @Override
     protected List<T> getData() {
         List<T> data = getListData();
 
         sort(data);
 
         return data;
     }

    
Returns the underlying list (before its sorted). Can be overridden by subclasses that provide their own lists.

Returns:
the list of data being displayed
 
     protected List<T> getListData() {
         return super.getData();
     }

    
Sorts the data returned by ListDataProvider#getData() by the current sort property.

Parameters:
data the input list
 
     protected void sort(List<T> data) {
         if (getSortState() == null || getSort() == null) {
             return;
         }
 
         S property = getSort().getProperty();
         if (!(property instanceof String)) {
             return;
         }
 
         sort(data, (StringpropertygetSort().isAscending());
     }

    
Sorts the given list by the property declared in the given property expression.

Parameters:
data the input list
propertyExpression the expression that declares the property by which to sort the data
ascending whether or not to sort the data ascending
    protected void sort(List<T> dataString propertyExpressionboolean ascending) {
        Comparator<T> comparator = new DefaultModelPropertyValueComparator<T>(propertyExpression);
        if (ascending) {
            Collections.sort(datacomparator);
        } else {
            Collections.sort(data, Collections.reverseOrder(comparator));
        }
    }
New to GrepCode? Check out our FAQ X