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