Hbigoal Association sorting

Source: Internet
Author: User

Scenario: assume there are two table request information and account tables, which are one-to-many relationships. The corresponding java classes are Sfcx_RequestInfo and Sfcx_Zhxx. Sfcx_RequestInfo has a Set attribute sfcx_Zhxxs. You need to sort Sfcx_Zhxx by the account information query sequence number (ccxh. Solution: 1: configure the account information comparison auxiliary class. You can also define internal classes or write them to Sfcx_RequestInfo. Implement the Comparator interface. Override the compare method. Specify the configuration rules in this method.

package com.levelappro.gbism.app.sfcx.model;    import java.util.Comparator;    public class ComparatorZhxx implements Comparator<Sfcx_Zhxx> {        public int compare(Sfcx_Zhxx z1, Sfcx_Zhxx z2) {              if(z1.getCcxh().compareTo(z2.getCcxh())>0)               return 1;               if(z1.getCcxh().compareTo(z2.getCcxh())<0)               return -1;               return 0;           }     }  

 

2: define a new get method getSfcx_ZhxxsTreeSet on one side (Sfcx_RequestInfo) to deploy the sorted TreeSet.
/*** Get an ordered set of account information, sorted by the query Sequence Number * @ return */public TreeSet <Sfcx_Zhxx> getSfcx_ZhxxsTreeSet () {TreeSet <Sfcx_Zhxx> zhxxTreeSet = new TreeSet <Sfcx_Zhxx> (new ComparatorZhxx (); zhxxTreeSet. addAll (sfcx_Zhxxs); return zhxxTreeSet ;}

 

3: Call getSfcx_ZhxxsTreeSet to obtain the set of TreeSet.
for(Sfcx_RequestInfo info :infos){              TreeSet<Sfcx_Zhxx> zhxxSet = info.getSfcx_ZhxxsTreeSet();  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.