Java comparator for multi-column sorting?

后端 未结 3 1857
悲哀的现实
悲哀的现实 2021-01-02 15:04

Is there any Java open-source comparator for comparing beans by multiple fields for multi-column sorting? Each column can be sorted asceding or descending.

For singl

3条回答
  •  情书的邮戳
    2021-01-02 15:55

    I recently wrote a Comparator to sort multiple fields within a delimited String record. It allows you to define the delimiter, record structure and sorting rules (some of which are type-specific).

    Required information is seeded to the Comparator itself, either programmatically or through an XML file.

    XML is validated by a package embedded XSD file. For example, below is a tab delimited record layout with four fields (two of which are sortable):

     
    
    
        	
    
        
            Column One
        
    
        
            Column Two
        
    
        
            Column Three
            2
            true
            false        
            true
        
    
        
            Column Four
            1
            true
            true
            true
            yyyy-MM-dd
        
    
    
    

    You would then use this in java like so:

    Comparator comparator = new RowComparator(
                  new XMLStructureReader(new File("layout.xml")));
    

    Library can be found here:

    http://sourceforge.net/projects/multicolumnrowcomparator/

提交回复
热议问题