This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/common/src/main/java/envoy/data/Group.java

58 lines
1.5 KiB
Java

package envoy.data;
import java.io.*;
import java.util.*;
/**
* @author Leon Hofmeister
* @since Envoy Common v0.1-beta
*/
public final class Group extends Contact {
private static final long serialVersionUID = 0L;
/**
* Creates a new instance of a {@link Group} without any members.
*
* @param id the ID of this group
* @param name the name of this group
* @since Envoy Common v0.1-beta
*/
public Group(long id, String name) {
this(id, name, new HashSet<User>());
}
/**
* Creates an instance of a {@link Group}.
*
* @param id the ID of this group
* @param name the name of this group
* @param members all members that should be preinitialized
* @since Envoy Common v0.1-beta
*/
public Group(long id, String name, Set<User> members) {
super(id, name, members);
}
@Override
public String toString() {
return String.format("Group[id=%d,name=%s,%d member(s)]", id, name, contacts.size());
}
private void readObject(ObjectInputStream inputStream) throws Exception {
inputStream.defaultReadObject();
var contacts = Contact.class.getDeclaredField("contacts");
contacts.setAccessible(true);
contacts.set(this, inputStream.readObject());
}
private void writeObject(ObjectOutputStream outputStream) throws Exception {
outputStream.defaultWriteObject();
getContacts().forEach(user -> user.serializeContacts(false));
outputStream.writeObject(getContacts());
}
@Override
public Set<User> getContacts() { return (Set<User>) contacts; }
}