/** * * Determine the legality of the change of membership level * 1. When sorts is greater than all sorts values in the database (1,3) 5 * 2.1 (Sorts) * 3 when sorts is less than all 3,5 values in the database. When sorts equals number All sorts values in the library are 1 (1,3,5) * 4. When sorts can find values greater than and less than its value in the database 3 (1,5) * Description: 1. First determine the length of the list, (greater than 1, equal to 1, equals 0) three cases * 2. When l Ist.size () >1, sets the sort field in the database to a string, and then converts an array of 2.1 when sorts equals all sorts values in the database 1 (1,3,5) * 2.2 Gets the maximum, minimum * 2.3. When sorts is greater than all sorts values in the database (1,3) 5 * 2.4 When sorts is less than all sorts values in the database 1 (3,5) * 2.5 when sorts in the database can find a value greater than and less than its 3 (1,2,4,5) * 2.5.1 Split (1,2,4,5) to get 3 before the data array [up], and then get 3 before a data to judge * 2.5.2 Split ( , 4,5) gets 3 of the data after the array [4,5], and then gets 3 after a data is judged *@paramSorts ranking of membership levels *@paramLimitmax Required cumulative minimum (with minimum value to save the accumulated value, the maximum value is reserved for later use) *@paramThe UPD is used to determine if the validation is modified 0: not 1: Yes *@paramReq *@paramRESP *@return*/ @RequestMapping("/leveljudgetwo.jhtml")@ResponseBody PublicStringLeveljudgetwo(@RequestParamintSorts, @RequestParamintLimitmax, @RequestParamintUPD, @RequestParam String sortflag,httpservletrequest req, httpservletrespons E resp) {intshop_id =2; String str ="Yes"; String str1 ="";BooleanFlag =true; list<memberlevel> list = This. Memberlevelservice.listobjectall ();//Traversal of all objectsSystem.out.println ("Sorts------------------"+sorts); System.out.println ("Limitmax------------------"+limitmax);/* * when list.size () >1, make a string of the sort field in the database, and then convert the array */ if(List.size () >1) { for(Memberlevel level:list) {intSortstwo = Level.getsort (); STR1 = str1 + Sortstwo +","; } str1 = Str1.substring (0, Str1.length ()-1); string[] arr = Str1.split (","); String [] Arrone = {Sortflag}; string[] Arrresult = This. Memberlevelservice.arrcontrast (arr, arrone); for(intI=0; i<arrresult.length;i++) {if(Sorts==integer.parseint (Arrresult[i])) {flag =false; } }//for (int i = 0; i < arr.length; i++) { ////System.out.println ("arr[]--------" +arr[i]); // /* //* 3. When sorts equals all sorts values in the database 1 (1,3,5) // */ //if (sorts = = Integer.parseint (Arr[i])) {//When the database already has the rank of sort, flag=false //flag = false; //break; // } // } / * * Get the maximum and minimum value in the array */ intNMax = Integer.parseint (arr[0]);//Maximum value intNMin = Integer.parseint (arr[0]);//min value for(inti =0; i < arr.length; i++) {if(NMin > Integer.parseint (arr[i])) {nMin = Integer.parseint (Arr[i]); }if(NMax < Integer.parseint (Arr[i])) {NMax = Integer.parseint (Arr[i]); }} memberlevel Level2 = This. Memberlevelservice.getobjectbysort (shop_id, NMax);//Find objects by Store ID and sort numberMemberlevel LEVEL3 = This. Memberlevelservice.getobjectbysort (shop_id, nMin);//Find objects by Store ID and sort number intLimit_max1 = Level2.getlimit_max ();//Required cumulative minimum (save accumulated value with minimum value, maximum value reserved for later use) intLIMIT_MAX2 = Level3.getlimit_max ();//Required cumulative minimum (save accumulated value with minimum value, maximum value reserved for later use) /* * 1. When sorts equals to all sorts values in the database (1,3,5) 5 */ if(Sorts >= NMax) {intmax = Integer.parseint (arr[0]);//Maximum value intSecond =integer.parseint (arr[1]);//Secondary Large value for(inti =0; i < arr.length;i++) {if(Integer.parseint (Arr[i]) > Max)//Update maximum and sub-large values{second = max; max = Integer.parseint (Arr[i]); }Else if(Integer.parseint (Arr[i]) < Max && Integer.parseint (Arr[i]) > second)//Update secondary large value{second = Integer.parseint (Arr[i]);//Get a value of 3} Memberlevel Level5 = This. Memberlevelservice.getobjectbysort (shop_id, second);//Find objects by Store ID and sort number intLIMIT_MAX5 = Level5.getlimit_max ();//Required cumulative minimum (save accumulated value with minimum value, maximum value reserved for later use) if(Limitmax <= limit_max5) {//Do not meet the conditions, Flag=falseFlag =false; } } }/* * 2. When sorts equals all sorts values in the minimum database 1 (1,3,5) */ if(Sorts <= nMin) {intmin = Integer.parseint (arr[0]);//Maximum value intSecond =integer.parseint (arr[1]);//Secondary Large value if(Min > Second) {//Find the second small value in the arraymin = Integer.parseint (arr[1]); Second = Integer.parseint (arr[0]); } for(inti =2; i < arr.length; + + i) {if(Integer.parseint (Arr[i]) < min) {second = min; min = Integer.parseint (arr[i]); }Else if(Integer.parseint (Arr[i]) < second) {second = Integer.parseint (Arr[i]); }} memberlevel Level6 = This. Memberlevelservice.getobjectbysort (shop_id, second);//Find objects by Store ID and sort number intlimit_max6 = Level6.getlimit_max ();//Required cumulative minimum (save accumulated value with minimum value, maximum value reserved for later use) if(Limitmax >= limit_max6) {//Do not meet the conditions, Flag=falseFlag =false; }} System.out.println ("Flag----------------------"+flag);/* * 4. When sorts can find values greater than and less than its value in the database 3 (1,2,3,4,5) */String str2 =""; String STR3 ="";if(NMin < sorts && sorts < NMax) { for(intj =0; J < Arr.length; J + +) {intP1 =0;intP2 =0;/ * * Sorts data in front of the array * / if(Integer.parseint (Arr[j]) < sorts) {str2 = str2 + arr[j] +","; p1++; }if(P1 >1) {//sort before the number of more than 1STR2 = str2.substring (0, Str2.length ()-1); System.out.println ("str2----------"+STR2); string[] arr2 = Str2.split (",");intNMAX2 = Integer.parseint (arr[0]); for(inti =1; i < arr2.length; i++) {if(NMax2 < Integer.parseint (Arr2[i])) {nMax2 = Integer.parseint (Arr2[i]); }} memberlevel Level7 = This. Memberlevelservice.getobjectbysort (shop_id, NMAX2);intLIMIT_MAX7 = Level7.getlimit_max ();if(Limitmax < LIMIT_MAX7) {flag =false; } }Else{there are only 1 digits before//sort. if(Limitmax <= limit_max1) {flag =false; } }/ * * Sorts data in the following array * / if(Integer.parseint (Arr[j]) >sorts) {STR3 = Str3 + arr[j] +","; p2++; }if(P2 >1) {//sort before the number of more than 1STR3 = str3.substring (0, Str3.length ()-1); System.out.println ("Str3----------"+STR3); string[] arr2 = Str3.split (",");intNMax3 = Integer.parseint (arr[0]); for(inti =1; i < arr2.length; i++) {if(NMax3 < Integer.parseint (Arr2[i])) {nmax3= integer.parseint (arr2[i]); }} memberlevel Level8 = This. Memberlevelservice.getobjectbysort (shop_id, nMax3);intlimit_max8 = Level8.getlimit_max ();if(Limitmax >= limit_max8) {flag =false; } }Else{There is only one number after//sort if(Limitmax >=limit_max2) {flag =false; } } } } }if(!flag) {The //flag state is used to determinestr ="No"; }returnStr }
Related programs for manipulating arrays