Search in sources :

Example 1 with JUtilSorter

use of j.util.JUtilSorter in project JFramework by gugumall.

the class JCacheUnitMap method values.

/*
	 *  (non-Javadoc)
	 * @see j.cache.JCacheUnit#values(j.cache.JCacheParams)
	 */
public ConcurrentList values(JCacheParams params) throws Exception {
    checkStatus(false);
    JCacheFilter keyFileter = params == null ? null : params.keyFilter;
    JCacheFilter valueFilter = params == null ? null : params.valueFilter;
    JUtilSorter sorter = params == null ? null : params.sorter;
    String sortType = params == null ? null : params.sortType;
    int recordsPerPage = params == null ? 0 : params.recordsPerPage;
    int pageNum = params == null ? 0 : params.pageNum;
    ConcurrentMap mappings = container.snapshot();
    List values = null;
    if (keyFileter != null || valueFilter != null) {
        values = new ConcurrentList();
        List keys = mappings.listKeys();
        for (int i = 0; i < keys.size(); i++) {
            Object key = keys.get(i);
            Object value = mappings.get(key);
            boolean remove = false;
            if (keyFileter != null && !keyFileter.matches(key)) {
                remove = true;
            } else if (valueFilter != null && !valueFilter.matches(value)) {
                remove = true;
            }
            if (!remove) {
                values.add(value);
            }
        }
        keys.clear();
        keys = null;
    } else {
        values = mappings.listValues();
    }
    mappings.clear();
    mappings = null;
    if (sorter != null) {
        // 排序
        values = sorter.mergeSort(values, sortType);
    }
    ConcurrentList result = new ConcurrentList();
    result.setTotal(values.size());
    if (recordsPerPage > 0 && pageNum > 0) {
        // 分页
        int start = recordsPerPage * (pageNum - 1);
        int to = recordsPerPage * pageNum;
        if (start >= 0) {
            if (values.size() > start) {
                values = JUtilList.subConcurrentList(values, start, to > values.size() ? values.size() : to);
            } else {
                values.clear();
            }
        }
    }
    result.addAll(values);
    return result;
}
Also used : ConcurrentList(j.util.ConcurrentList) JUtilSorter(j.util.JUtilSorter) ConcurrentMap(j.util.ConcurrentMap) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilList(j.util.JUtilList)

Aggregations

ConcurrentList (j.util.ConcurrentList)1 ConcurrentMap (j.util.ConcurrentMap)1 JUtilList (j.util.JUtilList)1 JUtilSorter (j.util.JUtilSorter)1 List (java.util.List)1