Search in sources :

Example 1 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class AVLTreeReader method getParentKind.

@Override
public Kind getParentKind() {
    if (hasParent()) {
        if (mCurrentNode.getParentKey() == Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
            return Kind.DOCUMENT;
        } else {
            final long nodeKey = mCurrentNode.getNodeKey();
            final Kind parentKind = moveToParent().get().getKind();
            moveTo(nodeKey);
            return parentKind;
        }
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind)

Example 2 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class FMSE method match.

/**
 * Actual matching.
 *
 * @param oldLabels nodes in tree1, sorted by node type (element, attribute, text, comment, ...)
 * @param newLabels nodes in tree2, sorted by node type (element, attribute, text, comment, ...)
 * @param matching {@link Matching} reference
 * @param cmp functional class
 */
private void match(final Map<Kind, List<Long>> oldLabels, final Map<Kind, List<Long>> newLabels, final Matching matching, final Comparator<Long> cmp) {
    final Set<Kind> labels = oldLabels.keySet();
    // intersection
    labels.retainAll(newLabels.keySet());
    // 2 - for each label do
    for (final Kind label : labels) {
        // 2(a)
        final List<Long> first = oldLabels.get(label);
        // 2(b)
        final List<Long> second = newLabels.get(label);
        // 2(c)
        final List<Pair<Long, Long>> common = Util.longestCommonSubsequence(first, second, cmp);
        // Used to remove the nodes in common from s1 and s2 in step 2(e).
        final Map<Long, Boolean> seen = new HashMap<>();
        // 2(d) - for each pair of nodes in the lcs: add to matching.
        for (final Pair<Long, Long> p : common) {
            matching.add(p.getFirst(), p.getSecond());
            seen.put(p.getFirst(), true);
            seen.put(p.getSecond(), true);
        }
        // 2(e) (prepare) - remove nodes in common from s1, s2.
        removeCommonNodes(first, seen);
        removeCommonNodes(second, seen);
        // 2(e) - For each unmatched node x \in s1.
        final Iterator<Long> firstIterator = first.iterator();
        while (firstIterator.hasNext()) {
            final Long firstItem = firstIterator.next();
            boolean firstIter = true;
            // If there is an unmatched node y \in s2.
            final Iterator<Long> secondIterator = second.iterator();
            while (secondIterator.hasNext()) {
                final Long secondItem = secondIterator.next();
                // Such that equal.
                if (cmp.isEqual(firstItem, secondItem)) {
                    // 2(e)A
                    matching.add(firstItem, secondItem);
                    // 2(e)B
                    if (firstIter) {
                        firstIter = false;
                        firstIterator.remove();
                    }
                    secondIterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Kind(org.sirix.node.Kind) Pair(org.sirix.utils.Pair)

Example 3 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getRightSiblingKind.

@Override
public Kind getRightSiblingKind() {
    assertNotClosed();
    if (mCurrentNode instanceof StructNode && hasRightSibling()) {
        final long nodeKey = mCurrentNode.getNodeKey();
        moveToRightSibling();
        final Kind rightSiblKind = mCurrentNode.getKind();
        moveTo(nodeKey);
        return rightSiblKind;
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Example 4 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getFirstChildKind.

@Override
public Kind getFirstChildKind() {
    assertNotClosed();
    if (mCurrentNode instanceof StructNode && hasFirstChild()) {
        final long nodeKey = mCurrentNode.getNodeKey();
        moveToFirstChild();
        final Kind firstChildKind = mCurrentNode.getKind();
        moveTo(nodeKey);
        return firstChildKind;
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Example 5 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getLeftSiblingKind.

@Override
public Kind getLeftSiblingKind() {
    assertNotClosed();
    if (mCurrentNode instanceof StructNode && hasLeftSibling()) {
        final long nodeKey = mCurrentNode.getNodeKey();
        moveToLeftSibling();
        final Kind leftSiblKind = mCurrentNode.getKind();
        moveTo(nodeKey);
        return leftSiblKind;
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

Kind (org.sirix.node.Kind)20 PageKind (org.sirix.page.PageKind)13 StructNode (org.sirix.node.interfaces.StructNode)5 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 SirixUsageException (org.sirix.exception.SirixUsageException)2 TransactionTuple (org.sirix.gui.view.TransactionTuple)2 NameNode (org.sirix.node.interfaces.NameNode)2 NamePage (org.sirix.page.NamePage)2 HashMap (java.util.HashMap)1 Axis (org.sirix.api.Axis)1 ChildAxis (org.sirix.axis.ChildAxis)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)1 PostOrderAxis (org.sirix.axis.PostOrderAxis)1 FilterAxis (org.sirix.axis.filter.FilterAxis)1 NameFilter (org.sirix.axis.filter.NameFilter)1 PathKindFilter (org.sirix.axis.filter.PathKindFilter)1