From 56423028f6856206747e6365fe3b3eaaa6f06e30 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 20 Aug 2017 10:52:06 +0200 Subject: [PATCH] Fix comparing non-primitives. --- .../plugins/ConstraintsSafety/SafetyPlugin.java | 10 ++++++---- .../NSClientInternal/data/NSSettingsStatus.java | 3 ++- .../plugins/Overview/Dialogs/NewTreatmentDialog.java | 3 ++- .../androidaps/plugins/Overview/OverviewFragment.java | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index c685cd472d..6880d1a21e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.ConstraintsSafety; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Objects; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; @@ -161,17 +163,17 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { Double origRate = absoluteRate; if (absoluteRate > maxBasal) { absoluteRate = maxBasal; - if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit) + if (Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) log.debug("Limiting rate " + origRate + " by maxBasal preference to " + absoluteRate + "U/h"); } if (absoluteRate > maxBasalMult * profile.getBasal()) { absoluteRate = Math.floor(maxBasalMult * profile.getBasal() * 100) / 100; - if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit) + if (Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) log.debug("Limiting rate " + origRate + " by maxBasalMult to " + absoluteRate + "U/h"); } if (absoluteRate > profile.getMaxDailyBasal() * maxBasalFromDaily) { absoluteRate = profile.getMaxDailyBasal() * maxBasalFromDaily; - if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit) + if (Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) log.debug("Limiting rate " + origRate + " by 3 * maxDailyBasal to " + absoluteRate + "U/h"); } @@ -180,7 +182,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { percentRateAfterConst = Round.ceilTo((double) percentRateAfterConst, 10d).intValue(); else percentRateAfterConst = Round.floorTo((double) percentRateAfterConst, 10d).intValue(); - if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit) + if (Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) log.debug("Recalculated percent rate " + percentRate + "% to " + percentRateAfterConst + "%"); return percentRateAfterConst; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java index 4829af714e..c2c3aa036f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java @@ -6,6 +6,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.Date; +import java.util.Objects; /* { @@ -188,7 +189,7 @@ public class NSSettingsStatus { return result; } } - if (settingsO.has("alarmTimeagoWarnMins") && what == "alarmTimeagoWarnMins"){ + if (settingsO.has("alarmTimeagoWarnMins") && Objects.equals(what, "alarmTimeagoWarnMins")){ Double result = settingsO.getDouble(what); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index 0eb8d93720..e2edb1e76a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -20,6 +20,7 @@ import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; import java.text.DecimalFormat; +import java.util.Objects; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -86,7 +87,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - if (insulinAfterConstraints - insulin != 0 || carbsAfterConstraints != carbs) + if (insulinAfterConstraints - insulin != 0 || !Objects.equals(carbsAfterConstraints, carbs)) confirmMessage += "\n" + getString(R.string.constraintapllied); final double finalInsulinAfterConstraints = insulinAfterConstraints; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 663a3a1a85..8ad00bf642 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -55,6 +55,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -1740,7 +1741,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onBindViewHolder(NotificationsViewHolder holder, int position) { Notification notification = notificationsList.get(position); holder.dismiss.setTag(notification); - if(notification.text == MainApp.sResources.getString(R.string.nsalarm_staledata)) + if(Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata))) holder.dismiss.setText("snooze"); holder.text.setText(notification.text); holder.time.setText(DateUtil.timeString(notification.date));