replace assertions with good old if()
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 May 2019 15:17:05 +0000 (18:17 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 May 2019 15:18:53 +0000 (18:18 +0300)
assertions aren't implemented in Android's Java?

app/src/main/java/net/ktnx/mobileledger/async/UpdateAccountsTask.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index 328eff4..667bf99 100644 (file)
@@ -35,7 +35,7 @@ public class UpdateAccountsTask extends AsyncTask<Void, Void, ArrayList<LedgerAc
         Data.backgroundTaskStarted();
         try {
             MobileLedgerProfile profile = Data.profile.getValue();
-            assert profile != null;
+            if (profile == null) throw new AssertionError();
             String profileUUID = profile.getUuid();
             boolean onlyStarred = Data.optShowOnlyStarred.get();
             ArrayList<LedgerAccount> newList = new ArrayList<>();
index 243cb36..223a61e 100644 (file)
@@ -78,7 +78,7 @@ public final class Data {
     public static int getProfileIndex(MobileLedgerProfile profile) {
         try (LockHolder ignored = profilesLocker.lockForReading()) {
             List<MobileLedgerProfile> prList = profiles.getValue();
-            assert prList != null;
+            if (prList == null) throw new AssertionError();
             for (int i = 0; i < prList.size(); i++) {
                 MobileLedgerProfile p = prList.get(i);
                 if (p.equals(profile)) return i;
@@ -91,7 +91,7 @@ public final class Data {
     public static int getProfileIndex(String profileUUID) {
         try (LockHolder ignored = profilesLocker.lockForReading()) {
             List<MobileLedgerProfile> prList = profiles.getValue();
-            assert prList != null;
+            if (prList == null) throw new AssertionError();
             for (int i = 0; i < prList.size(); i++) {
                 MobileLedgerProfile p = prList.get(i);
                 if (p.getUuid().equals(profileUUID)) return i;
index 470a3ea..c0944f9 100644 (file)
@@ -108,7 +108,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
                         String.format("[fragment] removing profile %s", mProfile.getUuid()));
                 mProfile.removeFromDB();
                 ArrayList<MobileLedgerProfile> oldList = Data.profiles.getValue();
-                assert oldList != null;
+                if (oldList == null) throw new AssertionError();
                 ArrayList<MobileLedgerProfile> newList =
                         (ArrayList<MobileLedgerProfile>) oldList.clone();
                 newList.remove(mProfile);
@@ -144,7 +144,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         int index = Data.getProfileIndex(mProfile);
         MobileLedgerProfile newProfile = new MobileLedgerProfile(mProfile);
         final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-        assert profiles != null;
+        if (profiles == null) throw new AssertionError();
         profiles.set(index, newProfile);
         if (mProfile.equals(Data.profile.getValue())) Data.profile.setValue(newProfile);
     }
@@ -193,7 +193,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             updateProfileFromUI();
             mProfile.storeInDB();
             final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-            assert profiles != null;
+            if (profiles == null) throw new AssertionError();
             ArrayList<MobileLedgerProfile> newList =
                     (ArrayList<MobileLedgerProfile>) profiles.clone();
             newList.add(mProfile);
index 4ad4fdb..eb3d0a0 100644 (file)
@@ -71,7 +71,7 @@ public class ProfilesRecyclerViewAdapter
                                   @NonNull RecyclerView.ViewHolder viewHolder,
                                   @NonNull RecyclerView.ViewHolder target) {
                 final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-                assert profiles != null;
+                if (profiles == null) throw new AssertionError();
                 Collections.swap(profiles, viewHolder.getAdapterPosition(),
                         target.getAdapterPosition());
                 MobileLedgerProfile.storeProfilesOrder();
@@ -165,7 +165,7 @@ public class ProfilesRecyclerViewAdapter
     @Override
     public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) {
         final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-        assert profiles != null;
+        if (profiles == null) throw new AssertionError();
         final MobileLedgerProfile profile = profiles.get(position);
         final MobileLedgerProfile currentProfile = Data.profile.getValue();
         debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position,