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 describes an {@link EventCache}
027 * synchronization event.
028 *
029 * @param <T> a type of Kubernetes resource
030 *
031 * @author <a href="https://about.me/lairdnelson"
032 * target="_parent">Laird Nelson</a>
033 *
034 * @see EventCache
035 */
036public class SynchronizationEvent<T extends HasMetadata> extends AbstractEvent<T> {
037
038
039  /*
040   * Static fields.
041   */
042
043
044  /**
045   * The version of this class for {@linkplain Serializable
046   * serialization purposes}.
047   *
048   * @see Serializable
049   */
050  private static final long serialVersionUID = 1L;
051
052
053  /*
054   * Constructors.
055   */
056
057
058  /**
059   * Creates a new {@link SynchronizationEvent}.
060   *
061   * @param source the creator; must not be {@code null}
062   *
063   * @param type the {@link Type} of this {@link
064   * SynchronizationEvent}; must not be {@code null}; must not be
065   * {@link Type#DELETION}
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   * @exception IllegalArgumentException if {@link Type#DELETION} is
079   * equal to {@code type}
080   *
081   * @see Type
082   *
083   * @see EventObject#getSource()
084   */
085  public SynchronizationEvent(final Object source, final Type type, final T priorResource, final T resource) {
086    super(source, type, priorResource, resource);
087    if (Type.DELETION.equals(type)) {
088      throw new IllegalArgumentException("DELETION.equals(type): " + type);
089    }
090  }
091
092
093  /*
094   * Instance methods.
095   */
096
097
098  /**
099   * Returns {@code true} if the supplied {@link Object} is also a
100   * {@link SynchronizationEvent} and is equal in every respect to
101   * this one.
102   *
103   * @param other the {@link Object} to test; may be {@code null} in
104   * which case {@code false} will be returned
105   *
106   * @return {@code true} if the supplied {@link Object} is also a
107   * {@link SynchronizationEvent} and is equal in every respect to
108   * this one; {@code false} otherwise
109   */
110  @Override
111  public boolean equals(final Object other) {
112    if (other == this) {
113      return true;
114    } else if (other instanceof SynchronizationEvent) {
115
116      final boolean superEquals = super.equals(other);
117      if (!superEquals) {
118        return false;
119      }
120
121      return true;
122    } else {
123      return false;
124    }
125  }
126
127}