Commit d5ac3c3f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More optimization work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3743 b35dd754-fafc-0310-a699-88a17e54d16e
parent e1a499ca
...@@ -202,10 +202,7 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -202,10 +202,7 @@ public class RosterManager extends BasicModule implements GroupEventListener {
*/ */
private Collection<Group> parseGroups(String groupNames) { private Collection<Group> parseGroups(String groupNames) {
Collection<Group> answer = new HashSet<Group>(); Collection<Group> answer = new HashSet<Group>();
if (groupNames != null) { for (String groupName : parseGroupNames(groupNames)) {
StringTokenizer tokenizer = new StringTokenizer(groupNames, ",");
while (tokenizer.hasMoreTokens()) {
String groupName = tokenizer.nextToken();
try { try {
answer.add(GroupManager.getInstance().getGroup(groupName)); answer.add(GroupManager.getInstance().getGroup(groupName));
} }
...@@ -213,6 +210,24 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -213,6 +210,24 @@ public class RosterManager extends BasicModule implements GroupEventListener {
// Do nothing. Silently ignore the invalid reference to the group // Do nothing. Silently ignore the invalid reference to the group
} }
} }
return answer;
}
/**
* Returns a collection of Groups obtained by parsing a comma delimited String with the name
* of groups.
*
* @param groupNames a comma delimited string with group names.
* @return a collection of Groups obtained by parsing a comma delimited String with the name
* of groups.
*/
private Collection<String> parseGroupNames(String groupNames) {
Collection<String> answer = new HashSet<String>();
if (groupNames != null) {
StringTokenizer tokenizer = new StringTokenizer(groupNames, ",");
while (tokenizer.hasMoreTokens()) {
answer.add(tokenizer.nextToken());
}
} }
return answer; return answer;
} }
...@@ -362,9 +377,14 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -362,9 +377,14 @@ public class RosterManager extends BasicModule implements GroupEventListener {
if ("everybody".equals(showInRoster)) { if ("everybody".equals(showInRoster)) {
return true; return true;
} }
if ("onlyGroup".equals(showInRoster) ) { if ("onlyGroup".equals(showInRoster) && !groups.isEmpty()) {
Collection<Group> visibleGroups = parseGroups(properties.get("sharedRoster.groupList")); Collection<String> groupNames = new ArrayList<String>(groups.size());
return !Collections.disjoint(visibleGroups, groups); for (Group group : groups) {
groupNames.add(group.getName());
}
Collection<String> visibleGroups =
parseGroupNames(properties.get("sharedRoster.groupList"));
return !Collections.disjoint(visibleGroups, groupNames);
} }
return false; return false;
} }
...@@ -606,9 +626,9 @@ public class RosterManager extends BasicModule implements GroupEventListener { ...@@ -606,9 +626,9 @@ public class RosterManager extends BasicModule implements GroupEventListener {
String showInRoster = group.getProperties().get("sharedRoster.showInRoster"); String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if ("onlyGroup".equals(showInRoster)) { if ("onlyGroup".equals(showInRoster)) {
// Check if the user belongs to a group that may see this group // Check if the user belongs to a group that may see this group
Collection<Group> groupList = parseGroups(group.getProperties().get( Collection<String> groupList =
"sharedRoster.groupList")); parseGroupNames(group.getProperties().get("sharedRoster.groupList"));
if (groupList.contains(groupToCheck)) { if (groupList.contains(groupToCheck.getName())) {
answer.add(group); answer.add(group);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment