Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iterators for NameTree and NumberTree #623

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading