本文整理汇总了Java中org.javarosa.core.util.DAG类的典型用法代码示例。如果您正苦于以下问题:Java DAG类的具体用法?Java DAG怎么用?Java DAG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DAG类属于org.javarosa.core.util包,在下文中一共展示了DAG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: propagateMarkToDAG
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Propogates the provided mark in a chain from all nodes which meet the mask to all of their
* neighboring nodes, as long as those nodes meet the relationship provided. If the relationship
* is null, only the mask is checked.
*
* @param dag
* @param walkFromSourceToSink If true, start at sources (nodes with only outgoing edges), and walk edges
* from parent to child. If false, start at sinks (nodes with only incoming edges)
* and walk from child to parent
* @param maskCondition A mask for what nodes meet the criteria of being marked in the walk.
* @param markToApply A new binary flag (or set of flags) to apply to all nodes meeting the criteria
* @param relationship If non-null, an additional criteria for whether a node should be marked.
* A node will only be marked if the edge walked to put it on the stack
* meets this criteria.
*/
private static void propagateMarkToDAG(DAG<String, int[], String> dag, boolean walkFromSourceToSink,
int maskCondition, int markToApply, String relationship,
boolean requireOpenDestination) {
Stack<String> toProcess = walkFromSourceToSink ? dag.getSources() : dag.getSinks();
while (!toProcess.isEmpty()) {
// current node
String index = toProcess.pop();
int[] node = dag.getNode(index);
Vector<Edge<String, String>> edgeSet = walkFromSourceToSink ? dag.getChildren(index) :
dag.getParents(index);
for (Edge<String, String> edge : edgeSet) {
if (caseStatusIs(node[0], maskCondition) && (relationship == null || edge.e.equals(relationship))) {
if(!requireOpenDestination || caseStatusIs(dag.getNode(edge.i)[0], STATUS_OPEN)) {
dag.getNode(edge.i)[0] |= markToApply;
}
}
toProcess.addElement(edge.i);
}
}
}
示例2: setIdsToRemoveWithNewExtensions
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private void setIdsToRemoveWithNewExtensions(DAG<String, int[], String> graph) {
internalCaseDAG = graph;
// It is important that actual edge removal be done after the call to getInvalidEdges() is
// complete, to prevent a ConcurrentModificationException
Vector<String[]> edgesToRemove = getInvalidEdges();
for (String[] edge : edgesToRemove) {
internalCaseDAG.removeEdge(edge[0], edge[1]);
}
propagateRelevance(internalCaseDAG);
propagateAvailabile(internalCaseDAG);
propagateLive(internalCaseDAG);
// Ok, so now just go through all nodes and signal that we need to remove anything
// that isn't live!
for (Enumeration iterator = internalCaseDAG.getNodes(); iterator.hasMoreElements(); ) {
int[] node = (int[])iterator.nextElement();
if (!caseStatusIs(node[0], STATUS_ALIVE)) {
idsToRemove.addElement(new Integer(node[1]));
}
}
}
示例3: propagateMarkToDAG
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Propogates the provided mark in a chain from all nodes which meet the mask to all of their
* neighboring nodes, as long as those nodes meet the relationship provided. If the relationship
* is null, only the mask is checked.
*
* @param walkFromSourceToSink If true, start at sources (nodes with only outgoing edges), and walk edges
* from parent to child. If false, start at sinks (nodes with only incoming edges)
* and walk from child to parent
* @param maskCondition A mask for what nodes meet the criteria of being marked in the walk.
* @param markToApply A new binary flag (or set of flags) to apply to all nodes meeting the criteria
* @param relationship If non-null, an additional criteria for whether a node should be marked.
* A node will only be marked if the edge walked to put it on the stack
* meets this criteria.
*/
private static void propagateMarkToDAG(DAG<String, int[], String> dag, boolean walkFromSourceToSink,
int maskCondition, int markToApply, String relationship,
boolean requireOpenDestination) {
Stack<String> toProcess = walkFromSourceToSink ? dag.getSources() : dag.getSinks();
while (!toProcess.isEmpty()) {
// current node
String index = toProcess.pop();
int[] node = dag.getNode(index);
Vector<Edge<String, String>> edgeSet = walkFromSourceToSink ? dag.getChildren(index) :
dag.getParents(index);
for (Edge<String, String> edge : edgeSet) {
if (caseStatusIs(node[0], maskCondition) && (relationship == null || edge.e.equals(relationship))) {
if(!requireOpenDestination || caseStatusIs(dag.getNode(edge.i)[0], STATUS_OPEN)) {
dag.getNode(edge.i)[0] |= markToApply;
}
}
toProcess.addElement(edge.i);
}
}
}
示例4: testValidateCaseGraphBeforePurge_simple
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Test correct validation of a graph where 1 case indexes a non-existent node
*/
@Test
public void testValidateCaseGraphBeforePurge_simple() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_simple.xml"), sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_one");
nodesExpectedToBeLeft.add("case_two");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_two", "case_one"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_three"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例5: testValidateCaseGraphBeforePurge_complex
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Test correct validation of a graph where 2 different cases index the same non-existent node,
* and both of those cases have child nodes
*/
@Test
public void testValidateCaseGraphBeforePurge_complex() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_complex.xml"), sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_one");
nodesExpectedToBeLeft.add("case_two");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_two", "case_one"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_three"));
expectedToRemove.add(caseIdsToRecordIds.get("case_four"));
expectedToRemove.add(caseIdsToRecordIds.get("case_five"));
expectedToRemove.add(caseIdsToRecordIds.get("case_six"));
expectedToRemove.add(caseIdsToRecordIds.get("case_seven"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例6: testValidateCaseGraphBeforePurge_multipleParents
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Test correct validation of a graph where 1 case indexes 2 other cases - 1 valid and 1 that
* does not exist
*/
@Test
public void testValidateCaseGraphBeforePurge_multipleParents() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_multiple_parents.xml"),
sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
HashMap<String, Integer> caseIdsToRecordIds = createCaseIdsMap(storage);
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_two");
nodesExpectedToBeLeft.add("case_three");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_three", "case_two"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
expectedToRemove.add(caseIdsToRecordIds.get("case_one"));
expectedToRemove.add(caseIdsToRecordIds.get("case_four"));
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例7: testValidateCaseGraphBeforePurge_noRemoval
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Test correct validation of a graph where no cases index a non-existent node, so there is no
* change
*/
@Test
public void testValidateCaseGraphBeforePurge_noRemoval() throws Exception {
MockUserDataSandbox sandbox = MockDataUtils.getStaticStorage();
ParseUtils.parseIntoSandbox(this.getClass().getClassLoader().
getResourceAsStream("case_purge/validate_case_graph_test_no_change.xml"), sandbox);
IStorageUtilityIndexed<Case> storage = sandbox.getCaseStorage();
CasePurgeFilter filter = new CasePurgeFilter(storage);
Set<String> nodesExpectedToBeLeft = new HashSet<>();
nodesExpectedToBeLeft.add("case_one");
nodesExpectedToBeLeft.add("case_two");
nodesExpectedToBeLeft.add("case_three");
nodesExpectedToBeLeft.add("case_four");
Set<String[]> edgesExpectedToBeLeft = new HashSet<>();
edgesExpectedToBeLeft.add(new String[]{"case_two", "case_one"});
// Check that the edges and nodes still present in the graph are as expected
DAG<String, int[], String> internalCaseGraph = filter.getInternalCaseGraph();
checkProperNodesPresent(nodesExpectedToBeLeft, internalCaseGraph);
checkProperEdgesPresent(edgesExpectedToBeLeft, internalCaseGraph);
// Check that the correct cases (none in this case) were actually purged
Vector<Integer> expectedToRemove = new Vector<>();
Vector<Integer> removed = storage.removeAll(filter);
checkProperCasesRemoved(expectedToRemove, removed);
}
示例8: checkProperEdgesPresent
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Check that the set of edges we expect to still be in the case DAG is identical to the
* edges actually there
*/
private static void checkProperEdgesPresent(Set<String[]> edgesExpected,
DAG<String, int[], String> graph) {
Set<String[]> edgesActuallyLeft = getSimpleFormEdges(graph.getEdges());
for (String[] expected : edgesExpected) {
Assert.assertTrue(checkContainsThisEdge(edgesActuallyLeft, expected));
}
for (String[] actual : edgesActuallyLeft) {
Assert.assertTrue(checkContainsThisEdge(edgesExpected, actual));
}
}
示例9: getSimpleFormEdges
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private static Set<String[]> getSimpleFormEdges(
Hashtable<String, Vector<DAG.Edge<String, String>>> edges) {
Set<String[]> simpleFormEdges = new HashSet<>();
for (String sourceIndex : edges.keySet()) {
Vector<DAG.Edge<String, String>> edgesFromSource = edges.get(sourceIndex);
for (DAG.Edge<String, String> edge : edgesFromSource) {
simpleFormEdges.add(new String[]{sourceIndex, edge.i});
}
}
return simpleFormEdges;
}
示例10: propagateAvailabile
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private static void propagateAvailabile(DAG<String, int[], String> g) {
for (Enumeration e = g.getIndices(); e.hasMoreElements(); ) {
String index = (String)e.nextElement();
int[] node = g.getNode(index);
if (caseStatusIs(node[0], STATUS_OPEN | STATUS_RELEVANT) &&
!hasOutgoingExtension(g, index)) {
node[0] |= STATUS_AVAILABLE;
}
}
propagateMarkToDAG(g, false, STATUS_AVAILABLE, STATUS_AVAILABLE, CaseIndex.RELATIONSHIP_EXTENSION, true);
}
示例11: hasOutgoingExtension
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private static boolean hasOutgoingExtension(DAG<String, int[], String> g, String index) {
for (Edge<String, String> edge : g.getChildren(index)) {
if (edge.e.equals(CaseIndex.RELATIONSHIP_EXTENSION)) {
return true;
}
}
return false;
}
示例12: propagateLive
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private static void propagateLive(DAG<String, int[], String> g) {
for (Enumeration e = g.getIndices(); e.hasMoreElements(); ) {
String index = (String)e.nextElement();
int[] node = g.getNode(index);
if (caseStatusIs(node[0], STATUS_OWNED | STATUS_RELEVANT | STATUS_AVAILABLE)) {
node[0] |= STATUS_ALIVE;
}
}
propagateMarkToDAG(g, true, STATUS_ALIVE, STATUS_ALIVE);
propagateMarkToDAG(g, false, STATUS_ALIVE, STATUS_ALIVE, CaseIndex.RELATIONSHIP_EXTENSION, true);
}
示例13: checkProperNodesPresent
import org.javarosa.core.util.DAG; //导入依赖的package包/类
/**
* Check that the set of nodes we expect to still be in the case DAG is identical to the
* nodes actually there
*/
private static void checkProperNodesPresent(Set<String> nodesExpected,
DAG<String, int[], String> graph) {
Set<String> nodesActuallyLeft = getSimpleFormNodes(graph.getIndices());
Assert.assertTrue(nodesExpected.equals(nodesActuallyLeft));
}
示例14: propagateRelevance
import org.javarosa.core.util.DAG; //导入依赖的package包/类
private static void propagateRelevance(DAG<String, int[], String> g) {
propagateMarkToDAG(g, true, STATUS_RELEVANT, STATUS_RELEVANT);
propagateMarkToDAG(g, false, STATUS_RELEVANT, STATUS_RELEVANT, CaseIndex.RELATIONSHIP_EXTENSION, false);
}
示例15: getInternalCaseGraph
import org.javarosa.core.util.DAG; //导入依赖的package包/类
public DAG<String, int[], String> getInternalCaseGraph() {
return internalCaseDAG;
}