Hello,
like in
I think I have found that the Aspose Slides for Java API breaks the contract for java.util.Iterator in the implemantation of com.aspose.slides.ISlideCollection and com.aspose.slides.IShapeCollection.
The call to .hasNext() has the side effect to progress the iterator one step further.
That should be the job of .next(), which .next() does not perform. .nect() seems to have has no sideeffects.
A call to .next() with no prior .hasNext() always returns null, even for filled collections. Which is also not as expected.
I found that behavior in Version 19.1 and 20.4.
I have some example code to demonstrate this:
// //////////////////////////////////////////////////////////////////////////////////////////////////
package de.demo;
import java.util.Iterator;
import com.aspose.slides.*;
public class App
{
public static void main( String[] args )
{
IPresentation presentation = new Presentation("folienpool.pptx");
System.out.println("First slides:");
ISlideCollection slides = presentation.getSlides();
Iterator<ISlide> slides_iter;
slides_iter= slides.iterator();
System.out.println("1. Slides: .next()-> " + slides_iter.next());
slides_iter = slides.iterator();
slides_iter.hasNext();
System.out.println("2. Slides: .hasNext() .next()-> " + slides_iter.next());
slides_iter = slides.iterator();
slides_iter.hasNext();
System.out.println("3. Slides: .hasNext() .next()-> " + slides_iter.next());
slides_iter = slides.iterator();
slides_iter.hasNext();
slides_iter.hasNext();
System.out.println("4. Slides: .hasNext() : .hasNext() .next()-> " + slides_iter.next());
slides_iter = slides.iterator();
slides_iter.hasNext();
slides_iter.next();
System.out.println("5. Slides: .hasNext() .next() .next() -> " + slides_iter.next());
System.out.println("Now Shapes:");
ISlide slide = slides.get_Item(31);
IShapeCollection shapes = slide.getShapes();
Iterator<IShape> shape_iter;
shape_iter= shapes.iterator();
System.out.println("6. Shapes: .next() -> " + shape_iter.next());
shape_iter = shapes.iterator();
shape_iter.hasNext();
System.out.println("7. Shapes: .hasNext() .next() -> " + shape_iter.next());
shape_iter = shapes.iterator();
shape_iter.hasNext();
System.out.println("8. Shapes: .hasNext() .next() -> " + shape_iter.next());
shape_iter = shapes.iterator();
shape_iter.hasNext();
shape_iter.hasNext();
System.out.println("9. Shapes: .hasNext() .hasNext() .next() -> " + shape_iter.next());
shape_iter = shapes.iterator();
shape_iter.hasNext();
shape_iter.next();
System.out.println("10. Shapes: .hasNext() .next() .next() -> " + shape_iter.next());
}
}
// //////////////////////////////////////////////////////////////////////////////////////////////////
Example output:
First slides:
- Slides: .next()-> null
- Slides: .hasNext() .next()-> com.aspose.slides.Slide@27210a3b
- Slides: .hasNext() .next()-> com.aspose.slides.Slide@27210a3b
- Slides: .hasNext() : .hasNext() .next()-> com.aspose.slides.Slide@3a12f3e7
- Slides: .hasNext() .next() .next() → com.aspose.slides.Slide@27210a3b
Now Shapes: - Shapes: .next() → null
- Shapes: .hasNext() .next() → com.aspose.slides.Table@84a9f65
- Shapes: .hasNext() .next() → com.aspose.slides.Table@84a9f65
- Shapes: .hasNext() .hasNext() .next() → com.aspose.slides.AutoShape@70700b8a
- Shapes: .hasNext() .next() .next() → com.aspose.slides.Table@84a9f65
Expectation:
What I would expect for slides is:
1 = 2 = 3 = 4 = com.aspose.slides.Slide@27210a3b
and
5 = com.aspose.slides.Slide@3a12f3e7
And for shapes:
6 = 7= 8 = 9 = com.aspose.slides.Table@84a9f65
and
10 = com.aspose.slides.AutoShape@70700b8a
Kind regards,
Uwe Hubert