Author: adrianc
Date: Wed Jul 15 22:06:12 2009 New Revision: 794432 URL: http://svn.apache.org/viewvc?rev=794432&view=rev Log: Better implementation of my previous commit. Eliminated EntityListIterator warnings. Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java?rev=794432&r1=794431&r2=794432&view=diff ============================================================================== --- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java (original) +++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java Wed Jul 15 22:06:12 2009 @@ -1019,11 +1019,20 @@ } public static Map<String, Object> removeDuplicateWorkEfforts(DispatchContext ctx, Map<String, ? extends Object> context) { - Map<String, Object> result = ServiceUtil.returnSuccess(); List<GenericValue> resultList = null; EntityListIterator eli = (EntityListIterator) context.get("workEffortIterator"); if (eli != null) { - resultList = WorkEffortWorker.removeDuplicateWorkEfforts(eli); + Set<String> keys = FastSet.newInstance(); + resultList = FastList.newInstance(); + GenericValue workEffort = eli.next(); + while (workEffort != null) { + String workEffortId = workEffort.getString("workEffortId"); + if (!keys.contains(workEffortId)) { + resultList.add(workEffort); + keys.add(workEffortId); + } + workEffort = eli.next(); + } try { eli.close(); } catch (Exception e) { @@ -1035,6 +1044,7 @@ resultList = WorkEffortWorker.removeDuplicateWorkEfforts(workEfforts); } } + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("workEfforts", resultList); return result; } Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java?rev=794432&r1=794431&r2=794432&view=diff ============================================================================== --- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java (original) +++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java Wed Jul 15 22:06:12 2009 @@ -20,7 +20,6 @@ package org.ofbiz.workeffort.workeffort; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -202,20 +201,17 @@ } public static List<GenericValue> removeDuplicateWorkEfforts(List<GenericValue> workEfforts) { - return removeDuplicateWorkEfforts(workEfforts.iterator()); - } - - public static List<GenericValue> removeDuplicateWorkEfforts(Iterator<GenericValue> workEfforts) { Set<String> keys = FastSet.newInstance(); - List<GenericValue> resultList = FastList.newInstance(); - while (workEfforts.hasNext()) { - GenericValue workEffort = workEfforts.next(); + Set<GenericValue> exclusions = FastSet.newInstance(); + for (GenericValue workEffort : workEfforts) { String workEffortId = workEffort.getString("workEffortId"); - if (!keys.contains(workEffortId)) { - resultList.add(workEffort); + if (keys.contains(workEffortId)) { + exclusions.add(workEffort); + } else { keys.add(workEffortId); } } - return resultList; + workEfforts.removeAll(exclusions); + return workEfforts; } } |
Free forum by Nabble | Edit this page |