From 681beccf7b7e50308a74bca534f46d0d1c7db04d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 19 Feb 2021 13:35:57 +0100 Subject: [PATCH] make classes static where possible --- .../graphExtensions/AreaGraphSeries.java | 12 ++++---- .../graphExtensions/FixedLineGraphSeries.java | 30 ++++++++----------- .../androidaps/utils/TimeListEdit.java | 3 +- .../nightscout/androidaps/data/Profile.java | 27 +++++++++-------- .../pump/medtronic/util/MedtronicConst.java | 2 +- .../dialog/RileyLinkStatusActivity.java | 6 ++-- .../BaseComplicationProviderService.java | 4 +-- .../testing/mocks/SharedPreferencesMock.java | 2 +- 8 files changed, 42 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java index 6d6cf27b51..1eef5c790c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/AreaGraphSeries.java @@ -39,7 +39,7 @@ public class AreaGraphSeries extends BaseSeries { /** * wrapped styles regarding the line */ - private final class Styles { + private static final class Styles { /** * the thickness of the line. * This option will be ignored if you are @@ -115,7 +115,7 @@ public class AreaGraphSeries extends BaseSeries { /** * creates a series without data */ - public AreaGraphSeries() { + @SuppressWarnings("unused") public AreaGraphSeries() { init(); } @@ -174,9 +174,9 @@ public class AreaGraphSeries extends BaseSeries { Iterator values = getValues(minX, maxX); // draw background - double lastEndY1 = 0; - double lastEndY2 = 0; - double lastEndX = 0; + double lastEndY1; + double lastEndY2; + double lastEndX; // draw data mPaint.setStrokeWidth(mStyles.thickness); @@ -205,8 +205,6 @@ public class AreaGraphSeries extends BaseSeries { lastEndY1 = 0; lastEndY2 = 0; lastEndX = 0; - double lastUsedEndX = 0; - float firstX = 0; int i=0; while (values.hasNext()) { E value = values.next(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java index 1ccbcd85cf..4cfb27edcd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphExtensions/FixedLineGraphSeries.java @@ -1,9 +1,5 @@ package info.nightscout.androidaps.plugins.general.overview.graphExtensions; -/** - * Created by mike on 24.04.2017. - */ - import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -25,7 +21,7 @@ public class FixedLineGraphSeries extends BaseSeri /** * wrapped styles regarding the line */ - private final class Styles { + private static final class Styles { /** * the thickness of the line. * This option will be ignored if you are @@ -100,7 +96,7 @@ public class FixedLineGraphSeries extends BaseSeri /** * creates a series without data */ - public FixedLineGraphSeries() { + @SuppressWarnings("unused") public FixedLineGraphSeries() { init(); } @@ -158,8 +154,8 @@ public class FixedLineGraphSeries extends BaseSeri Iterator values = getValues(minX, maxX); // draw background - double lastEndY = 0; - double lastEndX = 0; + double lastEndY; + double lastEndX; // draw data mPaint.setStrokeWidth(mStyles.thickness); @@ -263,8 +259,8 @@ public class FixedLineGraphSeries extends BaseSeri lastUsedEndX = endX; } else if (mStyles.drawDataPoints) { //fix: last value not drawn as datapoint. Draw first point here, and then on every step the end values (above) - float first_X = (float) x + (graphLeft + 1); - float first_Y = (float) (graphTop - y) + graphHeight; + // float first_X = (float) x + (graphLeft + 1); + // float first_Y = (float) (graphTop - y) + graphHeight; //TODO canvas.drawCircle(first_X, first_Y, dataPointsRadius, mPaint); } lastEndY = orgY; @@ -289,7 +285,7 @@ public class FixedLineGraphSeries extends BaseSeri * * @return the thickness of the line */ - public int getThickness() { + @SuppressWarnings("unused") public int getThickness() { return mStyles.thickness; } @@ -312,7 +308,7 @@ public class FixedLineGraphSeries extends BaseSeri * @return whether the background will be drawn * @see #getBackgroundColor() */ - public boolean isDrawBackground() { + @SuppressWarnings("unused") public boolean isDrawBackground() { return mStyles.drawBackground; } @@ -335,7 +331,7 @@ public class FixedLineGraphSeries extends BaseSeri * @return flag whether the data points are highlighted * @see #setDataPointsRadius(float) */ - public boolean isDrawDataPoints() { + @SuppressWarnings("unused") public boolean isDrawDataPoints() { return mStyles.drawDataPoints; } @@ -346,7 +342,7 @@ public class FixedLineGraphSeries extends BaseSeri * @param drawDataPoints flag whether the data points are highlighted * @see #setDataPointsRadius(float) */ - public void setDrawDataPoints(boolean drawDataPoints) { + @SuppressWarnings("unused") public void setDrawDataPoints(boolean drawDataPoints) { mStyles.drawDataPoints = drawDataPoints; } @@ -354,7 +350,7 @@ public class FixedLineGraphSeries extends BaseSeri * @return the radius for the data points. * @see #setDrawDataPoints(boolean) */ - public float getDataPointsRadius() { + @SuppressWarnings("unused") public float getDataPointsRadius() { return mStyles.dataPointsRadius; } @@ -362,7 +358,7 @@ public class FixedLineGraphSeries extends BaseSeri * @param dataPointsRadius the radius for the data points. * @see #setDrawDataPoints(boolean) */ - public void setDataPointsRadius(float dataPointsRadius) { + @SuppressWarnings("unused") public void setDataPointsRadius(float dataPointsRadius) { mStyles.dataPointsRadius = dataPointsRadius; } @@ -371,7 +367,7 @@ public class FixedLineGraphSeries extends BaseSeri * the line. * @see #setDrawBackground(boolean) */ - public int getBackgroundColor() { + @SuppressWarnings("unused") public int getBackgroundColor() { return mStyles.backgroundColor; } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java index fd72be7b93..af6fd3e742 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java @@ -266,7 +266,7 @@ public class TimeListEdit { } - class SpinnerAdapter extends ArrayAdapter { + static class SpinnerAdapter extends ArrayAdapter { List values; SpinnerAdapter(@NonNull Context context, int resource, final @NonNull List objects, final @NonNull List values) { @@ -371,6 +371,7 @@ public class TimeListEdit { } + @SuppressWarnings("SameParameterValue") private void addItem(int index, int timeAsSeconds, double value1, double value2) { if (itemsCount() >= 24) return; if (itemsCount() > inflatedUntil) { diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 490bbcecb0..fbc60b5ec1 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.data; import androidx.collection.LongSparseArray; +import org.jetbrains.annotations.NotNull; import org.joda.time.DateTime; import org.json.JSONArray; import org.json.JSONException; @@ -66,7 +67,7 @@ public class Profile { this.injector = injector; } - @Override + @NotNull @Override public String toString() { if (json != null) return json.toString(); @@ -137,7 +138,7 @@ public class Profile { public String log() { String ret = "\n"; - for (Integer hour = 0; hour < 24; hour++) { + for (int hour = 0; hour < 24; hour++) { double value = getBasalTimeFromMidnight(hour * 60 * 60); ret += "NS basal value for " + hour + ":00 is " + value + "\n"; } @@ -184,7 +185,7 @@ public class Profile { for (int index = 0; index < array.length(); index++) { try { final JSONObject o = array.getJSONObject(index); - long tas = 0; + long tas; try { String time = o.getString("time"); tas = getShitfTimeSecs(DateUtil.toSeconds(time)); @@ -318,7 +319,7 @@ public class Profile { */ Integer getShitfTimeSecs(Integer originalTime) { - Integer shiftedTime = originalTime + timeshift * 60 * 60; + int shiftedTime = originalTime + timeshift * 60 * 60; shiftedTime = (shiftedTime + 24 * 60 * 60) % (24 * 60 * 60); return shiftedTime; } @@ -358,7 +359,7 @@ public class Profile { private double getValueToTime(LongSparseArray array, Integer timeAsSeconds) { Double lastValue = null; - for (Integer index = 0; index < array.size(); index++) { + for (int index = 0; index < array.size(); index++) { long tas = array.keyAt(index); double value = array.valueAt(index); if (lastValue == null) lastValue = value; @@ -459,8 +460,8 @@ public class Profile { ic_v = convertToSparseArray(ic); ProfileValue[] ret = new ProfileValue[ic_v.size()]; - for (Integer index = 0; index < ic_v.size(); index++) { - Integer tas = (int) ic_v.keyAt(index); + for (int index = 0; index < ic_v.size(); index++) { + int tas = (int) ic_v.keyAt(index); double value = ic_v.valueAt(index); ret[index] = new ProfileValue(tas, value); } @@ -488,7 +489,7 @@ public class Profile { return getValuesList(basal_v, null, new DecimalFormat("0.00"), resourceHelper.gs(R.string.profile_ins_units_per_hour)); } - public class ProfileValue { + public static class ProfileValue { public ProfileValue(int timeAsSeconds, double value) { this.timeAsSeconds = timeAsSeconds; this.value = value; @@ -515,8 +516,8 @@ public class Profile { basal_v = convertToSparseArray(basal); ProfileValue[] ret = new ProfileValue[basal_v.size()]; - for (Integer index = 0; index < basal_v.size(); index++) { - Integer tas = (int) basal_v.keyAt(index); + for (int index = 0; index < basal_v.size(); index++) { + int tas = (int) basal_v.keyAt(index); double value = basal_v.valueAt(index); ret[index] = new ProfileValue(tas, value); } @@ -566,7 +567,7 @@ public class Profile { return toMgdl(getTargetHighTimeFromMidnight(timeAsSeconds), units); } - public class TargetValue { + public static class TargetValue { TargetValue(int timeAsSeconds, double low, double high) { this.timeAsSeconds = timeAsSeconds; this.low = low; @@ -585,8 +586,8 @@ public class Profile { targetHigh_v = convertToSparseArray(targetHigh); TargetValue[] ret = new TargetValue[targetLow_v.size()]; - for (Integer index = 0; index < targetLow_v.size(); index++) { - Integer tas = (int) targetLow_v.keyAt(index); + for (int index = 0; index < targetLow_v.size(); index++) { + int tas = (int) targetLow_v.keyAt(index); double low = targetLow_v.valueAt(index); double high = targetHigh_v.valueAt(index); ret[index] = new TargetValue(tas, low, high); diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java index c02f4fcf8f..8a05ad6d35 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java @@ -22,7 +22,7 @@ public class MedtronicConst { public static final int BolusDebugEnabled = R.string.key_medtronic_bolus_debug; } - public class Statistics { + public static class Statistics { public static final String StatsPrefix = "medtronic_"; public static final String FirstPumpStart = Prefix + "first_pump_use"; diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java index 45d2bbbe7b..1010558316 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java @@ -10,6 +10,8 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.List; @@ -68,7 +70,7 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity { * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ - public class SectionsPagerAdapter extends FragmentPagerAdapter { + public static class SectionsPagerAdapter extends FragmentPagerAdapter { List fragmentList = new ArrayList<>(); List fragmentTitle = new ArrayList<>(); @@ -78,7 +80,7 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity { super(fm); } - @Override + @NotNull @Override public Fragment getItem(int position) { this.lastSelectedPosition = position; return fragmentList.get(position); diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java b/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java index 4e998e20f8..f510c9e267 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java +++ b/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java @@ -194,7 +194,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND); - messageReceiver = new BaseComplicationProviderService.MessageReceiver(); + messageReceiver = new MessageReceiver(); localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.registerReceiver(messageReceiver, messageFilter); @@ -395,7 +395,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid /* * Listen to broadcast --> new data was stored by ListenerService to Persistence */ - public class MessageReceiver extends BroadcastReceiver { + public static class MessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Set complications = Persistence.setOf(KEY_COMPLICATIONS); diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java b/wear/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java index 5b0736a450..33181dd751 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mocks/SharedPreferencesMock.java @@ -12,7 +12,7 @@ public class SharedPreferencesMock implements SharedPreferences { private final EditorInternals editor = new EditorInternals(); - class EditorInternals implements Editor { + static class EditorInternals implements Editor { Map innerMap = new HashMap<>();