<commit_before>package com.openxc;

import com.google.common.base.Objects;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Multimap;

import com.openxc.measurements.MeasurementInterface;
import com.openxc.measurements.UnrecognizedMeasurementTypeException;
import com.openxc.measurements.Measurement;

import com.openxc.remote.NoValueException;
import com.openxc.remote.RawMeasurement;

import com.openxc.remote.sinks.BaseVehicleDataSink;

import android.util.Log;

public class ListenerSink extends BaseVehicleDataSink {
    private final static String TAG = "ListenerSink";

    private Multimap<Class<? extends MeasurementInterface>,
            MeasurementInterface.Listener> mListeners;
    private BiMap<String, Class<? extends MeasurementInterface>>
            mMeasurementIdToClass;

    public ListenerSink(BiMap<String, Class<? extends MeasurementInterface>>
            measurementIdToClass) {
        mMeasurementIdToClass = measurementIdToClass;
        mListeners = HashMultimap.create();
        mListeners = Multimaps.synchronizedMultimap(mListeners);
    }

    public void register(Class<? extends MeasurementInterface> measurementType,
            Measurement.Listener listener) {
        mListeners.put(measurementType, listener);
    }
<commit_msg>Propagate last known measurement on the application side, not just remote.<commit_after>package com.openxc;

import com.google.common.base.Objects;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Multimap;

import com.openxc.measurements.MeasurementInterface;
import com.openxc.measurements.UnrecognizedMeasurementTypeException;
import com.openxc.measurements.Measurement;

import com.openxc.remote.NoValueException;
import com.openxc.remote.RawMeasurement;

import com.openxc.remote.sinks.BaseVehicleDataSink;

import android.util.Log;

public class ListenerSink extends BaseVehicleDataSink {
    private final static String TAG = "ListenerSink";

    private Multimap<Class<? extends MeasurementInterface>,
            MeasurementInterface.Listener> mListeners;
    private BiMap<String, Class<? extends MeasurementInterface>>
            mMeasurementIdToClass;

    public ListenerSink(BiMap<String, Class<? extends MeasurementInterface>>
                measurementIdToClass) {
        mMeasurementIdToClass = measurementIdToClass;
        mListeners = HashMultimap.create();
        mListeners = Multimaps.synchronizedMultimap(mListeners);
    }

    public void register(Class<? extends MeasurementInterface> measurementType,
            Measurement.Listener listener) {
        mListeners.put(measurementType, listener);

        String measurementId = mMeasurementIdToClass.inverse().get(measurementType);
        if(containsMeasurement(measurementId)) {
            // send the last known value to the new listener
            RawMeasurement rawMeasurement = get(measurementId);
            receive(measurementId, rawMeasurement);
        }
    }

{'fraction_non_alphanumeric': 0.08040519151630263, 'fraction_numerical': 0.0, 'mean_word_length': 4.31986531986532, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2134547', 'n_tokens_mistral': 867, 'n_tokens_neox': 859, 'n_words': 170}