Skip to content

Commit 4fcbc7c

Browse files
committed
Java 7-ness
1 parent 9c04515 commit 4fcbc7c

11 files changed

Lines changed: 44 additions & 40 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/build.gradle

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
apply plugin: 'com.android.library'
22

3-
def versionMajor = 0
4-
def versionMinor = 0
5-
def versionPatch = 2
6-
def androidVersionCode = 2
3+
final def versionMajor = 0
4+
final def versionMinor = 0
5+
final def versionPatch = 2
6+
final def androidVersionCode = 2
77

8-
def targetSdk = rootProject.targetSdkVersion;
9-
def minSdkRed = rootProject.minSdkVersion;
8+
final def targetSdk = rootProject.targetSdkVersion;
9+
final def minSdkRed = rootProject.minSdkVersion;
1010

1111
android {
1212
compileSdkVersion rootProject.compileSdkVersion
1313
buildToolsVersion rootProject.buildToolsVersion
1414

15+
compileOptions {
16+
sourceCompatibility JavaVersion.VERSION_1_7
17+
targetCompatibility JavaVersion.VERSION_1_7
18+
}
19+
1520
defaultConfig {
1621
minSdkVersion minSdkRed
1722
targetSdkVersion targetSdk

library/src/main/java/uk/co/alt236/bluetoothlelib/device/BluetoothLeDevice.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import java.io.Serializable;
99
import java.util.Arrays;
10-
import java.util.Iterator;
1110
import java.util.Map;
1211

1312
import uk.co.alt236.bluetoothlelib.device.adrecord.AdRecordStore;
@@ -71,7 +70,7 @@ public BluetoothLeDevice(final BluetoothDevice device, final int rssi, final byt
7170
mFirstTimestamp = timestamp;
7271
mRecordStore = new AdRecordStore(AdRecordUtils.parseScanRecordAsSparseArray(scanRecord));
7372
mScanRecord = scanRecord;
74-
mRssiLog = new LimitedLinkHashMap<Long, Integer>(MAX_RSSI_LOG_SIZE);
73+
mRssiLog = new LimitedLinkHashMap<>(MAX_RSSI_LOG_SIZE);
7574
updateRssiReading(timestamp, rssi);
7675
}
7776

@@ -279,17 +278,12 @@ public double getRunningAverageRssi() {
279278
int count = 0;
280279

281280
synchronized (mRssiLog) {
282-
final Iterator<Long> it1 = mRssiLog.keySet().iterator();
283281

284-
while (it1.hasNext()) {
282+
for (final Long aLong : mRssiLog.keySet()) {
285283
count++;
286-
sum += mRssiLog.get(it1.next());
284+
sum += mRssiLog.get(aLong);
287285
}
288286
}
289-
// for(final Map.Entry<Long,Integer> e : mRssiLog.entrySet()){
290-
// count ++;
291-
// sum += e.getValue();
292-
// }
293287

294288
if (count > 0) {
295289
return sum / count;

library/src/main/java/uk/co/alt236/bluetoothlelib/device/adrecord/AdRecordStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void writeToParcel(final Parcel parcel, final int arg1) {
148148
public static <C> Collection<C> asList(final SparseArray<C> sparseArray) {
149149
if (sparseArray == null) return null;
150150

151-
final Collection<C> arrayList = new ArrayList<C>(sparseArray.size());
151+
final Collection<C> arrayList = new ArrayList<>(sparseArray.size());
152152
for (int i = 0; i < sparseArray.size(); i++) {
153153
arrayList.add(sparseArray.valueAt(i));
154154
}

library/src/main/java/uk/co/alt236/bluetoothlelib/resolvers/CompanyIdentifierResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static String getCompanyName(final int companyId, final String fallback)
324324
}
325325

326326
private static SparseArray<String> populateCompanyNameMap() {
327-
final SparseArray<String> map = new SparseArray<String>();
327+
final SparseArray<String> map = new SparseArray<>();
328328

329329
map.put(ERICSSON_TECHNOLOGY_LICENSING, "Ericsson Technology Licensing");
330330
map.put(NOKIA_MOBILE_PHONES, "Nokia Mobile Phones");

library/src/main/java/uk/co/alt236/bluetoothlelib/resolvers/GattAttributeResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static String getAttributeName(final String uuid, final String fallback)
198198
}
199199

200200
private static Map<String, String> populateGattAttributesMap() {
201-
final Map<String, String> map = new HashMap<String, String>();
201+
final Map<String, String> map = new HashMap<>();
202202

203203
map.put(BASE_GUID, "Service Discovery Protocol (SDP)");
204204
map.put(SERVICE_DISCOVERY_PROTOCOL_SDP, "User Datagram Protocol (UDP)");

library/src/main/java/uk/co/alt236/bluetoothlelib/util/AdRecordUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static int getServiceDataUuid(final AdRecord serviceData) {
5050
* Read out all the AD structures from the raw scan record
5151
*/
5252
public static List<AdRecord> parseScanRecordAsList(final byte[] scanRecord) {
53-
final List<AdRecord> records = new ArrayList<AdRecord>();
53+
final List<AdRecord> records = new ArrayList<>();
5454

5555
int index = 0;
5656
while (index < scanRecord.length) {
@@ -76,7 +76,7 @@ public static List<AdRecord> parseScanRecordAsList(final byte[] scanRecord) {
7676

7777
@SuppressLint("UseSparseArrays")
7878
public static Map<Integer, AdRecord> parseScanRecordAsMap(final byte[] scanRecord) {
79-
final Map<Integer, AdRecord> records = new HashMap<Integer, AdRecord>();
79+
final Map<Integer, AdRecord> records = new HashMap<>();
8080

8181
int index = 0;
8282
while (index < scanRecord.length) {
@@ -101,7 +101,7 @@ public static Map<Integer, AdRecord> parseScanRecordAsMap(final byte[] scanRecor
101101
}
102102

103103
public static SparseArray<AdRecord> parseScanRecordAsSparseArray(final byte[] scanRecord) {
104-
final SparseArray<AdRecord> records = new SparseArray<AdRecord>();
104+
final SparseArray<AdRecord> records = new SparseArray<>();
105105

106106
int index = 0;
107107
while (index < scanRecord.length) {

library/src/main/java/uk/co/alt236/bluetoothlelib/util/ByteUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static int getIntFrom2ByteArray(final byte[] input) {
8282
* @return the int from byte
8383
*/
8484
public static int getIntFromByte(final byte bite) {
85-
return Integer.valueOf(bite & 0xFF);
85+
return bite & 0xFF;
8686
}
8787

8888
/**

sample_app/build.gradle

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
apply plugin: 'com.android.application'
22

3-
def versionMajor = 0
4-
def versionMinor = 0
5-
def versionPatch = 3
6-
def androidVersionCode = 3
3+
final def versionMajor = 0
4+
final def versionMinor = 0
5+
final def versionPatch = 3
6+
final def androidVersionCode = 3
77

8-
def targetSdk = rootProject.targetSdkVersion;
9-
def minSdkRed = rootProject.minSdkVersion;
8+
final def targetSdk = rootProject.targetSdkVersion;
9+
final def minSdkRed = rootProject.minSdkVersion;
1010

1111
android {
1212
compileSdkVersion rootProject.compileSdkVersion
1313
buildToolsVersion rootProject.buildToolsVersion
1414

15+
compileOptions {
16+
sourceCompatibility JavaVersion.VERSION_1_7
17+
targetCompatibility JavaVersion.VERSION_1_7
18+
}
19+
1520
defaultConfig {
1621
minSdkVersion minSdkRed
1722
targetSdkVersion targetSdk

sample_app/src/main/java/uk/co/alt236/btlescan/activities/DeviceControlActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class DeviceControlActivity extends Activity {
7373
TextView mDataAsArray;
7474
private BluetoothGattCharacteristic mNotifyCharacteristic;
7575
private BluetoothLeService mBluetoothLeService;
76-
private List<List<BluetoothGattCharacteristic>> mGattCharacteristics = new ArrayList<List<BluetoothGattCharacteristic>>();
76+
private List<List<BluetoothGattCharacteristic>> mGattCharacteristics = new ArrayList<>();
7777
// If a given GATT characteristic is selected, check for supported features. This sample
7878
// demonstrates 'Read' and 'Notify' features. See
7979
// http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for the complete
@@ -177,26 +177,26 @@ private void displayGattServices(final List<BluetoothGattService> gattServices)
177177
String uuid = null;
178178
final String unknownServiceString = getResources().getString(R.string.unknown_service);
179179
final String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
180-
final List<Map<String, String>> gattServiceData = new ArrayList<Map<String, String>>();
181-
final List<List<Map<String, String>>> gattCharacteristicData = new ArrayList<List<Map<String, String>>>();
182-
mGattCharacteristics = new ArrayList<List<BluetoothGattCharacteristic>>();
180+
final List<Map<String, String>> gattServiceData = new ArrayList<>();
181+
final List<List<Map<String, String>>> gattCharacteristicData = new ArrayList<>();
182+
mGattCharacteristics = new ArrayList<>();
183183

184184
// Loops through available GATT Services.
185185
for (final BluetoothGattService gattService : gattServices) {
186-
final Map<String, String> currentServiceData = new HashMap<String, String>();
186+
final Map<String, String> currentServiceData = new HashMap<>();
187187
uuid = gattService.getUuid().toString();
188188
currentServiceData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownServiceString));
189189
currentServiceData.put(LIST_UUID, uuid);
190190
gattServiceData.add(currentServiceData);
191191

192-
final List<Map<String, String>> gattCharacteristicGroupData = new ArrayList<Map<String, String>>();
192+
final List<Map<String, String>> gattCharacteristicGroupData = new ArrayList<>();
193193
final List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
194-
final List<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();
194+
final List<BluetoothGattCharacteristic> charas = new ArrayList<>();
195195

196196
// Loops through available Characteristics.
197197
for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
198198
charas.add(gattCharacteristic);
199-
final Map<String, String> currentCharaData = new HashMap<String, String>();
199+
final Map<String, String> currentCharaData = new HashMap<>();
200200
uuid = gattCharacteristic.getUuid().toString();
201201
currentCharaData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownCharaString));
202202
currentCharaData.put(LIST_UUID, uuid);

0 commit comments

Comments
 (0)