Files
briar/briar-api/src/org/briarproject/api/messaging/Group.java
akwizgran 4154119ea5 Convert to and from UTF-8 without catching impossible exceptions.
All JVMs must support UTF-8 encoding.
2014-02-07 22:02:02 +00:00

54 lines
1.2 KiB
Java

package org.briarproject.api.messaging;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
import java.nio.charset.Charset;
/** A group to which users may subscribe. */
public class Group {
private final GroupId id;
private final String name;
private final byte[] salt;
public Group(GroupId id, String name, byte[] salt) {
int length = name.getBytes(Charset.forName("UTF-8")).length;
if(length == 0 || length > MAX_GROUP_NAME_LENGTH)
throw new IllegalArgumentException();
if(salt.length != GROUP_SALT_LENGTH)
throw new IllegalArgumentException();
this.id = id;
this.name = name;
this.salt = salt;
}
/** Returns the group's unique identifier. */
public GroupId getId() {
return id;
}
/** Returns the group's name. */
public String getName() {
return name;
}
/**
* Returns the salt used to distinguish the group from other groups with
* the same name.
*/
public byte[] getSalt() {
return salt;
}
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public boolean equals(Object o) {
return o instanceof Group && id.equals(((Group) o).id);
}
}