finalised things that could be final

This commit is contained in:
Alexandros Schillings
2015-07-03 14:32:19 +01:00
parent 67bc13a9c2
commit 56e27ffab1
25 changed files with 134 additions and 112 deletions
@@ -47,11 +47,11 @@ public class BluetoothLeDevice implements Parcelable{
/** The Constant CREATOR. */
public static final Parcelable.Creator<BluetoothLeDevice> CREATOR = new Parcelable.Creator<BluetoothLeDevice>() {
public BluetoothLeDevice createFromParcel(Parcel in) {
public BluetoothLeDevice createFromParcel(final Parcel in) {
return new BluetoothLeDevice(in);
}
public BluetoothLeDevice[] newArray(int size) {
public BluetoothLeDevice[] newArray(final int size) {
return new BluetoothLeDevice[size];
}
};
@@ -64,7 +64,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param scanRecord the scan record of the device
* @param timestamp the timestamp of the RSSI reading
*/
public BluetoothLeDevice(BluetoothDevice device, int rssi, byte[] scanRecord, long timestamp){
public BluetoothLeDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord, final long timestamp){
mDevice = device;
mFirstRssi = rssi;
mFirstTimestamp = timestamp;
@@ -79,7 +79,7 @@ public class BluetoothLeDevice implements Parcelable{
*
* @param device the device
*/
public BluetoothLeDevice(BluetoothLeDevice device) {
public BluetoothLeDevice(final BluetoothLeDevice device) {
mCurrentRssi = device.getRssi();
mCurrentTimestamp = device.getTimestamp();
mDevice = device.getDevice();
@@ -97,7 +97,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param in the in
*/
@SuppressWarnings("unchecked")
protected BluetoothLeDevice(Parcel in) {
protected BluetoothLeDevice(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader());
mCurrentRssi = b.getInt(PARCEL_EXTRA_CURRENT_RSSI, 0);
@@ -116,7 +116,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param timestamp the timestamp
* @param rssiReading the rssi reading
*/
private void addToRssiLog(long timestamp, int rssiReading){
private void addToRssiLog(final long timestamp, final int rssiReading){
synchronized (mRssiLog) {
if(timestamp - mCurrentTimestamp > LOG_INVALIDATION_THRESHOLD){
mRssiLog.clear();
@@ -140,14 +140,14 @@ public class BluetoothLeDevice implements Parcelable{
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BluetoothLeDevice other = (BluetoothLeDevice) obj;
final BluetoothLeDevice other = (BluetoothLeDevice) obj;
if (mCurrentRssi != other.mCurrentRssi)
return false;
if (mCurrentTimestamp != other.mCurrentTimestamp)
@@ -348,7 +348,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param timestamp the timestamp
* @param rssiReading the rssi reading
*/
public void updateRssiReading(long timestamp, int rssiReading){
public void updateRssiReading(final long timestamp, final int rssiReading){
addToRssiLog(timestamp, rssiReading);
}
@@ -356,7 +356,7 @@ public class BluetoothLeDevice implements Parcelable{
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/
@Override
public void writeToParcel(Parcel parcel, int arg1) {
public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle(getClass().getClassLoader());
b.putByteArray(PARCEL_EXTRA_DEVICE_SCANRECORD, mScanRecord);
@@ -380,7 +380,7 @@ public class BluetoothLeDevice implements Parcelable{
* @param bondState the bond state
* @return the string
*/
private static String resolveBondingState(int bondState){
private static String resolveBondingState(final int bondState){
switch (bondState){
case BluetoothDevice.BOND_BONDED:
return "Paired";
@@ -19,7 +19,7 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param scanRecord the scanRecord
* @throws IllegalArgumentException if the passed device is not an iBeacon
*/
public IBeaconDevice(BluetoothDevice device, int rssi, byte[] scanRecord) {
public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
super(device, rssi, scanRecord, 0);
validate();
mIBeaconData = new IBeaconManufacturerData(this);
@@ -34,7 +34,7 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param timestamp the timestamp of the RSSI measurement
* @throws IllegalArgumentException if the passed device is not an iBeacon
*/
public IBeaconDevice(BluetoothDevice device, int rssi, byte[] scanRecord, long timestamp){
public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord, final long timestamp){
super(device, rssi, scanRecord, timestamp);
validate();
mIBeaconData = new IBeaconManufacturerData(this);
@@ -47,13 +47,13 @@ public class IBeaconDevice extends BluetoothLeDevice{
* @param device the device
* @throws IllegalArgumentException if the passed device is not an iBeacon
*/
public IBeaconDevice(BluetoothLeDevice device){
public IBeaconDevice(final BluetoothLeDevice device){
super(device);
validate();
mIBeaconData = new IBeaconManufacturerData(this);
}
private IBeaconDevice(Parcel in) {
private IBeaconDevice(final Parcel in) {
super(in);
validate();
mIBeaconData = new IBeaconManufacturerData(this);
@@ -136,22 +136,22 @@ public final class AdRecord implements Parcelable{
public static final Parcelable.Creator<AdRecord> CREATOR = new Parcelable.Creator<AdRecord>() {
public AdRecord createFromParcel(Parcel in) {
public AdRecord createFromParcel(final Parcel in) {
return new AdRecord(in);
}
public AdRecord[] newArray(int size) {
public AdRecord[] newArray(final int size) {
return new AdRecord[size];
}
};
public AdRecord(int length, int type, byte[] data) {
public AdRecord(final int length, final int type, final byte[] data) {
mLength = length;
mType = type;
mData = data;
}
public AdRecord(Parcel in) {
public AdRecord(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader());
mLength = b.getInt(PARCEL_RECORD_LENGTH);
mType = b.getInt(PARCEL_RECORD_TYPE);
@@ -185,7 +185,7 @@ public final class AdRecord implements Parcelable{
}
@Override
public void writeToParcel(Parcel parcel, int arg1) {
public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle(getClass().getClassLoader());
b.putInt(PARCEL_RECORD_LENGTH, mLength);
@@ -195,7 +195,7 @@ public final class AdRecord implements Parcelable{
parcel.writeBundle(b);
}
private static String getHumanReadableAdType(int type){
private static String getHumanReadableAdType(final int type){
switch(type){
case TYPE_CONNECTION_INTERVAL_RANGE:
return "Slave Connection Interval Range";
@@ -19,16 +19,16 @@ public class AdRecordStore implements Parcelable{
private final String mLocalNameShort;
public static final Parcelable.Creator<AdRecordStore> CREATOR = new Parcelable.Creator<AdRecordStore>() {
public AdRecordStore createFromParcel(Parcel in) {
public AdRecordStore createFromParcel(final Parcel in) {
return new AdRecordStore(in);
}
public AdRecordStore[] newArray(int size) {
public AdRecordStore[] newArray(final int size) {
return new AdRecordStore[size];
}
};
public AdRecordStore(Parcel in) {
public AdRecordStore(final Parcel in) {
final Bundle b = in.readBundle(getClass().getClassLoader());
mAdRecords = b.getSparseParcelableArray("records_array");
mLocalNameComplete = b.getString("local_name_complete");
@@ -83,7 +83,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record
* @return the record
*/
public AdRecord getRecord(int record){
public AdRecord getRecord(final int record){
return mAdRecords.get(record);
}
@@ -93,7 +93,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record
* @return the record data as string
*/
public String getRecordDataAsString(int record){
public String getRecordDataAsString(final int record){
return AdRecordUtils.getRecordDataAsString(
mAdRecords.get(record));
}
@@ -113,7 +113,7 @@ public class AdRecordStore implements Parcelable{
* @param record the record
* @return true, if is record present
*/
public boolean isRecordPresent(int record){
public boolean isRecordPresent(final int record){
return mAdRecords.indexOfKey(record) >= 0;
}
@@ -129,7 +129,7 @@ public class AdRecordStore implements Parcelable{
* @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
*/
@Override
public void writeToParcel(Parcel parcel, int arg1) {
public void writeToParcel(final Parcel parcel, final int arg1) {
final Bundle b = new Bundle();
b.putString("local_name_complete", mLocalNameComplete);
b.putString("local_name_short", mLocalNameShort);
@@ -145,7 +145,7 @@ public class AdRecordStore implements Parcelable{
* @param sparseArray the sparse array
* @return the collection
*/
public static <C> Collection<C> asList(SparseArray<C> sparseArray) {
public static <C> Collection<C> asList(final SparseArray<C> sparseArray) {
if (sparseArray == null) return null;
final Collection<C> arrayList = new ArrayList<C>(sparseArray.size());
@@ -53,7 +53,7 @@ public final class IBeaconManufacturerData {
private final int mMinor;
private final String mUUID;
public IBeaconManufacturerData(BluetoothLeDevice device){
public IBeaconManufacturerData(final BluetoothLeDevice device){
this(device.getAdRecordStore().getRecord(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getData());
}
@@ -63,7 +63,7 @@ public final class IBeaconManufacturerData {
* @param data the {@link uk.co.alt236.bluetoothlelib.device.adrecord.AdRecord#TYPE_MANUFACTURER_SPECIFIC_DATA} data array
* @throws IndexOutOfBoundsException if the data array is shorter than expected
*/
public IBeaconManufacturerData(byte[] data){
public IBeaconManufacturerData(final byte[] data){
mData = data;
mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray(
@@ -4,7 +4,7 @@ import android.bluetooth.BluetoothClass;
public class BluetoothClassResolver {
public static String resolveDeviceClass(int btClass){
public static String resolveDeviceClass(final int btClass){
switch (btClass){
case BluetoothClass.Device.AUDIO_VIDEO_CAMCORDER:
return "A/V, Camcorder";
@@ -318,7 +318,7 @@ public class CompanyIdentifierResolver {
private static final SparseArray<String> COMPANY_NAME_MAP = populateCompanyNameMap();
public static String getCompanyName(int companyId, String fallback){
public static String getCompanyName(final int companyId, final String fallback){
final String name = COMPANY_NAME_MAP.get(companyId);
return name == null ? fallback : name;
}
@@ -195,7 +195,7 @@ public class GattAttributeResolver {
private final static Map<String, String> sGattAttributesMap = populateGattAttributesMap();
public static String getAttributeName(String uuid, String fallback){
public static String getAttributeName(final String uuid, final String fallback){
final String name = sGattAttributesMap.get(uuid.toLowerCase(Locale.US));
return name == null ? fallback : name;
}
@@ -93,7 +93,7 @@ public class AdRecordUtils {
return Collections.unmodifiableMap(records);
}
public static SparseArray<AdRecord> parseScanRecordAsSparseArray(byte[] scanRecord) {
public static SparseArray<AdRecord> parseScanRecordAsSparseArray(final byte[] scanRecord) {
final SparseArray<AdRecord> records = new SparseArray<AdRecord>();
int index = 0;
@@ -40,7 +40,7 @@ public class ByteUtils {
* @param prefix the prefix
* @return true, if successful
*/
public static boolean doesArrayBeginWith(byte[] array, byte[] prefix){
public static boolean doesArrayBeginWith(final byte[] array, final byte[] prefix){
if(array.length < prefix.length){return false;}
for(int i = 0; i < prefix.length; i++){
@@ -58,7 +58,7 @@ public class ByteUtils {
* @param input the input
* @return the int from the array
*/
public static int getIntFrom2ByteArray(byte[] input){
public static int getIntFrom2ByteArray(final byte[] input){
final byte[] result = new byte[4];
result[0] = 0;
@@ -108,7 +108,7 @@ public class ByteUtils {
* @param array the array
* @return the byte[]
*/
public static byte[] invertArray(byte[] array){
public static byte[] invertArray(final byte[] array){
final int size = array.length;
byte temp;
@@ -10,7 +10,7 @@ public class IBeaconUtils {
private static final byte[] MANUFACTURER_DATA_IBEACON_PREFIX = new byte[]{0x4C, 0x00, 0x02, 0x15};
public static IBeaconDistanceDescriptor getDistanceDescriptor(double accuracy){
public static IBeaconDistanceDescriptor getDistanceDescriptor(final double accuracy){
if(accuracy < DISTANCE_THRESHOLD_WTF){
return IBeaconDistanceDescriptor.UNKNOWN;
}
@@ -35,12 +35,12 @@ public class IBeaconUtils {
* @param rssi the RSSI value of the iBeacon
* @return the calculated Accuracy
*/
public static double calculateAccuracy(int txPower, double rssi) {
public static double calculateAccuracy(final int txPower, final double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
double ratio = rssi*1.0/txPower;
final double ratio = rssi*1.0/txPower;
if (ratio < 1.0) {
return Math.pow(ratio,10);
}
@@ -56,7 +56,7 @@ public class IBeaconUtils {
* @param device a {@link uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice} device.
* @return true if the device is an iBeacon, false otherwise
*/
public static boolean isThisAnIBeacon(BluetoothLeDevice device){
public static boolean isThisAnIBeacon(final BluetoothLeDevice device){
return isThisAnIBeacon(
device.getAdRecordStore().getRecordDataAsString(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getBytes());
}
@@ -67,7 +67,7 @@ public class IBeaconUtils {
* @param manufacturerData a Bluetooth LE device's raw manufacturerData.
* @return
*/
public static boolean isThisAnIBeacon(byte[] manufacturerData){
public static boolean isThisAnIBeacon(final byte[] manufacturerData){
if(manufacturerData == null){return false;}
// An iBeacon record must be at least 25 chars long
@@ -8,13 +8,13 @@ public class LimitedLinkHashMap<K, V> extends LinkedHashMap<K, V>{
private final int mMaxSize;
public LimitedLinkHashMap(int maxSize){
public LimitedLinkHashMap(final int maxSize){
super(maxSize + 1, 1, false);
mMaxSize = maxSize;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return this.size() > mMaxSize;
}
}