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;
}
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;
}
}
}
}
}
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;
}
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;
}
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;
}
Aggregations