<commit_before>package com.polidea.rxandroidble;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import java.util.List;
import java.util.UUID;
import rx.Observable;

public class RxBleDeviceServices {

    private final List<BluetoothGattService> bluetoothGattServices;

    public RxBleDeviceServices(List<BluetoothGattService> bluetoothGattServices) {
        this.bluetoothGattServices = bluetoothGattServices;
    }

    public List<BluetoothGattService> getBluetoothGattServices() {
        return bluetoothGattServices;
    }

    public Observable<BluetoothGattService> getService(UUID serviceUuid) {
        // TODO: [PU] 29.01.2016 Will raise NoSuchElementException if services are empty. It should be mapped to error if not found
        return Observable.from(bluetoothGattServices)
                .filter(bluetoothGattService -> bluetoothGattService.getUuid().equals(serviceUuid))
                .first();
    }

    public Observable<BluetoothGattCharacteristic> getCharacteristic(UUID characteristicUuid) {
        // TODO: [PU] 29.01.2016 Theoretically it may happen that characterisitic UUID in duplicated in another service.
        return Observable.from(bluetoothGattServices)
                .map(bluetoothGattService -> bluetoothGattService.getCharacteristic(characteristicUuid))
                .filter(bluetoothGattCharacteristic -> bluetoothGattCharacteristic != null)
                .take(1);
    }

    public Observable<BluetoothGattCharacteristic> getCharacteristic(UUID serviceUuid, UUID characteristicUuid) {
        return getService(serviceUuid).map(bluetoothGattService -> bluetoothGattService.getCharacteristic(characteristicUuid));
    }

    public Observable<BluetoothGattDescriptor> getDescriptor(UUID characteristicUuid, UUID descriptorUuid) {
        return getCharacteristic(characteristicUuid)
                .map(bluetoothGattCharacteristic -> bluetoothGattCharacteristic.getDescriptor(descriptorUuid))
                .filter(bluetoothGattDescriptor -> bluetoothGattDescriptor != null);
    }<commit_msg>Looking for a characteristic with UUID that is not present now results in an NoSuchElementException.<commit_after>package com.polidea.rxandroidble;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import java.util.List;
import java.util.UUID;
import rx.Observable;

public class RxBleDeviceServices {

    private final List<BluetoothGattService> bluetoothGattServices;

    public RxBleDeviceServices(List<BluetoothGattService> bluetoothGattServices) {
        this.bluetoothGattServices = bluetoothGattServices;
    }

    public List<BluetoothGattService> getBluetoothGattServices() {
        return bluetoothGattServices;
    }

    public Observable<BluetoothGattService> getService(UUID serviceUuid) {
        // TODO: [PU] 29.01.2016 Will raise NoSuchElementException if services are empty. It should be mapped to error if not found
        return Observable.from(bluetoothGattServices)
                .filter(bluetoothGattService -> bluetoothGattService.getUuid().equals(serviceUuid))
                .first();
    }

    public Observable<BluetoothGattCharacteristic> getCharacteristic(UUID characteristicUuid) {
        // TODO: [PU] 29.01.2016 Theoretically it may happen that characterisitic UUID in duplicated in another service.
        return Observable.from(bluetoothGattServices)
                .map(bluetoothGattService -> bluetoothGattService.getCharacteristic(characteristicUuid))
                .filter(bluetoothGattCharacteristic -> bluetoothGattCharacteristic != null)
                .first();
    }

    public Observable<BluetoothGattCharacteristic> getCharacteristic(UUID serviceUuid, UUID characteristicUuid) {
        return getService(serviceUuid).map(bluetoothGattService -> bluetoothGattService.getCharacteristic(characteristicUuid));
    }

    public Observable<BluetoothGattDescriptor> getDescriptor(UUID characteristicUuid, UUID descriptorUuid) {
        return getCharacteristic(characteristicUuid)
                .map(bluetoothGattCharacteristic -> bluetoothGattCharacteristic.getDescriptor(descriptorUuid))
                .filter(bluetoothGattDescriptor -> bluetoothGattDescriptor != null);
    }
{'fraction_non_alphanumeric': 0.07024323709934076, 'fraction_numerical': 0.0075017049329393045, 'mean_word_length': 4.225653206650831, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '421365', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1141, 'n_words': 230}