Filtering out specific objects from a search query in Alfresco using Java
Posted
by Snowright
on Stack Overflow
See other posts from Stack Overflow
or by Snowright
Published on 2010-03-31T01:45:06Z
Indexed on
2010/03/31
1:53 UTC
Read the original article
Hit count: 246
I have a HashSet containing all groups I've retrieved from my database. I've been asked to filter this result by removing two specific groups. It seems trivial but I can't seem to come up with a solid solution for storing the specific groups I want to filter out.
My idea is to just create an array containing references to the two groups I need to filter out. I can then filter out my search query with whatever is in the array. My concern is that in the future they may ask to filter out more groups and maybe an array may not be a good idea.
//Creates the array containing groups to filter out
String[] hiddenGroups = {"group1","group2"};
//retrieves all groups
Set<String>allGroups = new HashSet<String>();
allGroups.addAll(authorityService.getAllAuthorities(AuthorityType.GROUP);
List<String>results = new ArrayList<String>();
//filters out specified groups
for (String group : allGroups) {
boolean isHidden = false;
for (String hiddenGroup : hiddenGroups) {
if (hiddenGroup.equalsIgnorecase(group)) {
isHidden = true;
}
}
if (!isHidden){
results.add(group);
}
}
© Stack Overflow or respective owner