Java List Sort removeSortColumns(List selectColumns, List sorts, List ascending)

Here you can find the source of removeSortColumns(List selectColumns, List sorts, List ascending)

Description

remove Sort Columns

License

Apache License

Declaration

public static void removeSortColumns(List<String> selectColumns, List<String> sorts, List<Boolean> ascending) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static final String AS = " as ";

    public static void removeSortColumns(List<String> selectColumns, List<String> sorts, List<Boolean> ascending) {
        List<String> removedSorts = new ArrayList<String>();
        for (String sort : sorts) {
            if (!containsColumnByAlias(selectColumns, sort)) {
                removedSorts.add(sort);/*from www. ja  v  a 2 s  .  com*/
            }
        }
        for (String sort : removedSorts) {
            removeSortByColumnName(sorts, ascending, sort);
        }
    }

    public static boolean containsColumnByAlias(List<String> columns, String alias) {
        for (String column : columns) {
            if (getColumnAlias(column).equals(alias)) {
                return true;
            }
        }
        return false;
    }

    public static boolean removeSortByColumnName(List<String> sortProperty, List<Boolean> ascending,
            String columnName) {
        if (sortProperty == null) {
            return false;
        }
        int index = -1;
        for (int i = 0, size = sortProperty.size(); i < size; i++) {
            String sort = sortProperty.get(i);
            if (sort.equals(columnName)) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            sortProperty.remove(index);
            ascending.remove(index);
        }
        return (index == 0);
    }

    public static String getColumnAlias(String fullColumnName) {
        if (fullColumnName.contains(AS)) {
            int index = fullColumnName.indexOf(AS);
            return fullColumnName.substring(index + AS.length());
        } else {
            return fullColumnName;
        }
    }
}

Related

  1. mergeSort(List list)
  2. mergeSortedLists(List dest, List[] src, boolean removeDuplicates)
  3. quickSort(Comparable[] list, int min, int max)
  4. removeSortByColumnName(List sortProperty, List ascending, String columnName)
  5. removeSortColumns(List selectColumns, List sorts, List ascending)
  6. searchSorted(List a, double v)
  7. setToSortedList(final Set set, final Comparator comparator)
  8. sort( S list)
  9. sort(Collection list)