/* $This file is distributed under the terms of the license in /doc/license.txt$ */

package edu.cornell.mannlib.vitro.webapp.auth.identifier.common;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.Permission;
import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet;

/**
 * The current user has this Permission, through one or more PermissionSets.
 */
public class HasPermissionSet extends AbstractCommonIdentifier implements
		Identifier, Comparable<HasPermissionSet> {
	public static Collection<HasPermission> getIdentifiers(IdentifierBundle ids) {
		return getIdentifiersForClass(ids, HasPermission.class);
	}

	public static Collection<Permission> getPermissions(IdentifierBundle ids) {
		Set<Permission> set = new HashSet<Permission>();
		for (HasPermission id : getIdentifiers(ids)) {
			set.add(id.getPermission());
		}
		return set;
	}

	private final PermissionSet permissionSet; // never null

	public HasPermissionSet(PermissionSet permissionSet) {
		if (permissionSet == null) {
			throw new NullPointerException("permissionSet may not be null.");
		}
		this.permissionSet = permissionSet;
	}

	public PermissionSet getPermissionSet() {
		return permissionSet;
	}

	@Override
	public String toString() {
		return "HasPermissionSet[" + permissionSet.getLabel() + "]";
	}

	@Override
	public int hashCode() {
		return permissionSet.getUri().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof HasPermissionSet)) {
			return false;
		}
		HasPermissionSet that = (HasPermissionSet) obj;
		return this.permissionSet.getUri().equals(that.permissionSet.getUri());
	}

	@Override
	public int compareTo(HasPermissionSet that) {
		return this.permissionSet.getUri().compareTo(
				that.permissionSet.getUri());
	}
}

@@ -368,77 +368,8 @@
 le;%0A
-import edu.cornell.mannlib.vitro.webapp.auth.permissions.Permission;%0A
 impo
@@ -665,24 +665,27 @@
 asPermission
+Set
 %3E getIdentif
@@ -763,16 +763,19 @@
 rmission
+Set
 .class);
@@ -815,16 +815,19 @@
 rmission
+Set
 %3E getPer
@@ -833,16 +833,19 @@
 rmission
+Set
 s(Identi
@@ -878,16 +878,19 @@
 rmission
+Set
 %3E set = 
@@ -901,26 +901,241 @@
 HashSet%3C
-Permission
+%3E();%0A%09%09for (HasPermissionSet id : getIdentifiers(ids)) %7B%0A%09%09%09set.add(id.getPermissionSet());%0A%09%09%7D%0A%09%09return set;%0A%09%7D%0A%0A%09public static Collection%3CString%3E getPermissionSetUris(IdentifierBundle ids) %7B%0A%09%09Set%3CString%3E set = new HashSet%3C
 %3E();%0A%09%09f
@@ -1151,16 +1151,19 @@
 rmission
+Set
  id : ge
@@ -1210,16 +1210,28 @@
 rmission
+Set().getUri
 ());%0A%09%09%7D
@@ -1248,16 +1248,17 @@
 set;%0A%09%7D%0A
+%09
 %0A%09privat

Correct a copy/paste error in static utility method. Also, add another utility method.