package envoy.data;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;
/**
* This class is the superclass for both {@link User} and {@link Group}.
* It provides an id and a name for each user and group.
*
* Project: envoy-common
* File: Contact.java
* Created: 24 Mar 2020
*
* @author Leon Hofmeister
* @since Envoy v0.1-beta
*/
public abstract class Contact implements Serializable {
private final long id;
private final transient Set extends Contact> contacts;
private String name;
private static final long serialVersionUID = 0L;
/**
* Creates a new instance of a {@link Contact}.
*
* @param id the ID of this contact
* @param name the name of this contact
* @param contacts the {@link Contacts} of this {@link Contact}
* @since Envoy Common v0.1-beta
*/
public Contact(long id, String name, Set extends Contact> contacts) {
this.id = id;
this.name = name;
this.contacts = contacts;
}
/**
* @return the ID of this {@link Contact}
* @since Envoy Common v0.2-alpha
*/
public long getID() { return id; }
/**
* @return the name of this {@link Contact}
* @since Envoy Common v0.2-alpha
*/
public String getName() { return name; }
/**
* @param name the new name of this {@link Contact}
* @since Envoy Common v0.1-beta
*/
public void setName(String name) { this.name = name; }
/**
* {@inheritDoc}
*/
@Override
public String toString() { return String.format("Contact[id=%d,name=%s, contacts=%s]", id, name, contacts); }
/**
* {@inheritDoc}
*/
@Override
public int hashCode() { return Objects.hash(id); }
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Contact)) return false;
return id == ((Contact) obj).id;
}
/**
* @return the contacts of this {@link Contact}
* @since Envoy Common v0.1-beta
*/
public Set extends Contact> getContacts() { return contacts; }
}