Filtering out specific objects from a search query in Alfresco using Java
- by Snowright
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);
}
}