All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rinde.sim.event.Event Maven / Gradle / Ivy

There is a newer version: 4.4.6
Show newest version
/**
 * 
 */
package rinde.sim.event;

import java.io.Serializable;

import javax.annotation.Nullable;

import com.google.common.base.Optional;

/**
 * The base event class. It is immutable.
 * @author Rinde van Lon 
 * @author Bartosz Michalik 
 */
public class Event implements Serializable {
  private static final long serialVersionUID = -390528892294335442L;

  /**
   * The type of event.
   */
  protected final Enum eventType;
  private final Optional issuer;

  /**
   * Create a new event instance.
   * @param type the event type.
   * @param pIssuer The event issuer, may be null.
   */
  public Event(Enum type, @Nullable Object pIssuer) {
    eventType = type;
    issuer = Optional.fromNullable(pIssuer);
  }

  /**
   * Create a new event without a issuer.
   * @param type The event type.
   */
  protected Event(Enum type) {
    this(type, null);
  }

  /**
   * @return true if this event has an issuer, false
   *         otherwise.
   */
  public boolean hasIssuer() {
    return issuer.isPresent();
  }

  /**
   * @return The event issuer.
   */
  public Object getIssuer() {
    return issuer.get();
  }

  /**
   * @return The type of event.
   */
  public Enum getEventType() {
    return eventType;
  }

  @Override
  public String toString() {
    return "[Event " + eventType + "]";
  }
}