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;
}
Aggregations