Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 28, 2024
1 parent 19fece0 commit adaaa1f
Show file tree
Hide file tree
Showing 19 changed files with 2,007 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;

Expand Down Expand Up @@ -459,12 +460,42 @@ private void setHasChanged() {
}

@Override
public boolean containsPrecedingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
public @Nullable NodeProxy containsPrecedingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public boolean containsFollowingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
public @Nullable NodeProxy containsFollowingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> precedingSiblingsOf(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> precedingSiblingsOfReverse(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> precedingSiblingsOf(final DocumentImpl doc, final NodeId nodeId, final NodeRangeIterator it) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> followingSiblingsOf(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> followingSiblingsOfReverse(final DocumentImpl doc, final NodeId nodeId) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

@Override
public Iterator<NodeProxy> followingSiblingsOf(final DocumentImpl doc, final NodeId nodeId, final NodeRangeIterator it) {
throw new UnsupportedOperationException("TODO(AR) do we need to implement this?");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void add(final NodeProxy proxy, final int sizeHint) {

addInternal(proxy, sizeHint);

this.isSorted = false;
this.isSorted = false; // TODO(AR) make this more intelligent by comparing the entry we are adding with the last entry added; if they are added in order we don't need to sort them! Then also apply that approach to other NodeSet implementations
setHasChanged();
checkItemType(proxy.getType());
this.lastAdded = proxy;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2014, Evolved Binary Ltd
*
* This file was originally ported from FusionDB to eXist-db by
* Evolved Binary, for the benefit of the eXist-db Open Source community.
* Only the ported code as it appears in this file, at the time that
* it was contributed to eXist-db, was re-licensed under The GNU
* Lesser General Public License v2.1 only for use in eXist-db.
*
* This license grant applies only to a snapshot of the code as it
* appeared when ported, it does not offer or infer any rights to either
* updates of this source code or access to the original source code.
*
* The GNU Lesser General Public License v2.1 only license follows.
*
* ---------------------------------------------------------------------
*
* Copyright (C) 2014, Evolved Binary Ltd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.dom.persistent;

import javax.annotation.Nullable;
import java.util.NoSuchElementException;

/**
* Iterate backward over a range of nodes.
*
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
*/
public class BackwardNodeRangeIterator implements NodeRangeIterator {
@Nullable private NodeProxy[] nodes;
private int idx;
private int startIdx;

public BackwardNodeRangeIterator() {
this.nodes = null;
this.idx = -1;
this.startIdx = 0;
}

/**
* @param nodes the nodes array.
* @param startIdx the starting index within {@link #nodes}.
* @param endIdx the ending index within {@link #nodes}.
*/
public BackwardNodeRangeIterator(final NodeProxy[] nodes, final int startIdx, final int endIdx) {
this.nodes = nodes;
this.startIdx = startIdx;
this.idx = endIdx;
}

@Override
public boolean hasNext() {
return idx >= startIdx;
}

@Override
public NodeProxy next() {
if (!hasNext() || nodes == null) {
throw new NoSuchElementException();
}
return nodes[idx--];
}

@Override
public void reset(final NodeProxy[] nodes, final int startIdx, final int endIdx) {
this.nodes = nodes;
this.startIdx = startIdx;
this.idx = endIdx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.exist.xquery.value.SequenceIterator;
import org.w3c.dom.Node;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;

Expand Down Expand Up @@ -109,13 +111,43 @@ public NodeProxy parentWithChild(final DocumentImpl doc, final NodeId nodeId,
}

@Override
public boolean containsPrecedingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
return false;
public @Nullable NodeProxy containsPrecedingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
return null;
}

@Override
public boolean containsFollowingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
return false;
public @Nullable NodeProxy containsFollowingSiblingOf(final DocumentImpl doc, final NodeId nodeId) {
return null;
}

@Override
public Iterator<NodeProxy> precedingSiblingsOf(final DocumentImpl doc, final NodeId nodeId) {
return Collections.emptyIterator();
}

@Override
public Iterator<NodeProxy> precedingSiblingsOfReverse(final DocumentImpl doc, final NodeId nodeId) {
return Collections.emptyIterator();
}

@Override
public Iterator<NodeProxy> precedingSiblingsOf(final DocumentImpl doc, final NodeId nodeId, final NodeRangeIterator it) {
return Collections.emptyIterator();
}

@Override
public Iterator<NodeProxy> followingSiblingsOf(final DocumentImpl doc, final NodeId nodeId) {
return Collections.emptyIterator();
}

@Override
public Iterator<NodeProxy> followingSiblingsOfReverse(final DocumentImpl doc, final NodeId nodeId) {
return Collections.emptyIterator();
}

@Override
public Iterator<NodeProxy> followingSiblingsOf(final DocumentImpl doc, final NodeId nodeId, final NodeRangeIterator it) {
return Collections.emptyIterator();
}

@Override
Expand Down
Loading

0 comments on commit adaaa1f

Please sign in to comment.