82 lines
2.0 KiB
Java
82 lines
2.0 KiB
Java
package envoy.data;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* This class is the superclass for both {@link User} and {@link Group}.<br>
|
|
* It provides an id and a name for each user and group.<br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy v0.1-beta
|
|
*/
|
|
public abstract class Contact implements Serializable {
|
|
|
|
protected final long id;
|
|
protected final transient Set<? extends Contact> contacts;
|
|
|
|
protected 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 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; }
|
|
|
|
/**
|
|
* Provides a hash code based on the ID of this contact.
|
|
*
|
|
* @since Envoy Common v0.1-beta
|
|
*/
|
|
@Override
|
|
public final int hashCode() { return Objects.hash(id); }
|
|
|
|
/**
|
|
* Tests equality to another object. If that object is a contact as well,
|
|
* equality is determined by the ID.
|
|
*
|
|
* @param obj the object to test for equality to this contact
|
|
* @return {code true} if both objects are contacts and have identical IDs
|
|
*/
|
|
@Override
|
|
public final 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; }
|
|
}
|