Comparison record of two ways of judging in Java for loop

Source: Internet
Author: User

Recorded in the development of the month calendar display, customer requirements need to cancel the meeting in the calendar to exclude, the following two kinds of exclusion method of comparison, the second is logically wrong, there will be duplication. In fact, the reason is still their logical thinking is not good enough.

The first, correct:

Exclude canceled meetingsif(! Collectionutils.isempty (zhbg_hysgl_xxgl_qxydlist)) {//If a cancelled regular meeting is entered, excludeBooleanFlag =false; for(intj = 0; J < Zhbg_hysgl_xxgl_qxydlist.size ();
        J + +) {Zhbg_hysgl_xxgl_qxyd Qxyd = Zhbg_hysgl_xxgl_qxydlist.get (j); String canceldate =NewJava.sql.Date (C_begin.gettime (). GetTime ()). ToString ();if(Canceldate.equalsignorecase (QXYD.GETQXRQ ())) {//Judge the date that the meeting is canceled and the date of the calendar are different, add the regular meeting flag =true; Break; }
    }if(!flag) {//here to loop the properties of the entity JSON =NewJsonobject (); Json.put ("id", Bean.gethysxxglid ());
        STRKSSJ = BEAN.GETLHKSSJ (); SimpleDateFormat SDF =NewSimpleDateFormat ("hh:mm");
        Date sdate = Sdf.parse (STRKSSJ);
        STRJSSJ = BEAN.GETLHJSSJ ();
        Date edate = Sdf.parse (STRJSSJ);
        BSW = Sdate.gethours () <= 12; Bxw = Edate.gethours () <= 12;if(BSW && Bxw) {STRSW ="Morning"; }else if(Sdate.gethours () > && edate.gethours () > 12) {STRSW ="Afternoon"; }Else{STRSW ="All Day"; } json.put ("Start",NewJava.sql.Date (C_begin.gettime (). GetTime ()) +" " + BEAN.GETLHKSSJ ()); Json.put ("End",NewJava.sql.Date (C_begin.gettime (). GetTime ()) +" " + BEAN.GETLHJSSJ ()); Json.put ("description", BEAN.GETLHMC ()); Json.put ("Hys", STRSW +" " + ENTXXGL.GETHYSMC ()); Json.put ("SQBM", Entxxgl.getssdw_tname ()); Json.put ("chrs", entxxgl.getrnchrs ()); Json.put ("Sfapcs",""); Json.put ("Hybztsyq","");
    Jsona.add (JSON); }
}
The second type of error:

Exclude canceled meetingsif(! Collectionutils.isempty (zhbg_hysgl_xxgl_qxydlist)) {//If a cancelled regular meeting is entered, exclude for(intj = 0; J < Zhbg_hysgl_xxgl_qxydlist.size ();
        J + +) {Zhbg_hysgl_xxgl_qxyd Qxyd = Zhbg_hysgl_xxgl_qxydlist.get (j); String canceldate =NewJava.sql.Date (C_begin.gettime (). GetTime ()). ToString ();if(!canceldate.equalsignorecase (QXYD.GETQXRQ ())) {//The date of the cancellation of the meeting is different from the date of the calendar, not the same as to add the regular//here to iterate over the properties of the entity JSON =NewJsonobject (); Json.put ("id", Bean.gethysxxglid ());
            STRKSSJ = BEAN.GETLHKSSJ (); SimpleDateFormat SDF =NewSimpleDateFormat ("hh:mm");
            Date sdate = Sdf.parse (STRKSSJ);
            STRJSSJ = BEAN.GETLHJSSJ ();
            Date edate = Sdf.parse (STRJSSJ);
            BSW = Sdate.gethours () <= 12; Bxw = Edate.gethours () <= 12;if(BSW && Bxw) {STRSW ="Morning"; }else if(Sdate.gethours () > && edate.gethours () > 12) {STRSW ="Afternoon"; }Else{STRSW ="All Day"; } json.put ("Start",NewJava.sql.Date (C_begin.gettime (). GetTime ()) +" " + BEAN.GETLHKSSJ ()); Json.put ("End",NewJava.sql.Date (C_begin.gettime (). GetTime ()) +" " + BEAN.GETLHJSSJ ()); Json.put ("description", BEAN.GETLHMC ()); Json.put ("Hys", STRSW +" " + ENTXXGL.GETHYSMC ()); Json.put ("SQBM", Entxxgl.getssdw_tname ()); Json.put ("chrs", entxxgl.getrnchrs ()); Json.put ("Sfapcs",""); Json.put ("Hybztsyq","");
        Jsona.add (JSON); }
    }
}

Related Article

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.