Java multiple devices, locking sequencing

Source: Internet
Author: User

Scene Map:

4 Android devices need to be locked in order, the next time in order to push the socket data to these 4 different content. When a new machine is added, such as e, it is inserted into the place where the original position is C. The specific code is as follows:

 Public StaticArraylist<deviceloginentity> Setdeviceorder (arraylist<deviceloginentity>devices,string Orderstr) {        if(Stringutil.isnullorempty (ORDERSTR) | | devices = =NULL|| Devices.size () <= 0) {LOG.V ("Deviceutil", "if (Stringutil.isnullorempty (orderstr) | | | devices = = NULL | | Devices.size () > 0) return directly to Devices "); returndevices; }        Else{LOG.V ("Setdeviceorder", "orderstr=" +orderstr); String[] Orderstrarr= Orderstr.split ("\\|"); //priority will exist in the devices,             for(inti=0;i<orderstrarr.length;i++)            {                 for(intJ=0;j<devices.size (); j + +)                {                    if(Orderstrarr[i].equals (Devices.get (j). android_id)) {Devices.get (j). SN=i; }                }            }            //will be involved in Devices.get (j). sn= default value of 100 is set to not in {1,2,3,4} condition            intFlag =-1;  for(intI=0;i<devices.size (); i++)            {                intj = 0;  for(J=0;j<devices.size (); j + +)                {                    if(Devices.get (j). sn = =i) { Break;} }                if(j = = Devices.size ())//Description not found{flag=i;  Break; }            }             for(intI=0;i<devices.size (); i++)            {                if(Devices.get (i). sn = = && Flag!=-1)                {                    //then the SN is set to Devices.get (i). SN non-existent numberDevices.get (i). sn =Flag; }            }            //then the devices SN is sorted, the smaller the more in frontComparator<deviceloginentity> Comparator =NewComparator<deviceloginentity>(){                       Public intCompare (deviceloginentity s1, deviceloginentity S2) {if(S1.sn <s2.sn) {                            return-1; }                          Else                            return1;              }                  }; Collections.sort (Devices, comparator);//Sort by attribute Sn, from small to large//For (deviceloginentity en:devices)//            {//log.e ("Setdeviceorder", "deviceloginentity=" +en.android_id+ "; sn=" +en.sn);//            }            returndevices; }    }

Java multiple devices, locking sequencing

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.