|
|
|
|
@ -31,11 +31,11 @@ import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TaskList extends Node {
|
|
|
|
|
private static final String TAG = TaskList.class.getSimpleName();
|
|
|
|
|
private static final String TAG = TaskList.class.getSimpleName();//tag标记
|
|
|
|
|
|
|
|
|
|
private int mIndex;
|
|
|
|
|
private int mIndex;//当前TaskList的指针
|
|
|
|
|
|
|
|
|
|
private ArrayList<Task> mChildren;
|
|
|
|
|
private ArrayList<Task> mChildren;//类中主要保存数据的单元,用来实现一个以Task为元素的ArrayList
|
|
|
|
|
|
|
|
|
|
public TaskList() {
|
|
|
|
|
super();
|
|
|
|
|
@ -43,6 +43,9 @@ public class TaskList extends Node {
|
|
|
|
|
mIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
生成并返回一个包含了一定数据的JSONObject实体
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject getCreateAction(int actionId) {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
@ -58,7 +61,7 @@ public class TaskList extends Node {
|
|
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
|
|
|
|
|
|
|
|
|
|
// entity_delta
|
|
|
|
|
JSONObject entity = new JSONObject();
|
|
|
|
|
JSONObject entity = new JSONObject();//entity实体
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
|
|
|
|
|
@ -74,6 +77,9 @@ public class TaskList extends Node {
|
|
|
|
|
return js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
生成并返回一个包含了一定数据的JSONObject实体
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject getUpdateAction(int actionId) {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
@ -229,11 +235,16 @@ public class TaskList extends Node {
|
|
|
|
|
task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
|
|
|
|
|
.get(mChildren.size() - 1));
|
|
|
|
|
task.setParent(this);
|
|
|
|
|
//注意:每一次ArrayList的变化都要紧跟相关Task中PriorSibling的更改
|
|
|
|
|
//接下来几个函数都有相关操作
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:在当前任务表的指定位置添加新的任务
|
|
|
|
|
*/
|
|
|
|
|
public boolean addChildTask(Task task, int index) {
|
|
|
|
|
if (index < 0 || index > mChildren.size()) {
|
|
|
|
|
Log.e(TAG, "add child task: invalid index");
|
|
|
|
|
@ -260,6 +271,9 @@ public class TaskList extends Node {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:删除TaskList中的一个task
|
|
|
|
|
*/
|
|
|
|
|
public boolean removeChildTask(Task task) {
|
|
|
|
|
boolean ret = false;
|
|
|
|
|
int index = mChildren.indexOf(task);
|
|
|
|
|
@ -281,6 +295,9 @@ public class TaskList extends Node {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:将单签TaskList中含有的某个Task移到index位置
|
|
|
|
|
*/
|
|
|
|
|
public boolean moveChildTask(Task task, int index) {
|
|
|
|
|
|
|
|
|
|
if (index < 0 || index >= mChildren.size()) {
|
|
|
|
|
@ -297,8 +314,12 @@ public class TaskList extends Node {
|
|
|
|
|
if (pos == index)
|
|
|
|
|
return true;
|
|
|
|
|
return (removeChildTask(task) && addChildTask(task, index));
|
|
|
|
|
//利用已经实现好的功能完成当下功能
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:按gid寻找Task
|
|
|
|
|
*/
|
|
|
|
|
public Task findChildTaskByGid(String gid) {
|
|
|
|
|
for (int i = 0; i < mChildren.size(); i++) {
|
|
|
|
|
Task t = mChildren.get(i);
|
|
|
|
|
@ -309,10 +330,16 @@ public class TaskList extends Node {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:返回指定Task的index
|
|
|
|
|
*/
|
|
|
|
|
public int getChildTaskIndex(Task task) {
|
|
|
|
|
return mChildren.indexOf(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:返回指定index的Task
|
|
|
|
|
*/
|
|
|
|
|
public Task getChildTaskByIndex(int index) {
|
|
|
|
|
if (index < 0 || index >= mChildren.size()) {
|
|
|
|
|
Log.e(TAG, "getTaskByIndex: invalid index");
|
|
|
|
|
@ -321,8 +348,11 @@ public class TaskList extends Node {
|
|
|
|
|
return mChildren.get(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
功能:返回指定gid的Task
|
|
|
|
|
*/
|
|
|
|
|
public Task getChilTaskByGid(String gid) {
|
|
|
|
|
for (Task task : mChildren) {
|
|
|
|
|
for (Task task : mChildren) {//一种常见的ArrayList的遍历算法(四种)
|
|
|
|
|
if (task.getGid().equals(gid))
|
|
|
|
|
return task;
|
|
|
|
|
}
|
|
|
|
|
|