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;
022import java.util.Objects;
023
024import io.fabric8.kubernetes.api.model.HasMetadata;
025import io.fabric8.kubernetes.api.model.ObjectMeta;
026
027/**
028 * An {@link AbstractEvent} that represents another event that has
029 * occurred to a Kubernetes resource, usually as found in an {@link
030 * EventCache} implementation.
031 *
032 * @param <T> a type of Kubernetes resource
033 *
034 * @author <a href="https://about.me/lairdnelson"
035 * target="_parent">Laird Nelson</a>
036 *
037 * @see EventCache
038 */
039public class Event<T extends HasMetadata> extends AbstractEvent<T> {
040
041
042  /*
043   * Static fields.
044   */
045
046
047  /**
048   * The version of this class for {@linkplain Serializable
049   * serialization purposes}.
050   *
051   * @see Serializable
052   */
053  private static final long serialVersionUID = 1L;
054
055
056  /*
057   * Constructors.
058   */
059
060
061  /**
062   * Creates a new {@link Event}.
063   *
064   * @param source the creator; must not be {@code null}
065   *
066   * @param type the {@link Type} of this {@link Event}; must not be
067   * {@code null}
068   *
069   * @param priorResource a {@link HasMetadata} representing the
070   * <em>prior state</em> of the {@linkplain #getResource() Kubernetes
071   * resource this <code>Event</code> primarily concerns}; may
072   * be&mdash;<strong>and often is</strong>&mdash;null
073   *
074   * @param resource a {@link HasMetadata} representing a Kubernetes
075   * resource; must not be {@code null}
076   *
077   * @exception NullPointerException if {@code source}, {@code type}
078   * or {@code resource} is {@code null}
079   *
080   * @see Type
081   *
082   * @see EventObject#getSource()
083   */
084  public Event(final Object source, final Type type, final T priorResource, final T resource) {
085    super(source, type, priorResource, resource);
086  }
087
088
089  /*
090   * Instance methods.
091   */
092
093
094  /**
095   * Returns {@code true} if the supplied {@link Object} is also an
096   * {@link Event} and is equal in every respect to this one.
097   *
098   * @param other the {@link Object} to test; may be {@code null} in
099   * which case {@code false} will be returned
100   *
101   * @return {@code true} if the supplied {@link Object} is also an
102   * {@link Event} and is equal in every respect to this one; {@code
103   * false} otherwise
104   */
105  @Override
106  public boolean equals(final Object other) {
107    if (other == this) {
108      return true;
109    } else if (other instanceof Event) {
110
111      final boolean superEquals = super.equals(other);
112      if (!superEquals) {
113        return false;
114      }
115
116      return true;
117    } else {
118      return false;
119    }
120  }
121
122}