001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2017-2018 microBean.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
014 * implied.  See the License for the specific language governing
015 * permissions and limitations under the License.
016 */
017package org.microbean.kubernetes.controller;
018
019import java.io.Serializable; // for javadoc only
020
021import java.util.EventObject;
022
023import io.fabric8.kubernetes.api.model.HasMetadata;
024
025/**
026 * An {@link AbstractEvent} that represents another event that has
027 * occurred to a Kubernetes resource, usually as found in an {@link
028 * EventCache} implementation.
029 *
030 * @param <T> a type of Kubernetes resource
031 *
032 * @author <a href="https://about.me/lairdnelson"
033 * target="_parent">Laird Nelson</a>
034 *
035 * @see EventCache
036 */
037public class Event<T extends HasMetadata> extends AbstractEvent<T> {
038
039
040  /*
041   * Static fields.
042   */
043
044
045  /**
046   * The version of this class for {@linkplain Serializable
047   * serialization purposes}.
048   *
049   * @see Serializable
050   */
051  private static final long serialVersionUID = 1L;
052
053
054  /*
055   * Constructors.
056   */
057
058
059  /**
060   * Creates a new {@link Event}.
061   *
062   * @param source the creator; must not be {@code null}
063   *
064   * @param type the {@link Type} of this {@link Event}; must not be
065   * {@code null}
066   *
067   * @param priorResource a {@link HasMetadata} representing the
068   * <em>prior state</em> of the {@linkplain #getResource() Kubernetes
069   * resource this <code>Event</code> primarily concerns}; may
070   * be&mdash;<strong>and often is</strong>&mdash;null
071   *
072   * @param resource a {@link HasMetadata} representing a Kubernetes
073   * resource; must not be {@code null}
074   *
075   * @exception NullPointerException if {@code source}, {@code type}
076   * or {@code resource} is {@code null}
077   *
078   * @see Type
079   *
080   * @see EventObject#getSource()
081   */
082  public Event(final Object source, final Type type, final T priorResource, final T resource) {
083    super(source, type, priorResource, resource);
084  }
085
086
087  /*
088   * Instance methods.
089   */
090
091
092  /**
093   * Returns {@code true} if the supplied {@link Object} is also an
094   * {@link Event} and is equal in every respect to this one.
095   *
096   * @param other the {@link Object} to test; may be {@code null} in
097   * which case {@code false} will be returned
098   *
099   * @return {@code true} if the supplied {@link Object} is also an
100   * {@link Event} and is equal in every respect to this one; {@code
101   * false} otherwise
102   */
103  @Override
104  public boolean equals(final Object other) {
105    if (other == this) {
106      return true;
107    } else if (other instanceof Event) {
108
109      final boolean superEquals = super.equals(other);
110      if (!superEquals) {
111        return false;
112      }
113
114      return true;
115    } else {
116      return false;
117    }
118  }
119
120}