Optimize a piece of code today, as follows
intnum = 0; BooleanSkipappend =false; intTypes_ext1[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture, Moduletype.type_bookmark,moduletype.type_music}; intTypes_ext2[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture, Moduletype.type_bookmark,moduletype.type_calendar}; intTypes_ext3[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture, Moduletype.type_bookmark};if(Misgoogleorigcalendarexist &&misgoogleorigmusicexist) {num=types.length; for(inti = 0; i < num; i++) {Types_ext[i]=Types[i]; } mylogger.loge ("YJP", "Music & Calendar is not 3rd-party"); } Else if(! (Misgoogleorigcalendarexist | |misgoogleorigmusicexist)) {num=types_ext3.length; for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext3[i]; } mylogger.loge ("YJP", "Music & Calendar is 3rd-party"); } Else if(!misgoogleorigcalendarexist &&misgoogleorigmusicexist) {num=types_ext1.length; for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext1[i]; } mylogger.loge ("YJP", "Calendar is 3rd-party"); } Else if(Misgoogleorigcalendarexist &&!)misgoogleorigmusicexist) {num=types_ext2.length; for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext2[i]; } mylogger.loge ("YJP", "Music is 3rd-party"); }
This code, in fact, is to change the elements inside the int[]. Because the int[] array is more troublesome to delete, can only rely on the loop to extract to another array. So, I thought of using list, so it's very convenient to change dynamically.
As follows
Arraylist<integer> typelist =NewArraylist<integer>(); for(inti = 0; i < types.length; i++) {Typelist.add (types[i]); } Try{Packagemanager PM1=Getpackagemanager (); Pm1.getpackageinfo ("Com.android.calendar", packagemanager.get_activities); Misgoogleorigcalendarexist=true; } Catch(packagemanager.namenotfoundexception e) {Mylogger.loge ("YJP", "Google original Calendar not found"); } Try{Packagemanager PM2=Getpackagemanager (); Pm2.getpackageinfo ("Com.android.music", packagemanager.get_activities); Misgoogleorigmusicexist=true; } Catch(packagemanager.namenotfoundexception e) {Mylogger.loge ("YJP", "Google original Music not found"); } if(!misgoogleorigmusicexist) {Typelist.remove (integer.valueof (moduletype.type_music)); } if(!misgoogleorigcalendarexist) {Typelist.remove (integer.valueof (Moduletype.type_calendar)); } if(Featureoption.vanzo_oos_browser_support) {Typelist.remove (integer.valueof (Moduletype.type_bookmark)) ; } intnum = Typelist.size ();
Android-arraylist use