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

109 lines
3.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; // 错误
// 节点的基本属性
private String mGid; // 唯一标识符
private String mName; // 节点名称
private long mLastModified; // 上次修改时间
private boolean mDeleted; // 是否已删除
// 构造函数,初始化节点属性
public Node() {
mGid = null; // 初始化 Gid 为 null
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();
// 抽象方法:根据 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;
}
}