Sfoglia il codice sorgente

Merge pull request #10074 from nextcloud/equals

Replace equals with == on enums
Álvaro Brey 3 anni fa
parent
commit
0e03400486

+ 2 - 2
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1192,12 +1192,12 @@ public class FileDataStorageManager {
             + ProviderTableMeta.OCSHARES_SHARE_TYPE + AND
             + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?";
 
-        if (!ShareType.PUBLIC_LINK.equals(type)) {
+        if (ShareType.PUBLIC_LINK != type) {
             selection += " AND " + ProviderTableMeta.OCSHARES_SHARE_WITH + " = ?";
         }
 
         String[] selectionArgs;
-        if (ShareType.PUBLIC_LINK.equals(type)) {
+        if (ShareType.PUBLIC_LINK == type) {
             selectionArgs = new String[]{
                 path,
                 Integer.toString(type.getValue()),

+ 2 - 2
app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -814,7 +814,7 @@ public final class ThumbnailsCacheManager {
             // Not found in disk cache
             if (thumbnail == null) {
 
-                if (Type.IMAGE.equals(type)) {
+                if (Type.IMAGE == type) {
                     int px = getThumbnailDimension();
 
                     Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(file.getAbsolutePath(), px, px);
@@ -822,7 +822,7 @@ public final class ThumbnailsCacheManager {
                     if (bitmap != null) {
                         thumbnail = addThumbnailToCache(imageKey, bitmap, file.getPath(), px, px);
                     }
-                } else if (Type.VIDEO.equals(type)) {
+                } else if (Type.VIDEO == type) {
                     MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                     try {
                         retriever.setDataSource(file.getAbsolutePath());

+ 1 - 1
app/src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -640,7 +640,7 @@ public class FileDownloader extends Service
             int tickerId = downloadResult.isSuccess() ?
                     R.string.downloader_download_succeeded_ticker : R.string.downloader_download_failed_ticker;
 
-            boolean needsToUpdateCredentials = ResultCode.UNAUTHORIZED.equals(downloadResult.getCode());
+            boolean needsToUpdateCredentials = ResultCode.UNAUTHORIZED == downloadResult.getCode();
             tickerId = needsToUpdateCredentials ?
                     R.string.downloader_download_failed_credentials_error : tickerId;
 

+ 6 - 6
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -778,11 +778,11 @@ public class FileUploader extends Service
         // Only notify if the upload fails
         if (!uploadResult.isCancelled() &&
             !uploadResult.isSuccess() &&
-            !ResultCode.LOCAL_FILE_NOT_FOUND.equals(uploadResult.getCode()) &&
-            !uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI) &&
-            !uploadResult.getCode().equals(ResultCode.DELAYED_FOR_CHARGING) &&
-            !uploadResult.getCode().equals(ResultCode.DELAYED_IN_POWER_SAVE_MODE) &&
-            !uploadResult.getCode().equals(ResultCode.LOCK_FAILED)) {
+            ResultCode.LOCAL_FILE_NOT_FOUND != uploadResult.getCode() &&
+            uploadResult.getCode() != ResultCode.DELAYED_FOR_WIFI &&
+            uploadResult.getCode() != ResultCode.DELAYED_FOR_CHARGING &&
+            uploadResult.getCode() != ResultCode.DELAYED_IN_POWER_SAVE_MODE &&
+            uploadResult.getCode() != ResultCode.LOCK_FAILED) {
 
             int tickerId = R.string.uploader_upload_failed_ticker;
 
@@ -827,7 +827,7 @@ public class FileUploader extends Service
                 ));
             } else {
                 Intent intent;
-                if (uploadResult.getCode().equals(ResultCode.SYNC_CONFLICT)) {
+                if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) {
                     intent = ConflictsResolveActivity.createIntent(upload.getFile(),
                                                                    upload.getUser(),
                                                                    upload.getOCUploadId(),

+ 1 - 1
app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -699,7 +699,7 @@ public class RefreshFolderOperation extends RemoteOperation {
             for (Object obj : result.getData()) {
                 share = (OCShare) obj;
 
-                if (!ShareType.NO_SHARED.equals(share.getShareType())) {
+                if (ShareType.NO_SHARED != share.getShareType()) {
                     shares.add(share);
                 }
             }

+ 3 - 3
app/src/main/java/com/owncloud/android/operations/UnshareOperation.java

@@ -68,10 +68,10 @@ public class UnshareOperation extends SyncOperation {
             if (result.isSuccess()) {
                 Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
 
-                if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
+                if (ShareType.PUBLIC_LINK == share.getShareType()) {
                     file.setSharedViaLink(false);
-                } else if (ShareType.USER.equals(share.getShareType()) || ShareType.GROUP.equals(share.getShareType())
-                    || ShareType.FEDERATED.equals(share.getShareType())) {
+                } else if (ShareType.USER == share.getShareType() || ShareType.GROUP == share.getShareType()
+                    || ShareType.FEDERATED == share.getShareType()) {
                     // Check if it is the last share
                     List<OCShare> sharesWith = getStorageManager().
                         getSharesWithForAFile(remotePath,

+ 6 - 6
app/src/main/java/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -292,7 +292,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
 
         } else if (result.getCode() != ResultCode.FILE_NOT_FOUND) {
             // in failures, the statistics for the global result are updated
-            if (RemoteOperationResult.ResultCode.UNAUTHORIZED.equals(result.getCode())) {
+            if (ResultCode.UNAUTHORIZED == result.getCode()) {
                 mSyncResult.stats.numAuthExceptions++;
 
             } else if (result.getException() instanceof DavException) {
@@ -321,10 +321,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private boolean isFinisher(RemoteOperationResult failedResult) {
         if (failedResult != null) {
             RemoteOperationResult.ResultCode code = failedResult.getCode();
-            return code.equals(RemoteOperationResult.ResultCode.SSL_ERROR)
-                    || code.equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)
-                    || code.equals(RemoteOperationResult.ResultCode.BAD_OC_VERSION)
-                    || code.equals(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
+            return code == ResultCode.SSL_ERROR
+                || code == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED
+                || code == ResultCode.BAD_OC_VERSION
+                || code == ResultCode.INSTANCE_NOT_CONFIGURED;
         }
         return false;
     }
@@ -391,7 +391,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private void notifyFailedSynchronization() {
         NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
         boolean needsToUpdateCredentials = mLastFailedResult != null
-                && ResultCode.UNAUTHORIZED.equals(mLastFailedResult.getCode());
+            && ResultCode.UNAUTHORIZED == mLastFailedResult.getCode();
         if (needsToUpdateCredentials) {
             // let the user update credentials with one click
             Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class);

+ 10 - 10
app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java

@@ -348,27 +348,27 @@ public abstract class FileActivity extends DrawerActivity
         if (!result.isSuccess() && (
                 result.getCode() == ResultCode.UNAUTHORIZED ||
                 (result.isException() && result.getException() instanceof AuthenticatorException)
-                )) {
+        )) {
 
             requestCredentialsUpdate(this);
 
             if (result.getCode() == ResultCode.UNAUTHORIZED) {
                 DisplayUtils.showSnackMessage(
-                        this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
-                );
+                    this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
+                                             );
             }
 
-        } else if (!result.isSuccess() && ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(result.getCode())) {
+        } else if (!result.isSuccess() && ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == result.getCode()) {
 
             showUntrustedCertDialog(result);
 
         } else if (operation == null ||
-                operation instanceof CreateShareWithShareeOperation ||
-                operation instanceof UnshareOperation ||
-                operation instanceof SynchronizeFolderOperation ||
-                operation instanceof UpdateShareViaLinkOperation ||
-                operation instanceof UpdateSharePermissionsOperation
-                ) {
+            operation instanceof CreateShareWithShareeOperation ||
+            operation instanceof UnshareOperation ||
+            operation instanceof SynchronizeFolderOperation ||
+            operation instanceof UpdateShareViaLinkOperation ||
+            operation instanceof UpdateSharePermissionsOperation
+        ) {
             if (result.isSuccess()) {
                 updateFileFromDB();
 

+ 2 - 3
app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1299,8 +1299,7 @@ public class FileDisplayActivity extends FileActivity
                     }
                 }
 
-                if (synchResult != null && synchResult.getCode().equals(
-                    RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
+                if (synchResult != null && synchResult.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
                     mLastSslUntrustedServerResult = synchResult;
                 }
             } catch (RuntimeException e) {
@@ -1318,7 +1317,7 @@ public class FileDisplayActivity extends FileActivity
     }
 
     private boolean checkForRemoteOperationError(RemoteOperationResult syncResult) {
-        return ResultCode.UNAUTHORIZED.equals(syncResult.getCode()) ||
+        return ResultCode.UNAUTHORIZED == syncResult.getCode() ||
             (syncResult.isException() && syncResult.getException()
                 instanceof AuthenticatorException);
     }

+ 2 - 3
app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java

@@ -520,11 +520,10 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
                             /// TODO refactor and make common
                             syncResult != null && !syncResult.isSuccess()) {
 
-                            if (ResultCode.UNAUTHORIZED.equals(syncResult.getCode()) || (syncResult.isException()
+                            if (ResultCode.UNAUTHORIZED == syncResult.getCode() || (syncResult.isException()
                                 && syncResult.getException() instanceof AuthenticatorException)) {
                                 requestCredentialsUpdate(context);
-                            } else if (RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED
-                                .equals(syncResult.getCode())) {
+                            } else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) {
                                 showUntrustedCertDialog(syncResult);
                             }
 

+ 3 - 3
app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -1140,12 +1140,12 @@ public class ReceiveExternalFilesActivity extends FileActivity
                                 && syncResult != null && !syncResult.isSuccess()) {
 
                             if (syncResult.getCode() == ResultCode.UNAUTHORIZED ||
-                                    (syncResult.isException() && syncResult.getException()
-                                                instanceof AuthenticatorException)) {
+                                (syncResult.isException() && syncResult.getException()
+                                    instanceof AuthenticatorException)) {
 
                                 requestCredentialsUpdate(context);
 
-                            } else if (RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(syncResult.getCode())) {
+                            } else if (ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED == syncResult.getCode()) {
 
                                 showUntrustedCertDialog(syncResult);
                             }

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

@@ -462,7 +462,7 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
     }
 
     private boolean isReshareForbidden(OCShare share) {
-        return ShareType.FEDERATED.equals(share.getShareType()) ||
+        return ShareType.FEDERATED == share.getShareType() ||
             capabilities != null && capabilities.getFilesSharingResharing().isFalse();
     }
 

+ 5 - 5
app/src/main/java/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -264,7 +264,7 @@ public final class ErrorMessageAdapter {
         if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
             return res.getString(R.string.filename_forbidden_characters);
 
-        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+        } else if (result.getCode() == ResultCode.FORBIDDEN) {
             return String.format(res.getString(R.string.forbidden_permissions),
                                  res.getString(R.string.forbidden_permissions_create));
 
@@ -277,15 +277,15 @@ public final class ErrorMessageAdapter {
 
     private static @Nullable
     String getMessageForRenameFileOperation(RemoteOperationResult result, Resources res) {
-        if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
+        if (result.getCode() == ResultCode.INVALID_LOCAL_FILE_NAME) {
             return res.getString(R.string.rename_local_fail_msg);
 
-        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+        } else if (result.getCode() == ResultCode.FORBIDDEN) {
             // Error --> No permissions
             return String.format(res.getString(R.string.forbidden_permissions),
                                  res.getString(R.string.forbidden_permissions_rename));
 
-        } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
+        } else if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
             return res.getString(R.string.filename_forbidden_characters);
 
         } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
@@ -302,7 +302,7 @@ public final class ErrorMessageAdapter {
             return res.getString(R.string.remove_success_msg);
 
         } else {
-            if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+            if (result.getCode() == ResultCode.FORBIDDEN) {
                 // Error --> No permissions
                 return String.format(res.getString(R.string.forbidden_permissions),
                                      res.getString(R.string.forbidden_permissions_delete));

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-626
+592