gt:         MealData result = new MealData();
context: package info.nightscout.androidaps.plugins.treatments;
  
  import android.content.Intent;
  import android.os.Bundle;
  
  import androidx.annotation.Nullable;
  
  import com.google.firebase.analytics.FirebaseAnalytics;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  import info.nightscout.androidaps.Constants;
  import info.nightscout.androidaps.MainApp;
  import info.nightscout.androidaps.R;
  import info.nightscout.androidaps.data.DetailedBolusInfo;
  import info.nightscout.androidaps.data.Intervals;
  import info.nightscout.androidaps.data.Iob;
  import info.nightscout.androidaps.data.IobTotal;
  import info.nightscout.androidaps.data.MealData;
  import info.nightscout.androidaps.data.NonOverlappingIntervals;
  import info.nightscout.androidaps.data.OverlappingIntervals;
  import info.nightscout.androidaps.data.Profile;
  import info.nightscout.androidaps.data.ProfileIntervals;
  import info.nightscout.androidaps.db.ExtendedBolus;
  import info.nightscout.androidaps.db.ProfileSwitch;
  import info.nightscout.androidaps.db.TempTarget;
  import info.nightscout.androidaps.db.TemporaryBasal;
  import info.nightscout.androidaps.events.EventReloadProfileSwitchData;
  import info.nightscout.androidaps.events.EventReloadTempBasalData;
  import info.nightscout.androidaps.events.EventReloadTreatmentData;
  import info.nightscout.androidaps.events.EventTempTargetChange;
  import info.nightscout.androidaps.interfaces.InsulinInterface;
  import info.nightscout.androidaps.interfaces.PluginBase;
  import info.nightscout.androidaps.interfaces.PluginDescription;
  import info.nightscout.androidaps.interfaces.PluginType;
  import info.nightscout.androidaps.interfaces.PumpInterface;
  import info.nightscout.androidaps.interfaces.TreatmentsInterface;
  import info.nightscout.androidaps.logging.L;
  import info.nightscout.androidaps.plugins.bus.RxBus;
  import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
  import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
  import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
  import info.nightscout.androidaps.activities.ErrorHelperActivity;
  import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
  import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
  import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
  import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
  import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
  import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
  import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
  import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
  import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
  import info.nightscout.androidaps.utils.DateUtil;
  import info.nightscout.androidaps.utils.FabricPrivacy;
  import info.nightscout.androidaps.utils.SP;
  import info.nightscout.androidaps.utils.T;
  import io.reactivex.disposables.CompositeDisposable;
  import io.reactivex.schedulers.Schedulers;
  
  /**
   * Created by mike on 05.08.2016.
   */
  public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
      private Logger log = LoggerFactory.getLogger(L.DATATREATMENTS);
  
      private CompositeDisposable disposable = new CompositeDisposable();
  
      private static TreatmentsPlugin treatmentsPlugin;
  
      public static TreatmentsPlugin getPlugin() {
          if (treatmentsPlugin == null)
              treatmentsPlugin = new TreatmentsPlugin();
          return treatmentsPlugin;
      }
  
      private TreatmentService service;
  
      private IobTotal lastTreatmentCalculation;
      private IobTotal lastTempBasalsCalculation;
  
      private final ArrayList<Treatment> treatments = new ArrayList<>();
      private final Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<>();
      private final Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<>();
      private final Intervals<TempTarget> tempTargets = new OverlappingIntervals<>();
      private final ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
  
      public TreatmentsPlugin() {
          super(new PluginDescription()
                  .mainType(PluginType.TREATMENT)
                  .fragmentClass(TreatmentsFragment.class.getName())
                  .pluginName(R.string.treatments)
                  .shortName(R.string.treatments_shortname)
                  .alwaysEnabled(true)
                  .description(R.string.description_treatments)
          );
          this.service = new TreatmentService();
      }
  
      @Override
      protected void onStart() {
          initializeData(range());
          super.onStart();
          disposable.add(RxBus.INSTANCE
                  .toObservable(EventReloadTreatmentData.class)
                  .observeOn(Schedulers.io())
                  .subscribe(event -> {
                              if (L.isEnabled(L.DATATREATMENTS))
                                  log.debug("EventReloadTreatmentData");
                              initializeTreatmentData(range());
                              initializeExtendedBolusData(range());
                              updateTotalIOBTreatments();
                              RxBus.INSTANCE.send(event.getNext());
                          },
                          FabricPrivacy::logException
                  ));
          disposable.add(RxBus.INSTANCE
                  .toObservable(EventReloadProfileSwitchData.class)
                  .observeOn(Schedulers.io())
                  .subscribe(event -> initializeProfileSwitchData(range()),
                          FabricPrivacy::logException
                  ));
          disposable.add(RxBus.INSTANCE
                  .toObservable(EventTempTargetChange.class)
                  .observeOn(Schedulers.io())
                  .subscribe(event -> initializeTempTargetData(range()),
                          FabricPrivacy::logException
                  ));
          disposable.add(RxBus.INSTANCE
                  .toObservable(EventReloadTempBasalData.class)
                  .observeOn(Schedulers.io())
                  .subscribe(event -> {
                              if (L.isEnabled(L.DATATREATMENTS))
                                  log.debug("EventReloadTempBasalData");
                              initializeTempBasalData(range());
                              updateTotalIOBTempBasals();
                          },
                          FabricPrivacy::logException
                  ));
      }
  
      @Override
      protected void onStop() {
          disposable.clear();
          super.onStop();
      }
  
      public TreatmentService getService() {
          return this.service;
      }
  
      private long range() {
          double dia = Constants.defaultDIA;
          if (ConfigBuilderPlugin.getPlugin() != null && ProfileFunctions.getInstance().getProfile() != null)
              dia = ProfileFunctions.getInstance().getProfile().getDia();
          return  (long) (60 * 60 * 1000L * (24 + dia));
      }
  
      public void initializeData(long range) {
          initializeTempBasalData(range);
          initializeTreatmentData(range);
          initializeExtendedBolusData(range);
          initializeTempTargetData(range);
          initializeProfileSwitchData(range);
      }
  
      private void initializeTreatmentData(long range) {
          if (L.isEnabled(L.DATATREATMENTS))
              log.debug("initializeTreatmentData");
          synchronized (treatments) {
              treatments.clear();
              treatments.addAll(getService().getTreatmentDataFromTime(DateUtil.now() - range, false));
          }
      }
  
      private void initializeTempBasalData(long range) {
          if (L.isEnabled(L.DATATREATMENTS))
              log.debug("initializeTempBasalData");
          synchronized (tempBasals) {
              tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(DateUtil.now() - range, false));
          }
  
      }
  
      private void initializeExtendedBolusData(long range) {
          if (L.isEnabled(L.DATATREATMENTS))
              log.debug("initializeExtendedBolusData");
          synchronized (extendedBoluses) {
              extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(DateUtil.now() - range, false));
          }
  
      }
  
      private void initializeTempTargetData(long range) {
          if (L.isEnabled(L.DATATREATMENTS))
              log.debug("initializeTempTargetData");
          synchronized (tempTargets) {
              tempTargets.reset().add(MainApp.getDbHelper().getTemptargetsDataFromTime(DateUtil.now() - range, false));
          }
      }
  
      private void initializeProfileSwitchData(long range) {
          if (L.isEnabled(L.DATATREATMENTS))
              log.debug("initializeProfileSwitchData");
          synchronized (profiles) {
              profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - range, false));
          }
      }
  
      @Override
      public IobTotal getLastCalculationTreatments() {
          return lastTreatmentCalculation;
      }
  
      @Override
      public IobTotal getCalculationToTimeTreatments(long time) {
          IobTotal total = new IobTotal(time);
  
          Profile profile = ProfileFunctions.getInstance().getProfile();
          if (profile == null)
              return total;
  
          InsulinInterface insulinInterface = ConfigBuilderPlugin.getPlugin().getActiveInsulin();
          if (insulinInterface == null)
              return total;
  
          PumpInterface pumpInterface = ConfigBuilderPlugin.getPlugin().getActivePump();
          if (pumpInterface == null)
              return total;
  
          double dia = profile.getDia();
  
          synchronized (treatments) {
              for (Integer pos = 0; pos < treatments.size(); pos++) {
                  Treatment t = treatments.get(pos);
                  if (!t.isValid) continue;
                  if (t.date > time) continue;
                  Iob tIOB = t.iobCalc(time, dia);
                  total.iob += tIOB.iobContrib;
                  total.activity += tIOB.activityContrib;
                  if (t.insulin > 0 && t.date > total.lastBolusTime)
                      total.lastBolusTime = t.date;
                  if (!t.isSMB) {
                      // instead of dividing the DIA that only worked on the bilinear curves,
                      // multiply the time the treatment is seen active.
                      long timeSinceTreatment = time - t.date;
                      long snoozeTime = t.date + (long) (timeSinceTreatment * SP.getDouble(R.string.key_openapsama_bolussnooze_dia_divisor, 2.0));
                      Iob bIOB = t.iobCalc(snoozeTime, dia);
                      total.bolussnooze += bIOB.iobContrib;
                  }
              }
          }
  
          if (!pumpInterface.isFakingTempsByExtendedBoluses())
              synchronized (extendedBoluses) {
                  for (int pos = 0; pos < extendedBoluses.size(); pos++) {
                      ExtendedBolus e = extendedBoluses.get(pos);
                      if (e.date > time) continue;
                      IobTotal calc = e.iobCalc(time);
                      total.plus(calc);
                  }
              }
          return total;
      }
  
      @Override
      public void updateTotalIOBTreatments() {
          lastTreatmentCalculation = getCalculationToTimeTreatments(System.currentTimeMillis());
      }
  
      @Override
      public MealData getMealData() {
  