We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Iterable issue

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,


I have tried to reproduce the issue on my end using following sample code on my end by using Aspose.Slides for Java 8.4.0. I have not been able to reproduce the issue. Can you please share that what issue you are incurring and what is the output you are getting using Aspose.Slides. Please also share that what is the expected output on your end. Please share some more details about the issue along with working sample and presentation so that I may help you better in this regard.

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;
}

Many Thanks,

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,