jquery

package xml.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import xml.util.ObjectDuplicateException;

/**
* 流程对象
*
* @author 陈伟
*
*/
public class Flow {

private String id;
private String name; // 流程名称
private String description;
private List<Node> nodes; // 当前流程下的所有节点

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public List<Node> getNodes() {
return nodes;
}

public void setNodes(List<Node> nodes) {
this.nodes = nodes;
}

public Flow(String id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}

public Flow() {
}

/**
* 查询当前流程下所有节点信息
*
* @return 当前流程所有节点信息集合
*/
public List<Node> getAllNodes() {
return getNodes();
}

/**
* 根据节点编号查询当前流程下指定节点相关信息
*
* @param nodeId
*            节点编号
* @return 指定节点信息
*/
public Node getNodeById(String nodeId) {
Node rt = null;
for (Iterator<Node> itor = getNodes().iterator(); itor.hasNext();) {
Node tempNode = itor.next();
if (tempNode.getId().equalsIgnoreCase(nodeId)) {
rt = tempNode;
break;
}
}
return rt;
}

/**
* 查询当前流程下与指定节点同名的所有节点
*
* @param nodeName
*            节点名称
* @return 与指定节点同名的所有节点信息集合
*/
public List<Node> getNodesByName(String nodeName) {
List<Node> rt = new ArrayList<Node>();
for (Iterator<Node> itor = getNodes().iterator(); itor.hasNext();) {
Node tempNode = itor.next();
if (tempNode.getName().equalsIgnoreCase(nodeName)) {
rt.add(tempNode);
}
}
return rt;
}

/**
* 在当前流程下增加新节点
*
* @param node
*            增加新的节点
* @throws ObjectDuplicateException
*/
public void addNode(Node node) throws ObjectDuplicateException {
List<Node> list = getNodes();
if (null == list) {
list = new ArrayList<Node>();
//node.setId(RandNum.getInstance().getNum(3));
}
/*
String id = "";
for (Node n : list) {
id = RandNum.getInstance().getNum(3);
if (null != n.getId() && n.getId().equals(id)) {
continue;
} else {
node.setId(id);
break;
}
}*/
for (Node n : list) {
if (n.getId().equals(node.getId())) {
throw new ObjectDuplicateException("Node id is duplicate");
}
}
list.add(node);
setNodes(list);
}

/**
* 从当前流程中删除指定编号节点信息
*
* @param nodeId
*            节点编号
* @return true删除成功 false删除失败
*/
public boolean deleteNodeById(String nodeId) {
boolean rt = false;
List<Node> list = getNodes();
for (int i = 0; i < list.size(); i++) {
Node tempNode = list.get(i);
if (tempNode.getId().equalsIgnoreCase(nodeId)) {
list.remove(i);
rt = true;
break;
}
}
return rt;
}

/**
* 更新节点信息
*
* @param node
*            新节点信息
* @return true更新成功 false更新失败
*/
public boolean updateNode(Node node) {
boolean rt = false;
for (Iterator<Node> list = getNodes().iterator(); list.hasNext();) {
Node tempNode = list.next();
if (tempNode.getId().equalsIgnoreCase(node.getId())) {
tempNode = node;
rt = true;
break;
}
}
return rt;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Flow) {
Flow f = (Flow) obj;
return f.getId().equals(getId()) ? true : false; // 编号相同即为同一流程
}
return false;
}
}

你可能感兴趣的:(jquery,xml,bean,F#)