當前位置: 首頁>>代碼示例>>Java>>正文


Java DAG類代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:38,代碼來源:CasePurgeFilter.java

示例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]));
        }
    }
}
 
開發者ID:dimagi,項目名稱:commcare-core,代碼行數:24,代碼來源:CasePurgeFilter.java

示例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);
        }
    }
}
 
開發者ID:dimagi,項目名稱:commcare-core,代碼行數:37,代碼來源:CasePurgeFilter.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:32,代碼來源:CasePurgeRegressions.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:37,代碼來源:CasePurgeRegressions.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:35,代碼來源:CasePurgeRegressions.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:33,代碼來源:CasePurgeRegressions.java

示例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));
    }
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:15,代碼來源:CasePurgeRegressions.java

示例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;
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:12,代碼來源:CasePurgeRegressions.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:12,代碼來源:CasePurgeFilter.java

示例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;
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:9,代碼來源:CasePurgeFilter.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:13,代碼來源:CasePurgeFilter.java

示例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));
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:10,代碼來源:CasePurgeRegressions.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:5,代碼來源:CasePurgeFilter.java

示例15: getInternalCaseGraph

import org.javarosa.core.util.DAG; //導入依賴的package包/類
public DAG<String, int[], String> getInternalCaseGraph() {
    return internalCaseDAG;
}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:4,代碼來源:CasePurgeFilter.java


注:本文中的org.javarosa.core.util.DAG類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。