diff --git a/app/src/main/java/net/micode/notes/gtask/data/Node.java b/app/src/main/java/net/micode/notes/gtask/data/Node.java index 63950e0..4685727 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -20,33 +20,29 @@ import android.database.Cursor; import org.json.JSONObject; +/** + * 同步节点抽象类,定义了GTask同步操作的基本属性和方法 + * 所有同步节点类都应继承自该类 + */ public abstract class Node { - public static final int SYNC_ACTION_NONE = 0; - - public static final int SYNC_ACTION_ADD_REMOTE = 1; - - public static final int SYNC_ACTION_ADD_LOCAL = 2; - - public static final int SYNC_ACTION_DEL_REMOTE = 3; - - public static final int SYNC_ACTION_DEL_LOCAL = 4; - - public static final int SYNC_ACTION_UPDATE_REMOTE = 5; - - public static final int SYNC_ACTION_UPDATE_LOCAL = 6; - - public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; - - public static final int SYNC_ACTION_ERROR = 8; - - private String mGid; - - private String mName; - - private long mLastModified; - - private boolean mDeleted; - + // 同步操作类型常量 + public static final int SYNC_ACTION_NONE = 0; // 无操作 + public static final int SYNC_ACTION_ADD_REMOTE = 1; // 远程添加 + public static final int SYNC_ACTION_ADD_LOCAL = 2; // 本地添加 + public static final int SYNC_ACTION_DEL_REMOTE = 3; // 远程删除 + public static final int SYNC_ACTION_DEL_LOCAL = 4; // 本地删除 + public static final int SYNC_ACTION_UPDATE_REMOTE = 5; // 远程更新 + public static final int SYNC_ACTION_UPDATE_LOCAL = 6; // 本地更新 + public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; // 更新冲突 + public static final int SYNC_ACTION_ERROR = 8; // 操作错误 + + // 节点基本属性 + private String mGid; // 全局唯一ID + private String mName; // 节点名称 + private long mLastModified; // 最后修改时间 + private boolean mDeleted; // 删除标记 + + // 构造方法,初始化属性默认值 public Node() { mGid = null; mName = ""; @@ -54,48 +50,61 @@ public abstract class Node { mDeleted = false; } + // 创建同步操作的JSON对象(由子类实现) public abstract JSONObject getCreateAction(int actionId); + // 更新同步操作的JSON对象(由子类实现) public abstract JSONObject getUpdateAction(int actionId); + // 从远程JSON设置内容(由子类实现) public abstract void setContentByRemoteJSON(JSONObject js); + // 从本地JSON设置内容(由子类实现) public abstract void setContentByLocalJSON(JSONObject js); + // 从内容获取本地JSON(由子类实现) public abstract JSONObject getLocalJSONFromContent(); + // 获取同步操作类型(由子类实现) public abstract int getSyncAction(Cursor c); + // 设置全局ID public void setGid(String gid) { this.mGid = gid; } + // 设置节点名称 public void setName(String name) { this.mName = name; } + // 设置最后修改时间 public void setLastModified(long lastModified) { this.mLastModified = lastModified; } + // 设置删除标记 public void setDeleted(boolean deleted) { this.mDeleted = deleted; } + // 获取全局ID public String getGid() { return this.mGid; } + // 获取节点名称 public String getName() { return this.mName; } + // 获取最后修改时间 public long getLastModified() { return this.mLastModified; } + // 获取删除状态 public boolean getDeleted() { return this.mDeleted; } - -} +} \ No newline at end of file