I noticed that the iterators in the slides library for Java do not comply with the Java Iterator contract.
Using the following code to test it (count is how long the iterable is ):static boolean iteratorTest(Iterable<?> iterable, int count) {
java.util.Iterator<?> it = iterable.iterator();
boolean lastResult = it.hasNext();
for (int i = 0; i < count; i++){
boolean result = it.hasNext();
if (result != lastResult)
return false;
}
return true;
}
At minimum, the Collections for Presentation(Ex).getSlides() and TextFrame(Ex).getParagraphs() fail that test. The ones I tested in Aspose.Cells passed. Could you please fix this on all of the Iterables in Aspose.Slides for Java?
Hi Austin,
public static void TesPres(String presName){PresentationEx pres=new PresentationEx(presName);SlideEx slide=pres.getSlides().get_Item(1);for(int i=0;i<slide.getShapes().getCount();i++){ShapeEx sha=slide.getShapes().get_Item(i);if(sha instanceof AutoShapeEx && sha.getAlternativeText().contentEquals(“FontCheck”)){AutoShapeEx shape=(AutoShapeEx)sha;if(shape.getTextFrame()!=null){TextFrameEx txt=shape.getTextFrame();ParagraphEx para=txt.getParagraphs().get_Item(2);iteratorTest(txt.getParagraphs(), txt.getParagraphs().getCount());}}}}///static boolean iteratorTest(Iterable<?> iterable, int count){java.util.Iterator<?> it = iterable.iterator();boolean lastResult = it.hasNext();for (int i = 0; i < count; i++){boolean result = it.hasNext();if (result != lastResult)return false;}return true;}
Sorry for the delayed response. I had other projects to handle…
I tested this with the 8.4.0 version and it still fails. One of the ones I use is:
PresentationEx presentation = new PresentationEx(pathToSampleFile)
assert iteratorTest(presentation.getSlides(), presentation.getSlides().size())
does that code work for you. You will need assertions turned on for it to work, or you can use
if (!iteratorTest(presentation.getSlides(), presentation.getSlides().size()))
throw new AssertionError();
Let me know how it goes.
Hi Austin,
I have worked over the scenario shared by you and have been able to reproduce the issue on my end. I have created an issue with ID SLIDESJAVA-34317 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved. For the time being, I have developed the following work around approach for your that you may use on your end.
static boolean iteratorTest(Iterable<?> iterable, int count)
{
java.util.Iterator<?> it = iterable.iterator();
boolean lastResult = false;
if(count==1)
{
lastResult = it.hasNext();
return lastResult;
}
else
{
lastResult = it.hasNext();
for (int i = 0; i < count-1; i++)
{
boolean result = it.hasNext();
if (result != lastResult)
return false;
}
return true;
}
}
Many Thanks,