Question

Return the index of the last entry in the pagelist that the condition is satisfied for

I have a PageList that contains several pages. I need to identify the index in the last entry in the pagelist that the given conditions are satisfied. There are two out of the box functions that return the first entry for the given condition (eg. IndexInPageList, IndexInPageList) but the requirement is to return the last index in the pagelist for the given conditions satisfied.

Thank you in Advance.

Correct Answer
December 2, 2018 - 4:53pm

Hi, You could write a new function to return the last index if found otherwise it will return -1:

  1. int retValue = -1;
  2. Iterator it = lookIn.iterator();
  3. while (it.hasNext()) {
  4. ClipboardProperty next = (ClipboardProperty) it.next();
  5. ClipboardPage nextPage = next.getPageValue();
  6. ClipboardProperty prop = nextPage.getIfPresent(lookAt);
  7. if (prop != null)
  8. {
  9. if (prop.getStringValue().equals(lookFor)) {
  10. retValue = next.indexOf();
  11. }
  12. }
  13. }
  14. return retValue;

Parameters for the above function would be:

lookFor: value to look for

lookAt: property name to look at

lookIn: pagelist to look in

This is similar to what IndexInPageList does with the exception that it will not break out of loop if index is found that way you will get the last index.

Hope it helps!

 

 

Comments

Keep up to date on this post and subscribe to comments

Pega
December 2, 2018 - 4:53pm

Hi, You could write a new function to return the last index if found otherwise it will return -1:

  1. int retValue = -1;
  2. Iterator it = lookIn.iterator();
  3. while (it.hasNext()) {
  4. ClipboardProperty next = (ClipboardProperty) it.next();
  5. ClipboardPage nextPage = next.getPageValue();
  6. ClipboardProperty prop = nextPage.getIfPresent(lookAt);
  7. if (prop != null)
  8. {
  9. if (prop.getStringValue().equals(lookFor)) {
  10. retValue = next.indexOf();
  11. }
  12. }
  13. }
  14. return retValue;

Parameters for the above function would be:

lookFor: value to look for

lookAt: property name to look at

lookIn: pagelist to look in

This is similar to what IndexInPageList does with the exception that it will not break out of loop if index is found that way you will get the last index.

Hope it helps!