Talk is Cheap.
public class AppEvent {
private static AtomicInteger atomicInteger = new AtomicInteger(1000);
// 标记生成
public static int newTag() {
return atomicInteger.incrementAndGet();
}
// 标记
private int tag;
// 传递数据
public Object obj;
private AppEvent(int tag) {
this.tag = tag;
}
private AppEvent(int tag, Object obj) {
this(tag);
this.obj = obj;
}
/**
* 有数据传输
*/
public static AppEvent newInstance(int tag, Object obj) {
return new AppEvent(tag, obj);
}
/**
* 无数据传输
*/
public static AppEvent newInstance(int tag) {
return new AppEvent(tag);
}
/**
* 事件匹配
*/
public boolean match(int tag) {
return this.tag == tag;
}
}