You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiNote/gtask/data/Node.java

134 lines
4.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
/**
* 同步节点抽象类,定义同步操作的基础模型和行为
* 用于表示Google Tasks中的任务、列表等实体的同步状态和数据
*/
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;// Google Tasks全局唯一标识符GID
private String mName;// 节点名称(如任务标题、列表名称)
private long mLastModified;// 最后修改时间戳
private boolean mDeleted;// 是否已删除标记
/**
* 构造方法,初始化节点默认状态
*/
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
// ====================== 抽象方法(子类必须实现) ======================
/**
* 获取创建操作的JSON数据
* @param actionId 操作ID用于标识不同的创建场景
* @return 包含创建操作的JSON对象
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* 获取更新操作的JSON数据
* @param actionId 操作ID用于标识不同的更新场景
* @return 包含更新操作的JSON对象
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* 从远程JSON数据中解析并设置节点内容供同步模块调用
* @param js 包含远程数据的JSON对象
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* 从本地JSON数据中解析并设置节点内容供本地存储模块调用
* @param js 包含本地数据的JSON对象
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* 将节点内容转换为本地存储的JSON格式
* @return 表示节点内容的JSON对象
*/
public abstract JSONObject getLocalJSONFromContent();
/**
* 获取节点的同步操作类型(根据数据库游标数据判断)
* @param c 包含节点数据的数据库游标
* @return 同步操作类型常量如SYNC_ACTION_ADD_LOCAL
*/
public abstract int getSyncAction(Cursor c);
// ====================== 基础属性访问方法 ======================
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;
}
public String getGid() {
return this.mGid;
}
public String getName() {
return this.mName;
}
public long getLastModified() {
return this.mLastModified;
}
public boolean getDeleted() {
return this.mDeleted;
}
}