// Path: baseble/src/main/java/com/vise/baseble/utils/AdRecordUtil.java
// public class AdRecordUtil {
//     private AdRecordUtil() {
//         // TO AVOID INSTANTIATION
//     }
// 
//     public static String getRecordDataAsString(final AdRecord nameRecord) {
//         if (nameRecord == null) {
//             return "";
//         }
//         return new String(nameRecord.getData());
//     }
// 
//     public static byte[] getServiceData(final AdRecord serviceData) {
//         if (serviceData == null) {
//             return null;
//         }
//         if (serviceData.getType() != AdRecord.BLE_GAP_AD_TYPE_SERVICE_DATA) return null;
// 
//         final byte[] raw = serviceData.getData();
//         //Chop out the uuid
//         return Arrays.copyOfRange(raw, 2, raw.length);
//     }
// 
//     public static int getServiceDataUuid(final AdRecord serviceData) {
//         if (serviceData == null) {
//             return -1;
//         }
//         if (serviceData.getType() != AdRecord.BLE_GAP_AD_TYPE_SERVICE_DATA) return -1;
// 
//         final byte[] raw = serviceData.getData();
//         //Find UUID data in byte array
//         int uuid = (raw[1] & 0xFF) << 8;
//         uuid += (raw[0] & 0xFF);
// 
//         return uuid;
//     }
// 
//     /*
//      * Read out all the AD structures from the raw scan record
//      */
//     public static List<AdRecord> parseScanRecordAsList(final byte[] scanRecord) {
//         final List<AdRecord> records = new ArrayList<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.add(new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return Collections.unmodifiableList(records);
//     }
// 
//     public static Map<Integer, AdRecord> parseScanRecordAsMap(final byte[] scanRecord) {
//         final Map<Integer, AdRecord> records = new HashMap<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.put(type, new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return Collections.unmodifiableMap(records);
//     }
// 
//     public static SparseArray<AdRecord> parseScanRecordAsSparseArray(final byte[] scanRecord) {
//         final SparseArray<AdRecord> records = new SparseArray<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.put(type, new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return records;
//     }
// }


import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
import com.vise.baseble.utils.AdRecordUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
package com.vise.baseble.model.adrecord;




/**
 * @Description: 广播包解析仓库
 * @author: <a href="http://www.xiaoyaoyou1212.com">DAWI</a>
 * @date: 16/8/7 21:54.
 */
public class AdRecordStore implements Parcelable {

    public static final Creator<AdRecordStore> CREATOR = new Creator<AdRecordStore>() {
        public AdRecordStore createFromParcel(final Parcel in) {
            return new AdRecordStore(in);
        }

        public AdRecordStore[] newArray(final int size) {
            return new AdRecordStore[size];
        }
    };
    private static final String RECORDS_ARRAY = "records_array";
    private static final String LOCAL_NAME_COMPLETE = "local_name_complete";
    private static final String LOCAL_NAME_SHORT = "local_name_short";
    private final SparseArray<AdRecord> mAdRecords;
    private final String mLocalNameComplete;
    private final String mLocalNameShort;

    public AdRecordStore(final Parcel in) {
        final Bundle b = in.readBundle(getClass().getClassLoader());
        mAdRecords = b.getSparseParcelableArray(RECORDS_ARRAY);
        mLocalNameComplete = b.getString(LOCAL_NAME_COMPLETE);
        mLocalNameShort = b.getString(LOCAL_NAME_SHORT);
    }

