本文整理汇总了Java中org.apache.commons.collections.comparators.ComparatorChain类的典型用法代码示例。如果您正苦于以下问题:Java ComparatorChain类的具体用法?Java ComparatorChain怎么用?Java ComparatorChain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComparatorChain类属于org.apache.commons.collections.comparators包,在下文中一共展示了ComparatorChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortListBeans
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* 根据给定的条件,把 list 中的 javabean 排序。
* 用到了 commons beanutils 和 commons.collections
*
* @param list 待排序的 list
* @param listOrderedMap 排序条件。
* 这是一个有序的 list ,排序条件按照加入到 list 的 bean 的属性(map 的 key)的先后顺序排序。
* listOrderedMap 的 key 为待排序的 bean 的属性名称,值为是否按该属性的正序排序,true 为正序,false 为逆序。
* 使用方法见本类的 testSortListBeans() 方法例子,使用时注意不要写错 bean 的属性名称。
* @param <T> list 中的 bean 类型
*/
public static <T> void sortListBeans(List<T> list, ListOrderedMap listOrderedMap) {
int num = listOrderedMap.size();
ArrayList sortFields = new ArrayList();
for (int i = 0; i < num; i++) {
// System.out.println("key =" + listOrderedMap.get(i) + " , value=" + listOrderedMap.getValue(i));
Comparator comp = ComparableComparator.getInstance();
comp = ComparatorUtils.nullLowComparator(comp); //允许null
if ((Boolean) listOrderedMap.getValue(i) == false)
comp = ComparatorUtils.reversedComparator(comp); //逆序
Comparator cmp = new BeanComparator((String) listOrderedMap.get(i), comp);
sortFields.add(cmp);
}
ComparatorChain multiSort = new ComparatorChain(sortFields);
Collections.sort(list, multiSort);
}
示例2: sortResults
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* sort the result set for the user locale
*
* @param locale
* The locale to use.
* @param results
* the result
* @param <L>
* the list item
*/
@SuppressWarnings("unchecked")
public static <L extends TagData> void sortResults(Locale locale,
List<L> results) {
if (results.size() == 0) {
return;
}
Collator primaryCollator = Collator.getInstance(locale);
primaryCollator.setStrength(Collator.SECONDARY);
Collator secondaryCollator = Collator.getInstance(locale);
secondaryCollator.setStrength(Collator.TERTIARY);
ComparatorChain chain = new ComparatorChain();
chain.addComparator(new BeanComparator("name", primaryCollator));
chain.addComparator(new BeanComparator("name", secondaryCollator));
Collections.sort(results, chain);
}
示例3: run
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
@Atomic
public static SortedSet<DegreeModuleScope> run(String degreeCurricularPlanID, AcademicInterval academicInterval)
throws FenixServiceException {
final DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID);
final ComparatorChain comparator = new ComparatorChain();
comparator.addComparator(new BeanComparator("curricularYear"));
comparator.addComparator(new BeanComparator("curricularSemester"));
comparator.addComparator(new BeanComparator("curricularCourse.externalId"));
comparator.addComparator(new BeanComparator("branch"));
final SortedSet<DegreeModuleScope> scopes = new TreeSet<DegreeModuleScope>(comparator);
for (DegreeModuleScope degreeModuleScope : degreeCurricularPlan.getDegreeModuleScopes()) {
if (degreeModuleScope.isActiveForAcademicInterval(academicInterval)) {
scopes.add(degreeModuleScope);
}
}
return scopes;
}
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:22,代码来源:ReadActiveCurricularCourseScopeByDegreeCurricularPlanAndExecutionYear.java
示例4: getExecutionPeriodsLabels
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
public List<SelectItem> getExecutionPeriodsLabels() {
if (this.executionPeriodsLabels == null) {
this.executionPeriodsLabels = new ArrayList();
final List<InfoExecutionPeriod> infoExecutionPeriods = getExecutionPeriods();
final ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(new ReverseComparator(new BeanComparator("infoExecutionYear.year")));
comparatorChain.addComparator(new ReverseComparator(new BeanComparator("semester")));
Collections.sort(infoExecutionPeriods, comparatorChain);
for (final InfoExecutionPeriod infoExecutionPeriod : infoExecutionPeriods) {
final SelectItem selectItem = new SelectItem();
selectItem.setValue(infoExecutionPeriod.getExternalId());
selectItem.setLabel(infoExecutionPeriod.getName() + " - " + infoExecutionPeriod.getInfoExecutionYear().getYear());
this.executionPeriodsLabels.add(selectItem);
}
}
return this.executionPeriodsLabels;
}
示例5: sortByProperties
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void sortByProperties(List<? extends Object> list, boolean isNullHigh,
boolean isReversed, String... props) {
if (CollectionUtils.isNotEmpty(list)) {
Comparator<?> typeComp = ComparableComparator.getInstance();
if (isNullHigh) {
typeComp = ComparatorUtils.nullHighComparator(typeComp);
} else {
typeComp = ComparatorUtils.nullLowComparator(typeComp);
}
if (isReversed) {
typeComp = ComparatorUtils.reversedComparator(typeComp);
}
List<Object> sortCols = new ArrayList<Object>();
if (props != null) {
for (String prop : props) {
sortCols.add(new BeanComparator(prop, typeComp));
}
}
if (sortCols.size() > 0) {
Comparator<Object> sortChain = new ComparatorChain(sortCols);
Collections.sort(list, sortChain);
}
}
}
示例6: getComparator
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Comparator<NormalizedRankListItem<RankTagListItem>> getComparator(Locale locale) {
Collator primaryCollator = Collator.getInstance(locale);
primaryCollator.setStrength(Collator.SECONDARY);
Collator secondaryCollator = Collator.getInstance(locale);
secondaryCollator.setStrength(Collator.TERTIARY);
ComparatorChain chain = new ComparatorChain();
chain.addComparator(new BeanComparator("item.name", primaryCollator));
chain.addComparator(new BeanComparator("item.name", secondaryCollator));
return chain;
}
示例7: getComparator
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Comparator<NormalizedRankListItem<RankUserListItem>> getComparator(Locale locale) {
ComparatorChain chain = new ComparatorChain();
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.SECONDARY);
chain.addComparator(new BeanComparator("item.lastName", collator));
chain.addComparator(new BeanComparator("item.firstName", collator));
chain.addComparator(new BeanComparator("item.email", collator));
chain.addComparator(new BeanComparator("item.alias", collator));
return chain;
}
示例8: getComparator
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* The comparator to use for sorting the resulting items. If null they will not be sorted.
*
* @return The comparator
*/
private static Comparator<Object> getComparator() {
Collator primaryCollator = Collator.getInstance(Locale.ENGLISH);
primaryCollator.setStrength(Collator.IDENTICAL);
ComparatorChain chain = new ComparatorChain();
chain.addComparator(new BeanComparator("rawOffset"));
chain.addComparator(new BeanComparator("sortingName", primaryCollator));
return chain;
}
示例9: getComparator
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* The comparator to use for sorting the resulting items. If null they will not be sorted.
*
* @param locale
* the locale
* @return The comparator
*/
@SuppressWarnings("rawtypes")
private Comparator getComparator(Locale locale) {
Collator primaryCollator = Collator.getInstance(locale);
primaryCollator.setStrength(Collator.SECONDARY);
Collator secondaryCollator = Collator.getInstance(locale);
secondaryCollator.setStrength(Collator.TERTIARY);
ComparatorChain chain = new ComparatorChain();
chain.addComparator(new BeanComparator(CountryConstants.NAME, primaryCollator));
chain.addComparator(new BeanComparator(CountryConstants.NAME, secondaryCollator));
return chain;
}
示例10: sortMembers
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
/**
* Sorts a list of members according to a list of SortKeySpecs.
* An in-place, Stable sort.
* Helper function for MDX OrderSet function.
*
* <p>NOTE: Does not preserve the contents of the validator.
*/
static List<Member> sortMembers(
Evaluator evaluator,
Iterable<Member> memberIter,
List<Member> memberList,
List<SortKeySpec> keySpecList)
{
if ((memberList != null) && (memberList.size() <= 1)) {
return memberList;
}
if (memberList == null) {
memberList = new ArrayList<Member>();
for (Member member : memberIter) {
memberList.add(member);
}
if (memberList.size() <= 1) {
return memberList;
}
}
ComparatorChain chain = new ComparatorChain();
for (SortKeySpec key : keySpecList) {
boolean brk = key.direction.brk;
MemberComparator comp;
if (brk) {
comp = new BreakMemberComparator(
evaluator, key.key, key.direction.descending);
} else {
comp = new HierarchicalMemberComparator(
evaluator, key.key, key.direction.descending);
}
comp.preloadValues(memberList);
chain.addComparator(comp.wrap(), false);
}
Collections.sort(memberList, chain);
return memberList;
}
示例11: getInfoEnrolmentsSorted
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
public List getInfoEnrolmentsSorted() {
final List<InfoEnrolment> infoEnrolments = getInfoEnrolments();
ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(new BeanComparator("infoExecutionPeriod.infoExecutionYear.year"));
comparatorChain.addComparator(new BeanComparator("infoExecutionPeriod.semester"));
comparatorChain.addComparator(new BeanComparator("infoCurricularCourse.name", Collator.getInstance()));
Collections.sort(infoEnrolments, comparatorChain);
return infoEnrolments;
}
示例12: sortScopes
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
private void sortScopes(List<InfoCurricularCourseScope> scopes) {
ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(new BeanComparator("infoCurricularSemester.infoCurricularYear.year"));
comparatorChain.addComparator(new BeanComparator("infoBranch.name"));
comparatorChain.addComparator(new BeanComparator("infoCurricularSemester.semester"));
comparatorChain.addComparator(new BeanComparator("infoCurricularCourse.name"));
Collections.sort(scopes, comparatorChain);
}
示例13: getComparator
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
private Comparator getComparator(HttpServletRequest request) {
final String orderParameter = request.getParameter(ORDER_PARAMETER);
final String orderGetter =
StringUtils.isEmpty(orderParameter) ? DEFAULT_ORDER_GETTER : orderParameter.substring(0,
orderParameter.indexOf(ORDER_MARKER));
final String orderDir =
StringUtils.isEmpty(orderParameter) ? DEFAULT_ORDER_DIR : orderParameter.substring(
orderParameter.indexOf(ORDER_MARKER) + 1, orderParameter.length());
final boolean orderAsc = Arrays.asList(ASC_ORDER_DIR).contains(orderDir);
if (orderGetter.equals(REQUEST_NUMBER_YEAR)) {
return orderAsc ? AcademicServiceRequest.COMPARATOR_BY_NUMBER : new ReverseComparator(
AcademicServiceRequest.COMPARATOR_BY_NUMBER);
} else if (orderGetter.equals(EXECUTION_YEAR)) {
return orderAsc ? AcademicServiceRequest.EXECUTION_YEAR_AND_OID_COMPARATOR : new ReverseComparator(
AcademicServiceRequest.EXECUTION_YEAR_AND_OID_COMPARATOR);
} else if (orderGetter.equals(REGISTRATION_NUMBER) || orderGetter.equals(DESCRIPTION)
|| orderGetter.equals(URGENT_REQUEST) || orderGetter.equals(REGISTRATION_NUMBER)
|| orderGetter.equals(REQUEST_DATE) || orderGetter.equals(ACTIVE_SITUATION_DATE)) {
final ComparatorChain chain = new ComparatorChain();
chain.addComparator(orderAsc ? new BeanComparator(orderGetter) : new ReverseComparator(
new BeanComparator(orderGetter)));
chain.addComparator(DomainObjectUtil.COMPARATOR_BY_ID);
return chain;
}
return null;
}
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:30,代码来源:AcademicServiceRequestsManagementDispatchAction.java
示例14: compare
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
@Override
public int compare(final IndividualCandidacyPersonalDetails o1, final IndividualCandidacyPersonalDetails o2) {
final ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(COMPARATOR_BY_NAME);
comparatorChain.addComparator(DomainObjectUtil.COMPARATOR_BY_ID);
return comparatorChain.compare(o1, o2);
}
示例15: compare
import org.apache.commons.collections.comparators.ComparatorChain; //导入依赖的package包/类
@Override
final public int compare(ICurriculumEntry o1, ICurriculumEntry o2) {
final ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(ICurriculumEntry.COMPARATOR_BY_EXECUTION_PERIOD);
comparatorChain.addComparator(ICurriculumEntry.COMPARATOR_BY_ID);
return comparatorChain.compare(o1, o2);
}