📄 process.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package eti.bi.alphaminer.vo;
import java.util.Vector;
/**
* Process is a class storing all connections of a case.
*/
public class Process {
/**
* A Vector storing all Connection.
*/
private Vector<NodeConnection> m_ConnectionList;
/**
* Constructs a Process.
*/
public Process() {
m_ConnectionList = new Vector<NodeConnection>();
}
/**
* Returns a Vector containing all Connections.
* @return Vector of Connections.
*/
public Vector<NodeConnection> getConnectionList() {
return m_ConnectionList;
}
/**
* Sets the Vector of Connections.
* @param a_List the Vector containing all Connections.
*/
public void setConnectionList(Vector<NodeConnection> a_List) {
m_ConnectionList = a_List;
}
/**
* Gets tail nodes that are connected to the head node.
* @param a_NodeID ID of the head node.
* @return Vector storing ID of tail nodes.
*/
public Vector<String> getChildrenOfNode(String a_NodeID) {
Vector<String> children = new Vector<String>();
NodeConnection con = null;
for (int i = 0; i < m_ConnectionList.size(); i++) {
con = m_ConnectionList.elementAt(i);
if (con.getHeadNodeID().equals(a_NodeID))
children.addElement(con.getTailNodeID());
}
return children;
}
/**
* Returns number of tail nodes that are connected to the head node.
* @param a_NodeID ID of the head node.
* @return number of tail nodes.
*/
public int getNumberOfChildrenOfNode(String a_NodeID)
{
Vector<String> children = getChildrenOfNode(a_NodeID);
if (children==null)
return 0;
else
return children.size();
}
/**
* Gets head nodes that are connected to the tail node.
* @param a_NodeID ID of the tail node.
* @return Vector storing ID of head nodes.
*/
public Vector<String> getParentsOfNode(String a_NodeID) {
Vector<String> parents = new Vector<String>();
NodeConnection con = null;
for (int i = 0; i < m_ConnectionList.size(); i++) {
con = m_ConnectionList.elementAt(i);
if (con.getTailNodeID().equals(a_NodeID))
parents.addElement(con.getHeadNodeID());
}
return parents;
}
/**
* Returns number of head nodes that are connected to the tail node.
* @param a_NodeID ID of the tail node.
* @return number of head nodes.
*/
public int getNumberOfParentsOfNode(String a_NodeID)
{
Vector<String> parents = getParentsOfNode(a_NodeID);
if (parents==null)
return 0;
else
return parents.size();
}
/**
* Inserts a Connection between a head node and a tail node in this case.
* @param a_HeadNodeID ID of the head node.
* @param a_TailNodeID ID of the tail node.
* @return true if Connection is aded successfully; false otherwise.
*/
public boolean insertConnection(String a_HeadNodeID, int a_HeadChildrenNum, String a_TailNodeID, int a_TailParentsNum) {
if (isConnectionExisted(a_HeadNodeID, a_TailNodeID))
return false;
if (isCyclic(a_HeadNodeID, a_TailNodeID))
return false;
if (getNumberOfChildrenOfNode(a_HeadNodeID)>=a_HeadChildrenNum)
return false;
if (getNumberOfParentsOfNode(a_TailNodeID)>=a_TailParentsNum)
return false;
m_ConnectionList.addElement(new NodeConnection(a_HeadNodeID, a_TailNodeID));
printDebug();
return true;
}
/**
* Remove connections connecting to two nodes.
* @param a_HeadNodeID ID of the parent node of the connection.
* @param a_TailNodeID ID of the tail node of the connection.
*/
public void removeConnectionBetweenNodes(
String a_HeadNodeID,
String a_TailNodeID) {
NodeConnection existingCon = null;
NodeConnection con = new NodeConnection(a_HeadNodeID, a_TailNodeID);
for (int i = 0; i < m_ConnectionList.size(); i++) {
existingCon = m_ConnectionList.elementAt(i);
if (existingCon.equals(con)) {
m_ConnectionList.remove(i);
break;
}
}
printDebug();
}
/**
* Remove connections connecting to a specific node.
* @param a_NodeID ID of the specified node.
*/
public void removeConnectionOfNode(String a_NodeID) {
NodeConnection existingCon = null;
for (int i = 0; i < m_ConnectionList.size(); i++) {
existingCon = m_ConnectionList.elementAt(i);
if (existingCon.containNode(a_NodeID)) {
m_ConnectionList.remove(i);
i--;
}
}
printDebug();
}
/**
* Checks if a connection between two nodes exists.
* @param a_HeadNodeID ID of the head node.
* @param a_TailNodeID ID of the tail node.
* @return true if the connection or the reverse connection of the two nodes
* exists; false otherwise.
*/
private boolean isConnectionExisted(
String a_HeadNodeID,
String a_TailNodeID) {
NodeConnection con = new NodeConnection(a_HeadNodeID, a_TailNodeID);
NodeConnection existingCon = null;
for (int i = 0; i < m_ConnectionList.size(); i++) {
existingCon = m_ConnectionList.elementAt(i);
if (existingCon.equals(con) || existingCon.equalsReverse(con))
return true;
}
return false;
}
/**
* Check if the connection between the head and the tail nodes produces a cyclic path.
* @param a_HeadNodeID ID of the head node.
* @param a_TailNodeID ID of the tail node.
* @return true if the connection causes a cyclic path; false otherwise.
*/
private boolean isCyclic(String a_HeadNodeID, String a_TailNodeID) {
Vector<String> nodes = getParentsOfNode(a_HeadNodeID);
for (int i = 0; i < nodes.size(); i++) {
if (nodes.elementAt(i).equals(a_TailNodeID))
return true;
else
return isCyclic(nodes.elementAt(i), a_TailNodeID);
}
return false;
}
private void printDebug() {
for (int i = 0; i < m_ConnectionList.size(); i++) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -