diff --git a/Notes-master1/.gradle/7.6.1/checksums/checksums.lock b/Notes-master1/.gradle/7.6.1/checksums/checksums.lock index 296bb81..526311e 100644 Binary files a/Notes-master1/.gradle/7.6.1/checksums/checksums.lock and b/Notes-master1/.gradle/7.6.1/checksums/checksums.lock differ diff --git a/Notes-master1/.gradle/7.6.1/checksums/md5-checksums.bin b/Notes-master1/.gradle/7.6.1/checksums/md5-checksums.bin index 5e449db..53c7cc5 100644 Binary files a/Notes-master1/.gradle/7.6.1/checksums/md5-checksums.bin and b/Notes-master1/.gradle/7.6.1/checksums/md5-checksums.bin differ diff --git a/Notes-master1/.gradle/7.6.1/checksums/sha1-checksums.bin b/Notes-master1/.gradle/7.6.1/checksums/sha1-checksums.bin index 99c27d9..b16af4e 100644 Binary files a/Notes-master1/.gradle/7.6.1/checksums/sha1-checksums.bin and b/Notes-master1/.gradle/7.6.1/checksums/sha1-checksums.bin differ diff --git a/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.bin b/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.bin index e7f5408..49322e7 100644 Binary files a/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.bin and b/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.bin differ diff --git a/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.lock b/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.lock index fccb03f..4fe69a0 100644 Binary files a/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.lock and b/Notes-master1/.gradle/7.6.1/executionHistory/executionHistory.lock differ diff --git a/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.bin b/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.bin index 6edb8b4..5bdccea 100644 Binary files a/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.bin and b/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.bin differ diff --git a/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.lock b/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.lock index 37d54c0..2abd99d 100644 Binary files a/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.lock and b/Notes-master1/.gradle/7.6.1/fileHashes/fileHashes.lock differ diff --git a/Notes-master1/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/Notes-master1/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 2034ebd..7139512 100644 Binary files a/Notes-master1/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/Notes-master1/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/Notes-master1/.gradle/buildOutputCleanup/outputFiles.bin b/Notes-master1/.gradle/buildOutputCleanup/outputFiles.bin index dcff715..71de027 100644 Binary files a/Notes-master1/.gradle/buildOutputCleanup/outputFiles.bin and b/Notes-master1/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/Notes-master1/app/src/main/java/net/micode/notes/data/Notes.java b/Notes-master1/app/src/main/java/net/micode/notes/data/Notes.java index f240604..3c4e36a 100644 --- a/Notes-master1/app/src/main/java/net/micode/notes/data/Notes.java +++ b/Notes-master1/app/src/main/java/net/micode/notes/data/Notes.java @@ -18,6 +18,8 @@ package net.micode.notes.data; import android.net.Uri; public class Notes { + private static final String UTILITY_CLASS = "Utility class"; + private static final String CONTENT = "content://"; public static final String AUTHORITY = "micode_notes"; public static final String TAG = "Notes"; public static final int TYPE_NOTE = 0; @@ -47,6 +49,10 @@ public class Notes { public static final int TYPE_WIDGET_4X = 1; public static class DataConstants { + private DataConstants() + { + throw new IllegalStateException(UTILITY_CLASS); + } public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; } @@ -54,14 +60,26 @@ public class Notes { /** * Uri to query all notes and folders */ - public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); + public static final Uri CONTENT_NOTE_URI = Uri.parse(CONTENT + AUTHORITY + "/note"); /** * Uri to query data */ - public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); - - public interface NoteColumns { + public static final Uri CONTENT_DATA_URI = Uri.parse(CONTENT + AUTHORITY + "/data"); + //常量接口模式是对接口的一种不良使用。 + //一个类在内部使用一些常量是一个实现细节。 + /* + 实现一个常量接口会导致这个实现细节泄露到该类的输出API中。对于一个类的用户来说,该类实现了一个常量接口是没有任何意义的。 + 事实上,这甚至会使他们感到困惑。更糟糕的是,它代表了一种承诺:如果在未来的版本中,类被修改得不再需要使用常量,它仍然必须实现这个接口以确保二进制的兼容性。如果一个非最终版本的类实现了一个常量接口它的所有子类都会被接口中的常量污染它们的名字空间。 + 当一个接口只由字段组成,没有任何其他成员时,这个规则就会引起问题。 + */ + //解决方法:将常量接口改成常量类或者枚举类 + public final class NoteColumns { + //实用程序类(实用程序类是定义一组执行通用功能的方法的类),不能用自带的构造函数,实用程序类一般都是包含的静态方法。 它通常是用来包装一些的“有用”的算法 + private NoteColumns() + { + throw new IllegalStateException(UTILITY_CLASS); + } /** * The unique ID for a row *

Type: INTEGER (long)

@@ -167,7 +185,11 @@ public class Notes { public static final String VERSION = "version"; } - public interface DataColumns { + public final class DataColumns { + private DataColumns() + { + throw new IllegalStateException(UTILITY_CLASS); + } /** * The unique ID for a row *

Type: INTEGER (long)

@@ -241,12 +263,16 @@ public class Notes { public static final String DATA5 = "data5"; } - public static final class TextNote implements DataColumns { + public static final class TextNote { + private TextNote() + { + throw new IllegalStateException(UTILITY_CLASS); + } /** * Mode to indicate the text in check list mode or not *

Type: Integer 1:check list mode 0: normal mode

*/ - public static final String MODE = DATA1; + public static final String MODE = DataColumns.DATA1; public static final int MODE_CHECK_LIST = 1; @@ -254,26 +280,30 @@ public class Notes { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); + public static final Uri CONTENT_URI = Uri.parse(CONTENT + AUTHORITY + "/text_note"); } - public static final class CallNote implements DataColumns { + public static final class CallNote { + private CallNote() + { + throw new IllegalStateException(UTILITY_CLASS); + } /** * Call date for this record *

Type: INTEGER (long)

*/ - public static final String CALL_DATE = DATA1; + public static final String CALL_DATE = DataColumns.DATA1; /** * Phone number for this record *

Type: TEXT

*/ - public static final String PHONE_NUMBER = DATA3; + public static final String PHONE_NUMBER = DataColumns.DATA3; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); + public static final Uri CONTENT_URI = Uri.parse(CONTENT + AUTHORITY + "/call_note"); } } diff --git a/Notes-master1/app/src/main/java/net/micode/notes/model/Note.java b/Notes-master1/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..bd17f50 100644 --- a/Notes-master1/app/src/main/java/net/micode/notes/model/Note.java +++ b/Notes-master1/app/src/main/java/net/micode/notes/model/Note.java @@ -35,6 +35,8 @@ import java.util.ArrayList; public class Note { + //重复字符串定义为常量 + private static final String WRONG_NOTE_ID = "Wrong note id:"; private ContentValues mNoteDiffValues; private NoteData mNoteData; private static final String TAG = "Note"; @@ -60,7 +62,7 @@ public class Note { noteId = 0; } if (noteId == -1) { - throw new IllegalStateException("Wrong note id:" + noteId); + throw new IllegalStateException(WRONG_NOTE_ID + noteId); } return noteId; } @@ -102,7 +104,7 @@ public class Note { public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); + throw new IllegalArgumentException(WRONG_NOTE_ID + noteId); } if (!isLocalModified()) { @@ -183,7 +185,7 @@ public class Note { * Check for safety */ if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); + throw new IllegalArgumentException(WRONG_NOTE_ID + noteId); } ArrayList operationList = new ArrayList();