当前位置: 首页>>代码示例>>Java>>正文


Java ComparableComparator类代码示例

本文整理汇总了Java中org.apache.commons.collections.comparators.ComparableComparator的典型用法代码示例。如果您正苦于以下问题:Java ComparableComparator类的具体用法?Java ComparableComparator怎么用?Java ComparableComparator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ComparableComparator类属于org.apache.commons.collections.comparators包,在下文中一共展示了ComparableComparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sortListBeans

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的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);
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:33,代码来源:MyBeanUtils.java

示例2: getAppropriateComparatorForPropertyClass

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
 * This method returns a comparator to be used for comparing the contents of cells, that is
 * the compareTo method will be invoked w/ displaytag Cell objects
 * @param propClass
 * @return
 */
public static Comparator getAppropriateComparatorForPropertyClass(Class propClass) {
    // TODO, do we really need to create so many comparators (1 per each cell)?
    if (propClass == null) {
        return new NullCellComparator();
    }
    else if (TypeUtils.isDecimalClass(propClass) || TypeUtils.isIntegralClass(propClass)) {
        return new NumericCellComparator();
    }
    else if (TypeUtils.isTemporalClass(propClass)) {
        return new TemporalCellComparator();
    }
    else if (String.class.equals(propClass)) {
        // StringCellComparator is smarter about nulls than String.CASE_INSENSITIVE_ORDER
        return new StringCellComparator();
    }
    else {
        return ComparableComparator.getInstance();
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:26,代码来源:CellComparatorHelper.java

示例3: getAppropriateValueComparatorForPropertyClass

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
 * This method returns a comparator to be used for comparing propertyValues (in String form)
 * @param propClass
 * @return
 */
public static Comparator getAppropriateValueComparatorForPropertyClass(Class propClass) {
    if (propClass == null) {
        return NullValueComparator.getInstance();
    }
    else if (TypeUtils.isDecimalClass(propClass) || TypeUtils.isIntegralClass(propClass)) {
        return NumericValueComparator.getInstance();
    }
    else if (TypeUtils.isTemporalClass(propClass)) {
        return TemporalValueComparator.getInstance();
    }
    else if (String.class.equals(propClass)) {
        // StringCellComparator is smarter about nulls than String.CASE_INSENSITIVE_ORDER
        return StringValueComparator.getInstance();
    }
    else {
        return ComparableComparator.getInstance();
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:24,代码来源:CellComparatorHelper.java

示例4: getWebFriendlyRecipients

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
  * Converts a collection of Recipients into a collection of WebFriendlyRecipients which can be displayed in the UI
  * @param recipients recipients to convert
  * @return a collection of WebFriendlyRecipients which can be displayed in the UI
  */
 public static List<WebFriendlyRecipient> getWebFriendlyRecipients(Collection<Recipient> recipients) {
     Collection<WebFriendlyRecipient> newRecipients = new ArrayList<WebFriendlyRecipient>(recipients.size());
     for (Recipient recipient : recipients) {
         newRecipients.add(new WebFriendlyRecipient(recipient));
     }
     List<WebFriendlyRecipient> recipientList = new ArrayList<WebFriendlyRecipient>(newRecipients);
     Collections.sort(recipientList, new Comparator<WebFriendlyRecipient>() {
         Comparator<String> comp = new ComparableComparator();

         @Override
public int compare(WebFriendlyRecipient o1, WebFriendlyRecipient o2) {
             return comp.compare(o1.getDisplayName().trim().toLowerCase(), o2.getDisplayName().trim().toLowerCase());
         }
     });
     return recipientList;
 }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:22,代码来源:ActionListUtil.java

示例5: sort

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
 * This method will sort a passed Collection
 *
 * @param c The collection to sort
 * @param sortProperty The javabean property to sort the elements of the Collection by
 * @param reverseOrder Boolean indicating whether or not to reverse the order of the collection
 * @return A sorted List of the passed elements
 */
public static <T> List<T> sort(Collection<T> c, String sortProperty, Boolean reverseOrder) {
	if (StringUtils.isEmpty(sortProperty)) {
		throw new IllegalArgumentException("sortProperty = " + sortProperty);
	}
	// fail early if the passed collection is null
	if (c == null) {
		return null;
	}
	
	// fail early if the passed collection is empty
	if (c.size() == 0) {
		return Collections.emptyList();
	}
	
	List<T> l = new ArrayList<T>(c);
	Comparator comp = new BeanComparator(sortProperty, new ComparableComparator());
	Collections.sort(l, comp);
	if (reverseOrder) {
		Collections.reverse(l);
	}
	return l;
}
 
开发者ID:openmrs,项目名称:openmrs-module-legacyui,代码行数:31,代码来源:Sort.java

示例6: testIterator

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
public void testIterator() throws Exception {
    final File logPath = new File(tmpDir, "tmp.log");
    VolatileGeneration<Integer, Long> volatileGeneration = new VolatileGeneration(logPath, new IntSerializer(), new LongSerializer(), new ComparableComparator());
    int[] random = new int[1000000];
    Random r = new Random(0);
    for (int i = 0; i < random.length; i++) {
        random[i] = r.nextInt();
    }
    for (int element : random) {
        volatileGeneration.put(element, (long)element);
    }
    int[] sorted = new int[random.length];
    System.arraycopy(random, 0, sorted, 0, random.length);
    Arrays.sort(sorted);
    verifyIterationOrder(volatileGeneration, sorted);

    volatileGeneration.close();
    volatileGeneration = new VolatileGeneration<Integer, Long>(new File(tmpDir, "tmp2.log"), new IntSerializer(), new LongSerializer(), new ComparableComparator());
    volatileGeneration.replayTransactionLog(logPath);
    verifyIterationOrder(volatileGeneration, sorted);
}
 
开发者ID:indeedeng,项目名称:lsmtree,代码行数:22,代码来源:TestVolatileGeneration.java

示例7: getSorter

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Sorter getSorter(int trimSize, AggregationFunction aggregationFunction, boolean isComparable) {
  // This will cover both MIN and MINMV
  boolean minOrder = aggregationFunction instanceof MinAggregationFunction;

  if (isComparable) {
    if (minOrder) {
      return new ComparableSorter(trimSize, Collections.reverseOrder());
    } else {
      return new ComparableSorter(trimSize, new ComparableComparator());
    }
  } else {
    // Reverse the comparator so that keys are ordered in descending order
    if (minOrder) {
      return new NonComparableSorter(trimSize, new ComparableComparator(), aggregationFunction);
    } else {
      return new NonComparableSorter(trimSize, Collections.reverseOrder(), aggregationFunction);
    }
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:21,代码来源:AggregationGroupByTrimmingService.java

示例8: sortByProperties

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的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);
        }
    }
}
 
开发者ID:Topview-us,项目名称:school-website,代码行数:28,代码来源:ExcelUtils.java

示例9: BeanPropertyComparator

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
 * Constructs a PropertyComparator for comparing beans using the properties named in the given List.
 *
 * <p>Properties will be compared
 * in the order in which they are listed. Case will be ignored if ignoreCase is true.</p>
 * 
 * @param propertyNames List of property names (as Strings) used to compare beans
 * @param ignoreCase if true, case will be ignored during String comparisons
 */
public BeanPropertyComparator(List propertyNames, boolean ignoreCase) {
    if (propertyNames == null) {
        throw new IllegalArgumentException("invalid (null) propertyNames list");
    }
    if (propertyNames.size() == 0) {
        throw new IllegalArgumentException("invalid (empty) propertyNames list");
    }
    this.propertyNames = Collections.unmodifiableList(propertyNames);
    this.ignoreCase = ignoreCase;

    if (ignoreCase) {
        this.stringComparator = String.CASE_INSENSITIVE_ORDER;
    }
    else {
        this.stringComparator = ComparableComparator.getInstance();
    }
    this.booleanComparator = new Comparator() {
        public int compare(Object o1, Object o2) {
            int compared = 0;

            Boolean b1 = (Boolean) o1;
            Boolean b2 = (Boolean) o2;

            if (!b1.equals(b2)) {
                if (b1.equals(Boolean.FALSE)) {
                    compared = -1;
                }
                else {
                    compared = 1;
                }
            }

            return compared;
        }

    };
    this.genericComparator = ComparableComparator.getInstance();
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:48,代码来源:BeanPropertyComparator.java

示例10: doStartTag

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
public int doStartTag() {
	if (drugOrders == null || drugOrders.isEmpty()) {
		log.error("ForEachDrugOrderTag skipping body due to drugOrders param being null or empty: " + drugOrders);
		return SKIP_BODY;
	}
	// First retrieve all encounters matching the passed concept id, if provided.
	// If not provided, return all encounters
	matchingDrugOrders = new ArrayList<DrugOrder>();
	for (Iterator<DrugOrder> i = drugOrders.iterator(); i.hasNext();) {
		DrugOrder d = i.next();
		if (d != null) {
			// TODO: eventually we might want to have criteria, but not yet
			matchingDrugOrders.add(d);
		}
	}
	log.debug("ForEachDrugOrderTag found " + matchingDrugOrders.size() + " drug orders");
	
	// Next, sort the encounters
	if (StringUtils.isEmpty(sortBy)) {
		sortBy = defaultSortBy;
	}
	Comparator comp = new BeanComparator(sortBy, (descending ? new ReverseComparator(new ComparableComparator())
	        : new ComparableComparator()));
	try {
		Collections.sort(matchingDrugOrders, comp);
	}
	catch (ClassCastException cce) {
		log
		        .error("ForEachDrugTag unable to compare the list of drug orders passed.  Ensure they are compatible with Comparator used.");
	}
	
	// Return appropriate number of results
	if (matchingDrugOrders.isEmpty()) {
		return SKIP_BODY;
	} else {
		pageContext.setAttribute(var, matchingDrugOrders.get(count++));
		return EVAL_BODY_BUFFERED;
	}
}
 
开发者ID:openmrs,项目名称:openmrs-module-legacyui,代码行数:40,代码来源:ForEachDrugOrderTag.java

示例11: doStartTag

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
@Override
public int doStartTag() {
	if (visits == null || visits.isEmpty()) {
		log.debug("ForEachVisitTag skipping body due to 'visits' param = " + visits);
		return SKIP_BODY;
	}
	// First retrieve all visits matching the passed visit type id, if provided.
	// If not provided, return all visits
	matchingVisits = new ArrayList<Visit>();
	for (Iterator<Visit> i = visits.iterator(); i.hasNext();) {
		Visit e = i.next();
		if (type == null || e.getVisitType().getVisitTypeId().intValue() == type.intValue()) {
			matchingVisits.add(e);
		}
	}
	log.debug("ForEachVisitTag found " + matchingVisits.size() + " visits matching type = " + type);
	
	// Next, sort the visits
	if (StringUtils.isEmpty(sortBy)) {
		sortBy = "visitDatetime";
	}
	Comparator comp = new BeanComparator(sortBy, (descending ? new ReverseComparator(new ComparableComparator())
	        : new ComparableComparator()));
	Collections.sort(matchingVisits, comp);
	
	// Return appropriate number of results
	if (matchingVisits.isEmpty()) {
		return SKIP_BODY;
	} else {
		pageContext.setAttribute(var, matchingVisits.get(count++));
		return EVAL_BODY_BUFFERED;
	}
}
 
开发者ID:openmrs,项目名称:openmrs-module-legacyui,代码行数:34,代码来源:ForEachVisitTag.java

示例12: doStartTag

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
public int doStartTag() {
	
	if (obs == null || obs.isEmpty()) {
		log.error("ForEachObsTag skipping body due to obs param = " + obs);
		return SKIP_BODY;
	}
	// First retrieve all observations matching the passed concept id, if provided.
	// If not provided, return all observations
	matchingObs = new ArrayList<Obs>();
	for (Iterator<Obs> i = obs.iterator(); i.hasNext();) {
		Obs o = i.next();
		if (conceptId == null
		        || (o.getConcept() != null && o.getConcept().getConceptId().intValue() == conceptId.intValue())) {
			matchingObs.add(o);
		}
	}
	log.debug("ForEachObsTag found " + matchingObs.size() + " observations matching conceptId = " + conceptId);
	
	// Next, sort these observations
	if (StringUtils.isEmpty(sortBy)) {
		sortBy = "obsDatetime";
	}
	Comparator comp = new BeanComparator(sortBy, (descending ? new ReverseComparator(new ComparableComparator())
	        : new ComparableComparator()));
	Collections.sort(matchingObs, comp);
	
	// Return appropriate number of results
	if (matchingObs.isEmpty()) {
		return SKIP_BODY;
	} else {
		pageContext.setAttribute(var, matchingObs.get(count++));
		return EVAL_BODY_BUFFERED;
	}
}
 
开发者ID:openmrs,项目名称:openmrs-module-legacyui,代码行数:35,代码来源:ForEachObsTag.java

示例13: provide

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
@Override
public Object provide(Object source, Object currentValue) {

    AlumniMailSendToBean bean = (AlumniMailSendToBean) source;
    final List<Degree> degrees = new ArrayList<Degree>(bean.getDegreeType().getDegreeSet());
    Collections.sort(degrees, new ComparableComparator());
    return degrees;
}
 
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:9,代码来源:AlumniSearchDegreeProvider.java

示例14: BucketDefinition

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
/**
 * Creates a bucket.
 * 
 * @param valueClass the class of the bucket values
 * @param orderer bucket entries orderer
 * @param comparator the comparator to use for bucket sorting
 * @param order the order type, {@link BucketOrder#ASCENDING}, {@link BucketOrder#DESCENDING} or {@link BucketOrder#NONE}
 * @param totalPosition the position of the total bucket
 * @throws JRException
 */
public BucketDefinition(Class<?> valueClass, 
		BucketOrderer orderer, Comparator<Object> comparator, BucketOrder order, 
		CrosstabTotalPositionEnum totalPosition) throws JRException
{
	this.orderer = orderer;
	this.order = order;
	
	if (orderer == null)
	{
		// we don't have a bucket orderer
		if (order == BucketOrder.NONE)
		{
			// no ordering, values are inserted in the order in which they come
			this.bucketValueComparator = null;
		}
		else
		{
			// the buckets are ordered using the bucket values
			// if there's no comparator, we're assuming that the values are Comparable
			this.bucketValueComparator = createOrderComparator(comparator, order);
		}
	}
	else
	{
		// we have an order by expression
		// we only need an internal ordering for bucket values
		if (Comparable.class.isAssignableFrom(valueClass))
		{
			// using natural order
			this.bucketValueComparator = ComparableComparator.getInstance();
		}
		else
		{
			// using an arbitrary rank comparator
			// TODO lucianc couldn't we just set here bucketValueComparator to null?
			if (log.isDebugEnabled())
			{
				log.debug("Using arbitrary rank comparator for bucket");
			}
			
			this.bucketValueComparator = new ArbitraryRankComparator();
		}
	}
	
	this.totalPosition = totalPosition;
	computeTotal = totalPosition != CrosstabTotalPositionEnum.NONE || orderer != null;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:58,代码来源:BucketDefinition.java

示例15: getSortOrder

import org.apache.commons.collections.comparators.ComparableComparator; //导入依赖的package包/类
@Override
public Comparator<TitanElement> getSortOrder() {
    if (orders.isEmpty()) return new ComparableComparator();
    else return orders;
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:6,代码来源:GraphCentricQuery.java


注:本文中的org.apache.commons.collections.comparators.ComparableComparator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。