VersionHistory - Unable to get size directly by getAllVersions.getSize() | Community
Skip to main content
Shubham_borole
Community Advisor
Community Advisor
February 21, 2020
Solved

VersionHistory - Unable to get size directly by getAllVersions.getSize()

  • February 21, 2020
  • 1 reply
  • 1990 views

Hi All,

 

Recently tried to use VersionHistory API (https://docs.adobe.com/content/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/version/VersionHistory.html) I am able to use getAllVersions() but getAllVersions().getSize() gives me -1. To get the actual size so far I am having to loop the iterator and add the count within the loop. 

 

Is there a better way or I missed something?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aemmarc2

https://docs.adobe.com/content/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()

 

Returns the total number of of items available through this iterator. For example, for some node NN.getNodes().getSize() returns the number of child nodes of N visible through the current Session. In some implementations precise information about the number of elements may not be available. In such cases this method must return -1. API clients will then be able to use RangeIterator.getNumberRemaining to get an estimate on the number of elements.

 

---

Iterators in Java don't know how many items they contain, hence why you iterate over it and count.  getAllVersions() in the VersionHistory class just returns an Iterator. It can't determine the size therefore gives you a -1. 

1 reply

aemmarc2Adobe EmployeeAccepted solution
Adobe Employee
February 21, 2020

https://docs.adobe.com/content/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/RangeIterator.html#getSize()

 

Returns the total number of of items available through this iterator. For example, for some node NN.getNodes().getSize() returns the number of child nodes of N visible through the current Session. In some implementations precise information about the number of elements may not be available. In such cases this method must return -1. API clients will then be able to use RangeIterator.getNumberRemaining to get an estimate on the number of elements.

 

---

Iterators in Java don't know how many items they contain, hence why you iterate over it and count.  getAllVersions() in the VersionHistory class just returns an Iterator. It can't determine the size therefore gives you a -1. 

Shubham_borole
Community Advisor
Community Advisor
February 21, 2020
Makes sense, thanks!!