/*******************************************************************************
 * Copyright (c) 2015 - 2016 - 2016, Andreas Hefti, inarisoft@yahoo.de 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.inari.commons.event;

import com.inari.commons.lang.indexed.Indexed;
import com.inari.commons.lang.indexed.IndexedType;
import com.inari.commons.lang.indexed.IndexedTypeKey;
import com.inari.commons.lang.indexed.Indexer;

/** Base implementation of an Event handled by the IEventDispatcher.
 *  <p>
 *  Implement this for a specific Event type bound to a EventListener implementation (L)
 *  For example if a specified Event is needed to notify specified listener(s) creation and 
 *  implementation of the following interfaces/classes are needed:
 *  <p>
 *  <pre>
 *  public interface TheEventListener extends EventListener {
 *  
 *      void onTheEvent( TheEvent event );
 *      
 *  }
 *  
 *  public class TheEvent extends Event<TheEventListener> {
 *  
 *      public final String anEventAttribute;
 *      
 *      public TheEvent( String anEventAttribute ) {
 *          super();
 *          this.anEventAttribute = anEventAttribute;
 *      }
 *      
 *      public final void notify( TheEventListener listener ) {
 *          listener.onTheEvent( this );
 *      }
 *  }
 *  </pre>
 *  
 *  
 * @author andreas hefti
 *
 * @param <L> The type of EventListener the is interested in the specified Event.
 */
public abstract class Event<L> implements IndexedType, Indexed {
    
    /** The EventTypeKey that specified type type of event */
    protected final EventTypeKey indexedTypeKey;
    
    protected Event( EventTypeKey indexedTypeKey ) {
        this.indexedTypeKey = indexedTypeKey;
    }

    @Override
    public final int index() {
        return indexedTypeKey.index();
    }

    @Override
    public final IndexedTypeKey indexedTypeKey() {
        return indexedTypeKey;
    }

    /** Implements the notification of specified listener.
     *  For an implementation example have a look at the class documentation example
     *  
     *  @param listener the listener to notify.
     */
    protected abstract void notify( final L listener );
    
    
    /** This is internally used to create index for specified event type */
    protected static final EventTypeKey createTypeKey( Class<? extends Event<?>> type ) {
        return Indexer.createIndexedTypeKey( EventTypeKey.class, type );
    }
    
    /** Use this to get the EventTypeKey for e given Event class type */
    public static final EventTypeKey getTypeKey( Class<? extends Event<?>> type ) {
        return Indexer.getIndexedTypeKey( EventTypeKey.class, type );
    }
    
    /** Defines a type key for a specified event.
     *  This is used for indexing the event types.
     */
    public static final class EventTypeKey extends IndexedTypeKey {
        
        EventTypeKey( Class<? extends Event<?>> indexedType ) {
            super( indexedType );
        }
        
        @Override
        public final Class<?> baseType() {
            return Event.class;
        }
        
    }

}

@@ -1071,16 +1071,23 @@
  by the 
+%7B@link 
 IEventDi
@@ -1094,16 +1094,17 @@
 spatcher
+%7D
 .%0A *  %3Cp
@@ -1161,16 +1161,23 @@
 nd to a 
+%7B@link 
 EventLis
@@ -1181,16 +1181,17 @@
 Listener
+%7D
  impleme
@@ -1973,16 +1973,23 @@
 type of 
+%7B@link 
 EventLis
@@ -1989,24 +1989,25 @@
 ventListener
+%7D
  the is inte
@@ -2123,16 +2123,23 @@
 /** The 
+%7B@link 
 EventTyp
@@ -2142,16 +2142,17 @@
 tTypeKey
+%7D
  that sp
@@ -2333,32 +2333,101 @@
 TypeKey;%0A    %7D%0A%0A
+    /** Use this to get the index/type id of the specified Event */ %0A
     @Override%0A  
@@ -2497,24 +2497,110 @@
 x();%0A    %7D%0A%0A
+    /** Use this to get the %7B@link EventTypeKey%7D that specified type type of event */%0A
     @Overrid

Update Event.java