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.
note/Node.java

198 lines
4.5 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.
*/
java
// 导入所需的包
package net.micode.notes.gtask.data;
import android.database.Cursor; // 用于数据库查询结果的游标
import org.json.JSONObject; // JSON对象类
// 定义一个抽象类Node它代表了一个节点如任务、笔记等的基本属性和行为
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 Node() {
mGid = null; // GID初始化为null表示新创建的节点还没有GID
mName = ""; // 名称初始化为空字符串
mLastModified = 0; // 最后修改时间初始化为0表示节点还没有被修改过
mDeleted = false; // 删除标志初始化为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);
// 设置节点的GID
public void setGid(String gid) {
this.mGid = gid;
}
// 获取节点的GID
public String getGid() {
return this.mGid;
}
// 设置节点的名称
public void setName(String name) {
this.mName = name;
}
// 获取节点的名称
public String getName() {
return this.mName;
}
// 设置节点最后修改的时间戳
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
// 获取节点最后修改的时间戳
public long getLastModified() {
return this.mLastModified;
}
// 设置节点是否被删除的标志
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
// 获取节点是否被删除的标志
public boolean getDeleted() {
return this.mDeleted;
}
}