From d228b64819d4c6abc74d59118acbb5a847615d00 Mon Sep 17 00:00:00 2001 From: ziji Wu <2193177243@qq.com> Date: Tue, 10 Sep 2019 17:39:34 +0800 Subject: [PATCH] correct some error by sonarlint --- .../java/net/micode/notes/model/Note.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/src/main/java/net/micode/notes/model/Note.java b/src/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..8a67f03 100644 --- a/src/app/src/main/java/net/micode/notes/model/Note.java +++ b/src/app/src/main/java/net/micode/notes/model/Note.java @@ -38,6 +38,7 @@ public class Note { private ContentValues mNoteDiffValues; private NoteData mNoteData; private static final String TAG = "Note"; + private static final String WRONGNOTEID = "Wrong note id:"; /** * Create a new note id for adding a new note to databases */ @@ -60,7 +61,7 @@ public class Note { noteId = 0; } if (noteId == -1) { - throw new IllegalStateException("Wrong note id:" + noteId); + throw new IllegalStateException(WRONGNOTEID + noteId); } return noteId; } @@ -102,7 +103,7 @@ public class Note { public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); + throw new IllegalArgumentException(WRONGNOTEID + noteId); } if (!isLocalModified()) { @@ -122,8 +123,7 @@ public class Note { } mNoteDiffValues.clear(); - if (mNoteData.isLocalModified() - && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { + if (mNoteData.isLocalModified() && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; } @@ -183,10 +183,10 @@ public class Note { * Check for safety */ if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); + throw new IllegalArgumentException(WRONGNOTEID + noteId); } - ArrayList operationList = new ArrayList(); + ArrayList operationList = new ArrayList<>(); ContentProviderOperation.Builder builder = null; if(mTextDataValues.size() > 0) { @@ -233,16 +233,13 @@ public class Note { mCallDataValues.clear(); } - if (operationList.size() > 0) { + if (!operationList.isEmpty()) { try { ContentProviderResult[] results = context.getContentResolver().applyBatch( Notes.AUTHORITY, operationList); return (results == null || results.length == 0 || results[0] == null) ? null : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); - } catch (RemoteException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - return null; - } catch (OperationApplicationException e) { + } catch (RemoteException|OperationApplicationException e) { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); return null; }