I have the following arrays which save the MAC-adresses of a lot of bluetooth beacons and their positions in a building:
private static final String[][] MAC_ADDRESSES_A_BLUETOOTH = {{"B09122F5D126", "210.105"}, {"B09122F5F26B", "136.121"}, {"B09122F5F619", "181.172"}};
...
private static final String[][] MAC_ADDRESSES_Q_BLUETOOTH = {{"B09122F5D124", "210.105"}, {"B09122F5F26Z", "136.121"}, {"B09122F5F61Q", "181.172"}};
Then I'm looking for the matching triple based on a current triple:
private String[][] compareArrays(String[] beacon) {
if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_A_BLUETOOTH))) {
return MAC_ADDRESSES_A_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_B_BLUETOOTH))) {
return MAC_ADDRESSES_B_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_C_BLUETOOTH))) {
return MAC_ADDRESSES_C_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_D_BLUETOOTH))) {
return MAC_ADDRESSES_D_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_F_BLUETOOTH))) {
return MAC_ADDRESSES_F_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_G_BLUETOOTH))) {
return MAC_ADDRESSES_G_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_H_BLUETOOTH))) {
return MAC_ADDRESSES_H_BLUETOOTH;
} else if (Arrays.equals(beacon, getFirstArray(MAC_ADDRESSES_I_BLUETOOTH))) {
return MAC_ADDRESSES_I_BLUETOOTH;
} ...
} else {
return null;
}
}
This code looks horrible and it bugs me. Is there an easier way to do this without having to write 16 if
statements? getFirstArray
returns all first values from a two-dimensional array.