org.lsc.utils
Class SetUtils

java.lang.Object
  extended by org.lsc.utils.SetUtils

public class SetUtils
extends Object

Utility class offering various methods to manipulate and search in Lists.

Author:
Jonathan Clarke <jonathan@phillipoux.net>

Method Summary
static void addAllIfNotPresent(Set<Object> set, Set<?> values)
           
static Set<Object> attributeToSet(Attribute attr)
          Return a new HashSet containing all the Objects that are an Attribute's values.
static boolean doSetsMatch(Set<Object> srcAttrValues, Set<Object> dstAttrValues)
          Compare two lists of values to see if they contain the same values.
static Set<?> findMissingNeedles(Set<?> haystack, Set<?> needles)
          Find missing needles from a haystack.
static boolean setContainsAll(Set<Object> haystack, Set<Object> needles)
          Check to make sure all needles are in the haystack.
static Attribute setToAttribute(String attrName, Set<?> values)
          Return an Attribute containing all the Objects that are in a Set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

attributeToSet

public static Set<Object> attributeToSet(Attribute attr)
                                  throws NamingException
Return a new HashSet containing all the Objects that are an Attribute's values.

Parameters:
attr - An Attribute containing values to extract.
Returns:
HashSet Values as a set. Never null.
Throws:
NamingException

setToAttribute

public static Attribute setToAttribute(String attrName,
                                       Set<?> values)
Return an Attribute containing all the Objects that are in a Set.

Parameters:
attrName - The name of the attribute to return
values - Values as a set
Returns:
Attribute An Attribute containing values from the set. Never null.

findMissingNeedles

public static Set<?> findMissingNeedles(Set<?> haystack,
                                        Set<?> needles)
Find missing needles from a haystack. In other words, identify values in the set of needles that are not in the haystack, and return them in a new Set. This method is type-aware and will intelligently compare byte[], String, etc.

Parameters:
haystack - Set of Objects to find the needles in.
needles - Set of Objects to search for in the haystack.
Returns:
Set of needles that are not in the haystack.

setContainsAll

public static boolean setContainsAll(Set<Object> haystack,
                                     Set<Object> needles)
Check to make sure all needles are in the haystack. In other words each value from the set needles must be in the set haystack. This method is type-aware and will intelligently compare byte[], String, etc.

Parameters:
haystack - Set of Objects to find the needles in.
needles - Set of Objects to search for in the haystack.
Returns:
true if all the members of needles are found in haystack

doSetsMatch

public static boolean doSetsMatch(Set<Object> srcAttrValues,
                                  Set<Object> dstAttrValues)
Compare two lists of values to see if they contain the same values. This method is type-aware and will intelligently compare byte[], String, etc.

Parameters:
srcAttrValues -
dstAttrValues -
Returns:
true if all values of each set are present in the other set, false otherwise

addAllIfNotPresent

public static void addAllIfNotPresent(Set<Object> set,
                                      Set<?> values)


Copyright © 2005-2010 LSC project. All Rights Reserved.