<commit_before>package com.google.heartrate.wearos.app.sensors;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Listener for heart rate sensor.
 */
public class HeartRateSensorListener implements SensorEventListener {
    private static final String TAG = HeartRateSensorListener.class.getSimpleName();

    /** Sensor manager. */
    private final SensorManager mSensorManager;

    /** Heart rate sensor to listen to. */
    private final Sensor mHeartRateSensor;

    /** Subscriber for heart rate value updates. */
    private List<HeartRateValueSubscriber> subscribers = new ArrayList<>();

    public HeartRateSensorListener(Context context) {
        mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
    }

    /**
     * Register subscriber.
     * @param subscriber subscriber to register.
     */
    public void registerSubscriber(HeartRateValueSubscriber subscriber) {
        Log.d(TAG, "Register subscriber");
        if (subscribers.size() == 0) {
            startMeasure();
        }
        subscribers.add(subscriber);
    }

    /**
     * Unregister subscriber.
     * @param subscriber subscriber to unregister.
     */
    public void unregisterSubscriber(HeartRateValueSubscriber subscriber) {
        Log.d(TAG, "Unregister subscriber");
        subscribers.remove(subscriber);
        if (subscribers.size() == 0) {
            stopMeasure();
        }
    }

    /**
     * Start measurement heart rate data. Register to heart rate sensor changes.
     */
    private void startMeasure() {
        Log.d(TAG, "Start measurement");
        boolean sensorRegistered = mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_FASTEST);
        if (!sensorRegistered) {
            Log.e(TAG, "Heart rate sensor not registered");
        } else {
            Log.d(TAG, "Heart rate sensor registered");
        }

    }

    /**
     * Stop measurement heart rate data. Unregister from heart rate sensor changes.
     */
    private void stopMeasure() {
        Log.d(TAG, "Stop measurement");
        mSensorManager.unregisterListener(this);
    }

    /**
     * Callback invokes when heart rate value has been changed.
     * @param event event from heart rate sensor
     */
    @Override
    public void onSensorChanged(SensorEvent event) {
        float heartRateFloat = event.values[0];
        int heartRate = Math.round(heartRateFloat);
        Log.v(TAG, String.format("onSensorChanged() - value=%d", heartRate));

        for (HeartRateValueSubscriber listener : subscribers) {
            listener.onHeartRateValueChanged(heartRate);
        }
    }<commit_msg>Fix fields names<commit_after>package com.google.heartrate.wearos.app.sensors;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Listener for heart rate sensor.
 */
public class HeartRateSensorListener implements SensorEventListener {
    private static final String TAG = HeartRateSensorListener.class.getSimpleName();

    /** Sensor manager. */
    private final SensorManager sensorManager;

    /** Heart rate sensor to listen to. */
    private final Sensor heartRateSensor;

    /** Subscriber for heart rate value updates. */
    private List<HeartRateValueSubscriber> subscribers = new ArrayList<>();

    public HeartRateSensorListener(Context context) {
        sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        heartRateSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
    }

    /**
     * Register subscriber.
     * @param subscriber subscriber to register.
     */
    public void registerSubscriber(HeartRateValueSubscriber subscriber) {
        Log.d(TAG, "Register subscriber");
        if (subscribers.size() == 0) {
            startMeasure();
        }
        subscribers.add(subscriber);
    }

    /**
     * Unregister subscriber.
     * @param subscriber subscriber to unregister.
     */
    public void unregisterSubscriber(HeartRateValueSubscriber subscriber) {
        Log.d(TAG, "Unregister subscriber");
        subscribers.remove(subscriber);
        if (subscribers.size() == 0) {
            stopMeasure();
        }
    }

    /**
     * Start measurement heart rate data. Register to heart rate sensor changes.
     */
    private void startMeasure() {
        Log.d(TAG, "Start measurement");
        boolean sensorRegistered = sensorManager.registerListener(this, heartRateSensor, SensorManager.SENSOR_DELAY_FASTEST);
        if (!sensorRegistered) {
            Log.e(TAG, "Heart rate sensor not registered");
        } else {
            Log.d(TAG, "Heart rate sensor registered");
        }

    }

    /**
     * Stop measurement heart rate data. Unregister from heart rate sensor changes.
     */
    private void stopMeasure() {
        Log.d(TAG, "Stop measurement");
        sensorManager.unregisterListener(this);
    }

    /**
     * Callback invokes when heart rate value has been changed.
     * @param event event from heart rate sensor
     */
    @Override
    public void onSensorChanged(SensorEvent event) {
        float heartRateFloat = event.values[0];
        int heartRate = Math.round(heartRateFloat);
        Log.v(TAG, String.format("onSensorChanged() - value=%d", heartRate));

        for (HeartRateValueSubscriber listener : subscribers) {
            listener.onHeartRateValueChanged(heartRate);
        }
    }
{'fraction_non_alphanumeric': 0.0969430839385239, 'fraction_numerical': 0.0010133423408208073, 'mean_word_length': 2.9348837209302325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5836540', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1566, 'n_words': 396}