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