TaskList.java代码注释

zy
lengjiao 3 years ago
parent 2d41757b82
commit f96d9c4fd3

@ -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;
}
/*
TaskListtask
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +295,9 @@ public class TaskList extends Node {
return ret;
}
/*
TaskListTaskindex
*/
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));
//利用已经实现好的功能完成当下功能
}
/*
gidTask
*/
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;
}
/*
Taskindex
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/*
indexTask
*/
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);
}
/*
gidTask
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
for (Task task : mChildren) {//一种常见的ArrayList的遍历算法四种
if (task.getGid().equals(gid))
return task;
}

Loading…
Cancel
Save