=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/collection/CollectionUtils.java' --- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/collection/CollectionUtils.java 2015-07-15 19:25:25 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/collection/CollectionUtils.java 2015-09-22 10:47:41 +0000 @@ -238,4 +238,30 @@ return valueList; } + + /** + * Searches for and returns the first string which starts with the given + * prefix. Removes the match from the collection. + * + * @param collection the collection. + * @param prefix the string prefix. + * @return a string, or null if no matches. + */ + public static String popStartsWith( Collection collection, String prefix ) + { + Iterator iterator = collection.iterator(); + + while ( iterator.hasNext() ) + { + String element = iterator.next(); + + if ( element != null && element.startsWith( prefix ) ) + { + iterator.remove(); + return element; + } + } + + return null; + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2015-09-22 10:25:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2015-09-22 10:47:41 +0000 @@ -29,9 +29,9 @@ */ import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import org.hisp.dhis.commons.collection.CollectionUtils; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementGroup; @@ -68,20 +68,8 @@ } else { - Iterator iterator = filters.iterator(); - String deGroup = null; - - while ( iterator.hasNext() ) - { - String filter = iterator.next(); - - if ( filter.startsWith( "dataElement.dataElementGroups.id:eq:" ) ) - { - deGroup = filter.substring( "dataElement.dataElementGroups.id:eq:".length() ); - iterator.remove(); - break; - } - } + String deGroup = CollectionUtils.popStartsWith( filters, "dataElement.dataElementGroups.id:eq:" ); + deGroup = deGroup.substring( "dataElement.dataElementGroups.id:eq:".length() ); if ( deGroup != null ) {