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.
xiaomi_notes_reading/src/notes/gtask/data/Node.java

114 lines
3.4 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;
//无参构造法创建Node对象时无需传入任何参数
public Node() {
mGid = null; //常由云端生成
mName = ""; //不初始化为null避免后续调用mName.length等方法时触发空指针异常
mLastModified = 0;
mDeleted = false;
}
//JSONObject是JSON实例的抽象类生成同步创建操作JSON数据返回操作ID
public abstract JSONObject getCreateAction(int actionId);
//生成同步更新操作的JSON数据返回操作ID
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();
//通过游标获取同步操作类型在前面声明为类型变量0-8
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;
}
}