Implement equals() and hashCode() for permissions.

This commit is contained in:
Michael Jumper
2013-01-30 23:24:56 -08:00
parent 01477ba063
commit e37d0eb1c9
4 changed files with 106 additions and 0 deletions

View File

@@ -66,4 +66,26 @@ public class GuacamoleConfigurationDirectoryPermission
return type; return type;
} }
@Override
public int hashCode() {
return type.hashCode();
}
@Override
public boolean equals(Object obj) {
// Not equal if null or wrong type
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final GuacamoleConfigurationDirectoryPermission other =
(GuacamoleConfigurationDirectoryPermission) obj;
// Compare types
if (type != other.type)
return false;
return true;
}
} }

View File

@@ -86,4 +86,36 @@ public class GuacamoleConfigurationPermission
return type; return type;
} }
@Override
public int hashCode() {
int hash = 5;
if (identifier != null) hash = 47 * hash + identifier.hashCode();
if (type != null) hash = 47 * hash + type.hashCode();
return hash;
}
@Override
public boolean equals(Object obj) {
// Not equal if null or wrong type
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final GuacamoleConfigurationPermission other =
(GuacamoleConfigurationPermission) obj;
// Not equal if different type
if (this.type != other.type)
return false;
// If null identifier, equality depends on whether other identifier
// is null
if (identifier == null)
return other.identifier != null;
// Otherwise, equality depends entirely on identifier
return identifier.equals(other.identifier);
}
} }

View File

@@ -64,4 +64,25 @@ public class UserDirectoryPermission implements SystemPermission {
return type; return type;
} }
@Override
public int hashCode() {
return type.hashCode();
}
@Override
public boolean equals(Object obj) {
// Not equal if null or wrong type
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final UserDirectoryPermission other = (UserDirectoryPermission) obj;
// Compare types
if (type != other.type)
return false;
return true;
}
} }

View File

@@ -82,4 +82,35 @@ public class UserPermission implements ObjectPermission<String> {
return type; return type;
} }
@Override
public int hashCode() {
int hash = 5;
if (identifier != null) hash = 47 * hash + identifier.hashCode();
if (type != null) hash = 47 * hash + type.hashCode();
return hash;
}
@Override
public boolean equals(Object obj) {
// Not equal if null or wrong type
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final UserPermission other = (UserPermission) obj;
// Not equal if different type
if (this.type != other.type)
return false;
// If null identifier, equality depends on whether other identifier
// is null
if (identifier == null)
return other.identifier != null;
// Otherwise, equality depends entirely on identifier
return identifier.equals(other.identifier);
}
} }