    /**
     * Instantiates a new Bluetooth LE device Ad Record Store.
     *
     * @param adRecords the ad records
     */
    public AdRecordStore(final SparseArray<AdRecord> adRecords) {
        mAdRecords = adRecords;
// Path: baseble/src/main/java/com/vise/baseble/utils/AdRecordUtil.java
// public class AdRecordUtil {
//     private AdRecordUtil() {
//         // TO AVOID INSTANTIATION
//     }
// 
//     public static String getRecordDataAsString(final AdRecord nameRecord) {
//         if (nameRecord == null) {
//             return "";
//         }
//         return new String(nameRecord.getData());
//     }
// 
//     public static byte[] getServiceData(final AdRecord serviceData) {
//         if (serviceData == null) {
//             return null;
//         }
//         if (serviceData.getType() != AdRecord.BLE_GAP_AD_TYPE_SERVICE_DATA) return null;
// 
//         final byte[] raw = serviceData.getData();
//         //Chop out the uuid
//         return Arrays.copyOfRange(raw, 2, raw.length);
//     }
// 
//     public static int getServiceDataUuid(final AdRecord serviceData) {
//         if (serviceData == null) {
//             return -1;
//         }
//         if (serviceData.getType() != AdRecord.BLE_GAP_AD_TYPE_SERVICE_DATA) return -1;
// 
//         final byte[] raw = serviceData.getData();
//         //Find UUID data in byte array
//         int uuid = (raw[1] & 0xFF) << 8;
//         uuid += (raw[0] & 0xFF);
// 
//         return uuid;
//     }
// 
//     /*
//      * Read out all the AD structures from the raw scan record
//      */
//     public static List<AdRecord> parseScanRecordAsList(final byte[] scanRecord) {
//         final List<AdRecord> records = new ArrayList<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.add(new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return Collections.unmodifiableList(records);
//     }
// 
//     public static Map<Integer, AdRecord> parseScanRecordAsMap(final byte[] scanRecord) {
//         final Map<Integer, AdRecord> records = new HashMap<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.put(type, new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return Collections.unmodifiableMap(records);
//     }
// 
//     public static SparseArray<AdRecord> parseScanRecordAsSparseArray(final byte[] scanRecord) {
//         final SparseArray<AdRecord> records = new SparseArray<>();
// 
//         int index = 0;
//         while (index < scanRecord.length) {
//             final int length = scanRecord[index++];
//             //Done once we run out of records
//             if (length == 0) break;
// 
//             final int type = scanRecord[index] & 0xFF;
// 
//             //Done if our record isn't a valid type
//             if (type == 0) break;
// 
//             final byte[] data = Arrays.copyOfRange(scanRecord, index + 1, index + length);
// 
//             records.put(type, new AdRecord(length, type, data));
// 
//             //Advance
//             index += length;
//         }
// 
//         return records;
//     }
// }


// Path: baseble/src/main/java/com/vise/baseble/model/adrecord/AdRecordStore.java
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
import com.vise.baseble.utils.AdRecordUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

package com.vise.baseble.model.adrecord;




/**
 * @Description: 广播包解析仓库
 * @author: <a href="http://www.xiaoyaoyou1212.com">DAWI</a>
 * @date: 16/8/7 21:54.
 */
public class AdRecordStore implements Parcelable {

    public static final Creator<AdRecordStore> CREATOR = new Creator<AdRecordStore>() {
        public AdRecordStore createFromParcel(final Parcel in) {
            return new AdRecordStore(in);
        }

        public AdRecordStore[] newArray(final int size) {
            return new AdRecordStore[size];
        }
    };
    private static final String RECORDS_ARRAY = "records_array";
    private static final String LOCAL_NAME_COMPLETE = "local_name_complete";
    private static final String LOCAL_NAME_SHORT = "local_name_short";
    private final SparseArray<AdRecord> mAdRecords;
    private final String mLocalNameComplete;
    private final String mLocalNameShort;

    public AdRecordStore(final Parcel in) {
        final Bundle b = in.readBundle(getClass().getClassLoader());
        mAdRecords = b.getSparseParcelableArray(RECORDS_ARRAY);
        mLocalNameComplete = b.getString(LOCAL_NAME_COMPLETE);
        mLocalNameShort = b.getString(LOCAL_NAME_SHORT);
    }

    /**
     * Instantiates a new Bluetooth LE device Ad Record Store.
     *
     * @param adRecords the ad records
     */
    public AdRecordStore(final SparseArray<AdRecord> adRecords) {
        mAdRecords = adRecords;
        mLocalNameComplete = AdRecordUtil.getRecordDataAsString(mAdRecords.get(AdRecord.BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME));