Replace switches with too few cases with ifs

This commit is contained in:
TacoTheDank 2020-05-31 02:24:17 -04:00
parent 634322af33
commit df8a083ec7
6 changed files with 23 additions and 45 deletions

View File

@ -61,11 +61,8 @@ public final class ResponseList$$JsonObjectMapper<T> extends JsonMapper<Response
@Override @Override
public void parseField(ResponseList<T> instance, String fieldName, JsonParser jsonParser) throws IOException { public void parseField(ResponseList<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
switch (fieldName) { if ("results".equals(fieldName)) {
case "results": { instance.addAll(m84ClassJsonMapper.parseList(jsonParser));
instance.addAll(m84ClassJsonMapper.parseList(jsonParser));
break;
}
} }
} }

View File

@ -35,10 +35,8 @@ import java.io.IOException;
public abstract class ConversationExtras implements Parcelable { public abstract class ConversationExtras implements Parcelable {
public static ConversationExtras parse(@NonNull final String extrasType, @Nullable final String json) throws IOException { public static ConversationExtras parse(@NonNull final String extrasType, @Nullable final String json) throws IOException {
if (json == null) return null; if (json == null) return null;
switch (extrasType) { if (ExtrasType.TWITTER_OFFICIAL.equals(extrasType)) {
case ExtrasType.TWITTER_OFFICIAL: { return LoganSquare.parse(json, TwitterOfficialConversationExtras.class);
return LoganSquare.parse(json, TwitterOfficialConversationExtras.class);
}
} }
return LoganSquare.parse(json, DefaultConversationExtras.class); return LoganSquare.parse(json, DefaultConversationExtras.class);
} }

View File

@ -66,12 +66,9 @@ public final class DataExportImportTypeSelectorDialogFragment extends BaseDialog
@Override @Override
public final void onClick(final DialogInterface dialog, final int which) { public final void onClick(final DialogInterface dialog, final int which) {
switch (which) { if (which == DialogInterface.BUTTON_POSITIVE) {
case DialogInterface.BUTTON_POSITIVE: { final int flags = getCheckedFlags();
final int flags = getCheckedFlags(); onPositiveButtonClicked(flags);
onPositiveButtonClicked(flags);
break;
}
} }
} }

View File

@ -66,12 +66,10 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { if (item.getItemId() == R.id.reset) {
case R.id.reset: { final DialogFragment f = new ResetKeyboardShortcutConfirmDialogFragment();
final DialogFragment f = new ResetKeyboardShortcutConfirmDialogFragment(); f.show(getFragmentManager(), "reset_keyboard_shortcut_confirm");
f.show(getFragmentManager(), "reset_keyboard_shortcut_confirm"); return true;
return true;
}
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -132,11 +130,8 @@ public class KeyboardShortcutsFragment extends BasePreferenceFragment implements
implements OnClickListener { implements OnClickListener {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { if (which == DialogInterface.BUTTON_POSITIVE) {
case DialogInterface.BUTTON_POSITIVE: { keyboardShortcutsHandler.reset();
keyboardShortcutsHandler.reset();
break;
}
} }
} }

View File

@ -112,13 +112,11 @@ public class RecyclerViewNavigationHelper implements KeyboardShortcutCallback {
public boolean handleKeyboardShortcutSingle(@NonNull KeyboardShortcutsHandler handler, int keyCode, @NonNull KeyEvent event, int metaState) { public boolean handleKeyboardShortcutSingle(@NonNull KeyboardShortcutsHandler handler, int keyCode, @NonNull KeyEvent event, int metaState) {
final String action = handler.getKeyAction(CONTEXT_TAG_NAVIGATION, keyCode, event, metaState); final String action = handler.getKeyAction(CONTEXT_TAG_NAVIGATION, keyCode, event, metaState);
if (action == null) return false; if (action == null) return false;
switch (action) { if (ACTION_NAVIGATION_TOP.equals(action)) {
case ACTION_NAVIGATION_TOP: { if (iface != null) {
if (iface != null) { iface.scrollToStart();
iface.scrollToStart();
}
return true;
} }
return true;
} }
return false; return false;
} }

View File

@ -15,12 +15,7 @@ public class ImgurProvider implements Provider {
public boolean supports(@NonNull String link) { public boolean supports(@NonNull String link) {
final String authority = UriUtils.getAuthority(link); final String authority = UriUtils.getAuthority(link);
if (authority == null) return false; if (authority == null) return false;
switch (authority) { return "i.imgur.com".equals(authority);
case "i.imgur.com":
return true;
default:
return false;
}
} }
@Nullable @Nullable
@ -28,13 +23,11 @@ public class ImgurProvider implements Provider {
public ParcelableMedia from(@NonNull String url) { public ParcelableMedia from(@NonNull String url) {
final String authority = UriUtils.getAuthority(url); final String authority = UriUtils.getAuthority(url);
if (authority == null) return null; if (authority == null) return null;
switch (authority) { if ("i.imgur.com".equals(authority)) {
case "i.imgur.com": { final String path = UriUtils.getPath(url);
final String path = UriUtils.getPath(url); if (path == null) return null;
if (path == null) return null; ParcelableMedia media = new ParcelableMedia();
ParcelableMedia media = new ParcelableMedia(); media.url = url;
media.url = url;
}
} }
return null; return null;
} }