
org.refcodes.observer.impls.ObserverDescriptorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refcodes-observer Show documentation
Show all versions of refcodes-observer Show documentation
Artifact for event handling purposes according to the observer (observable) pattern.
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// =============================================================================
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// =============================================================================
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// together with the GPL linking exception applied; as being applied by the GNU
// Classpath ("http://www.gnu.org/software/classpath/license.html")
// =============================================================================
// Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
// =============================================================================
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.observer.impls;
import org.refcodes.observer.Event;
import org.refcodes.observer.EventMatcher;
import org.refcodes.observer.Observer;
import org.refcodes.observer.ObserverDescriptor;
/**
* As a descriptor describes something fixed, this class is immutable in the
* sense that there are no setters for the attributes. The attributes must be
* provided via the constructor.
*
* @param The event type.
*/
public class ObserverDescriptorImpl, O extends Observer, EM extends EventMatcher> implements ObserverDescriptor {
private O _observer;
private EM _eventMatcher;
/**
* Constructs the event listener descriptor with the given event listener
* and the given event matcher.
*
* @param aEventListener The listener to be stored in the event listener
* descriptor.
* @param aEventMatcher The matcher to be stored in the event listener
* descriptor.
*/
public ObserverDescriptorImpl( O aEventListener, EM aEventMatcher ) {
_observer = aEventListener;
_eventMatcher = aEventMatcher;
}
@Override
public void onEvent( E aEvent ) {
if ( _eventMatcher == null || _eventMatcher.isMatching( aEvent ) ) {
_observer.onEvent( aEvent );
}
}
@Override
public O getObserver() {
return _observer;
}
@Override
public EM getEventMatcher() {
return _eventMatcher;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy