From: <jrb...@us...> - 2009-08-06 22:02:38
|
Revision: 917 http://cishell.svn.sourceforge.net/cishell/?rev=917&view=rev Author: jrbibers Date: 2009-08-06 22:02:26 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Added CollectionUtilities to CIShell utilities. Initial commit includes only a method which filters a Collection according to a Dictionary into Boolean values. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2009-08-06 22:02:26 UTC (rev 917) @@ -0,0 +1,31 @@ +package org.cishell.utilities; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Dictionary; +import java.util.Iterator; + +public class CollectionUtilities { + + /* Return only elements of the Collection which are mapped to true in the + * Dictionary + */ + public static Collection grabSelectedValues( + Collection elements, Dictionary selectionDictionary) { + Collection selectedElements = new ArrayList(); + + for (Iterator elementsIt = elements.iterator(); elementsIt.hasNext();) { + String element = (String) elementsIt.next(); + Object isSelected = selectionDictionary.get(element); + + if ((isSelected != null) && (isSelected instanceof Boolean)) { + if (((Boolean) isSelected).booleanValue()) { + selectedElements.add(element); + } + } + } + + return selectedElements; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |