@Test(expected = IllegalStateException.class) public void testIntException() { CommandResult commandResult = new CommandResult(Neatle.createUUID(1), new byte[]{22, 21, 20, 19, 18}, BluetoothGatt.GATT_SUCCESS, 1); commandResult.getValueAsInt(); }
public int getValueAsInt() { if (data.length > 4) { throw new IllegalStateException("Data has more than 4 bytes and cannot be converted to an integer"); } int ret = 0; switch (data.length) { case 4: ret |= (data[3] & 0xFF) << ((data.length - 4) * 8); case 3: ret |= (data[2] & 0xFF) << ((data.length - 3) * 8); case 2: ret |= (data[1] & 0xFF) << ((data.length - 2) * 8); case 1: ret |= (data[0] & 0xFF) << ((data.length - 1) * 8); } return ret; }
CommandResult { public int getValueAsInt() { if (data.length > 4) { throw new IllegalStateException("Data has more than 4 bytes and cannot be converted to an integer"); } int ret = 0; switch (data.length) { case 4: ret |= (data[3] & 0xFF) << ((data.length - 4) * 8); case 3: ret |= (data[2] & 0xFF) << ((data.length - 3) * 8); case 2: ret |= (data[1] & 0xFF) << ((data.length - 2) * 8); case 1: ret |= (data[0] & 0xFF) << ((data.length - 1) * 8); } return ret; } }
CommandResult { public int getValueAsInt() { if (data.length > 4) { throw new IllegalStateException("Data has more than 4 bytes and cannot be converted to an integer"); } int ret = 0; switch (data.length) { case 4: ret |= (data[3] & 0xFF) << ((data.length - 4) * 8); case 3: ret |= (data[2] & 0xFF) << ((data.length - 3) * 8); case 2: ret |= (data[1] & 0xFF) << ((data.length - 2) * 8); case 1: ret |= (data[0] & 0xFF) << ((data.length - 1) * 8); } return ret; } CommandResult(UUID uuid, byte[] data, int status, long timestamp); }
CommandResult { public int getValueAsInt() { if (data.length > 4) { throw new IllegalStateException("Data has more than 4 bytes and cannot be converted to an integer"); } int ret = 0; switch (data.length) { case 4: ret |= (data[3] & 0xFF) << ((data.length - 4) * 8); case 3: ret |= (data[2] & 0xFF) << ((data.length - 3) * 8); case 2: ret |= (data[1] & 0xFF) << ((data.length - 2) * 8); case 1: ret |= (data[0] & 0xFF) << ((data.length - 1) * 8); } return ret; } CommandResult(UUID uuid, byte[] data, int status, long timestamp); byte[] getValue(); String getValueAsString(); int getValueAsInt(); Integer getFormattedIntValue(int formatType, int offset); UUID getUUID(); int getStatus(); long getTimestamp(); boolean wasSuccessful(); @Override String toString(); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createCharacteristicRead(BluetoothGattCharacteristic characteristic, int status); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createErrorResult(UUID characteristicUUID, int error); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createEmptySuccess(UUID characteristicUUID); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createCharacteristicChanged(BluetoothGattCharacteristic characteristic); }
CommandResult { public int getValueAsInt() { if (data.length > 4) { throw new IllegalStateException("Data has more than 4 bytes and cannot be converted to an integer"); } int ret = 0; switch (data.length) { case 4: ret |= (data[3] & 0xFF) << ((data.length - 4) * 8); case 3: ret |= (data[2] & 0xFF) << ((data.length - 3) * 8); case 2: ret |= (data[1] & 0xFF) << ((data.length - 2) * 8); case 1: ret |= (data[0] & 0xFF) << ((data.length - 1) * 8); } return ret; } CommandResult(UUID uuid, byte[] data, int status, long timestamp); byte[] getValue(); String getValueAsString(); int getValueAsInt(); Integer getFormattedIntValue(int formatType, int offset); UUID getUUID(); int getStatus(); long getTimestamp(); boolean wasSuccessful(); @Override String toString(); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createCharacteristicRead(BluetoothGattCharacteristic characteristic, int status); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createErrorResult(UUID characteristicUUID, int error); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createEmptySuccess(UUID characteristicUUID); @RestrictTo(RestrictTo.Scope.LIBRARY) static CommandResult createCharacteristicChanged(BluetoothGattCharacteristic characteristic); static final int FORMAT_UINT8; static final int FORMAT_UINT16; static final int FORMAT_UINT32; static final int FORMAT_SINT8; static final int FORMAT_SINT16; static final int FORMAT_SINT32; }