Skip to content

Commit

Permalink
Merge pull request #623 from veraPDF/tree_iterators
Browse files Browse the repository at this point in the history
Fix iterators for NameTree and NumberTree
  • Loading branch information
MaximPlusov authored Feb 14, 2024
2 parents 53cee78 + 275c80b commit d3c34af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 84 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/verapdf/pd/PDNameTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.verapdf.cos.COSObjType;
import org.verapdf.cos.COSObject;
import org.verapdf.exceptions.LoopedException;
import org.verapdf.pd.structure.NameTreeIterator;

import java.util.*;

Expand Down Expand Up @@ -165,14 +164,22 @@ private COSObject getObject(String key, Set<COSKey> visitedKeys) {
return null;
}

private List<COSObject> getObjects() {
List<COSObject> result = new LinkedList<>(getNames().values());
for (PDNameTreeNode kid : getKids()) {
result.addAll(kid.getObjects());
}
return result;
}

@Override
public NameTreeIterator iterator() {
return new NameTreeIterator(this);
public Iterator<COSObject> iterator() {
return getObjects().iterator();
}

public Long size() {
long i = 0;
NameTreeIterator iterator = iterator();
Iterator<COSObject> iterator = iterator();
for (; iterator.hasNext(); i++) {
iterator.next();
}
Expand Down
39 changes: 0 additions & 39 deletions src/main/java/org/verapdf/pd/structure/NameTreeIterator.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/org/verapdf/pd/structure/NumberTreeIterator.java

This file was deleted.

14 changes: 11 additions & 3 deletions src/main/java/org/verapdf/pd/structure/PDNumberTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public Map<Long, COSObject> getNums() {
return Collections.emptyMap();
}

private List<COSObject> getObjects() {
List<COSObject> result = new LinkedList<>(getNums().values());
for (PDNumberTreeNode kid : getKids()) {
result.addAll(kid.getObjects());
}
return result;
}

/**
* Gets object with given key from this node and it's kids recursively.
*
Expand Down Expand Up @@ -157,13 +165,13 @@ private COSObject getObject(Long key, Set<COSKey> visitedKeys) {
}

@Override
public NumberTreeIterator iterator() {
return new NumberTreeIterator(this);
public Iterator<COSObject> iterator() {
return getObjects().iterator();
}

public Long size() {
long i = 0;
NumberTreeIterator iterator = iterator();
Iterator<COSObject> iterator = iterator();
for (; iterator.hasNext(); i++) {
iterator.next();
}
Expand Down

0 comments on commit d3c34af

Please sign in to comment.