All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gu.dtalk.event.BaseObserver Maven / Gradle / Ivy

There is a newer version: 0.8.2
Show newest version
package gu.dtalk.event;

import java.util.Observable;
import java.util.Observer;

/**
 * 事件侦听器抽象类
 * @author guyadong
 *
 * @param  事件的参数类型
 */
public abstract class BaseObserver> implements Observer {

	public BaseObserver() {
	}
	/**
	 * 执行更新事件
	 * @param event 事件
	 */
	protected abstract void doUpdate(E event);
	@SuppressWarnings("unchecked")
	@Override
	public final void update(Observable o, Object arg) {
		E event;
		try {
			// 通过强制类型转时是否抛出异常自动过滤不属于当前侦听器关注的对象
			event = (E)arg;
		} catch (Throwable e) {		
			return;
		}
		doUpdate(event);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy