]> git.ktnx.net Git - mobile-ledger.git/commitdiff
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 328eff45c2f6f529d65015300782cd88df6ac2b3..667bf99809f6e29f6da971651f70cd5e673e4823 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 243cb36138dd580e751c2ca31b6ed19688239f27..223a61e8aa7ebe621a2df2b3b051c2d589a31378 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 470a3eaee682e99ae0c436e28466059ef90f207e..c0944f9a9261bd0aa1355a36fd2b7c9ba570df12 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 4ad4fdbe0d775323f027b5c996c6fc2a8175dc98..eb3d0a0d115fd15ea8dc41697157e13e5d0541ab 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,