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.
rass/gtask/data/Node.java

114 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.
*/
package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
// 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;
// 用于存储节点的唯一标识符可能是全局唯一的具体取决于业务场景初始化为null
private String mGid;
// 用于存储节点的名称,初始化为空字符串
private String mName;
// 用于记录节点最后一次被修改的时间戳初始化为0
private long mLastModified;
// 用于标记该节点是否已被删除初始化为false
private boolean mDeleted;
// 构造函数在创建Node对象时初始化各个属性的默认值
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
// 抽象方法用于获取创建操作对应的JSONObject具体的创建操作逻辑由继承该抽象类的具体子类去实现参数actionId可能用于指定具体的创建操作类型等细节
public abstract JSONObject getCreateAction(int actionId);
// 抽象方法用于获取更新操作对应的JSONObject同样具体更新操作逻辑由子类实现参数actionId用于细化更新操作的相关情况
public abstract JSONObject getUpdateAction(int actionId);
// 抽象方法根据远程的JSON对象来设置该节点的内容子类需要根据实际情况解析JSON并正确设置自身的相关属性
public abstract void setContentByRemoteJSON(JSONObject js);
// 抽象方法根据本地的JSON对象来设置该节点的内容与上述设置远程JSON内容的方法类似由子类去具体实现相应逻辑
public abstract void setContentByLocalJSON(JSONObject js);
// 抽象方法从该节点的内容中获取本地JSON表示形式也就是将节点自身的属性等信息转换为JSONObject返回由子类实现具体转换逻辑
public abstract JSONObject getLocalJSONFromContent();
// 抽象方法根据给定的数据库游标Cursor来获取该节点对应的同步操作类型具体如何根据游标内容判断同步操作由子类确定
public abstract int getSyncAction(Cursor c);
// 设置节点的唯一标识符Gid的方法
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;
}
// 获取节点唯一标识符Gid的方法
public String getGid() {
return this.mGid;
}
// 获取节点名称的方法
public String getName() {
return this.mName;
}
// 获取节点最后修改时间戳的方法
public long getLastModified() {
return this.mLastModified;
}
// 获取节点是否被删除状态的方法
public boolean getDeleted() {
return this.mDeleted;
}
}