package fr.nelaupe.spreadsheetlib;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by lucas34990 on 16/2/16.
 */
public abstract class FieldBinder<TSelf> {

    private List<AnnotationFields> fields;

    public FieldBinder() {
        this.fields = init();
    }

    protected abstract List<AnnotationFields> fill();

    public abstract Object getValueAt(String fieldName, TSelf data);

    public List<AnnotationFields> fields() {
        return fields;
    }

    private List<AnnotationFields> init() {
        List<AnnotationFields> fields = fill();
        Collections.sort(fields, new Comparator<AnnotationFields>() {
            @Override
            public int compare(AnnotationFields lhs, AnnotationFields rhs) {
                Integer positionL = lhs.getPosition();
                Integer positionR = rhs.getPosition();

                return positionL.compareTo(positionR);
            }
        });
        return Collections.unmodifiableList(fields);
    }


}

@@ -245,16 +245,88 @@
 ields;%0A%0A
+    private boolean mSortingDESC;%0A    private int mColumnSortSelected;%0A%0A
     publ
@@ -1094,11 +1094,447 @@
 %0A    %7D%0A%0A
+    boolean isSortingDESC() %7B%0A        return mSortingDESC;%0A    %7D%0A%0A    int getSortingColumnSelected() %7B%0A        return mColumnSortSelected;%0A    %7D%0A%0A    void setIsDESC(boolean mIsDESC) %7B%0A        this.mSortingDESC = mIsDESC;%0A    %7D%0A%0A    void invertSorting() %7B%0A        this.mSortingDESC = !this.mSortingDESC;%0A    %7D%0A%0A    public void setColumnSortSelected(int mColumnSortSelected) %7B%0A        this.mColumnSortSelected = mColumnSortSelected;%0A    %7D
 %0A%7D%0A

Add sorting state to the binder