com.xiaoleilu.hutool.io.watch.watchers.WatcherChain Maven / Gradle / Ivy
package com.xiaoleilu.hutool.io.watch.watchers;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.util.Iterator;
import java.util.List;
import com.xiaoleilu.hutool.collection.CollectionUtil;
import com.xiaoleilu.hutool.io.watch.Watcher;
import com.xiaoleilu.hutool.lang.Chain;
/**
* 观察者链
* 用于加入多个观察者
*
* @author Looly
* @since 3.1.0
*/
public class WatcherChain implements Watcher, Chain{
/** 观察者列表 */
final private List chain;
/**
* 创建观察者链{@link WatcherChain}
* @param watchers 观察者列表
* @return {@link WatcherChain}
*/
public static WatcherChain create(Watcher... watchers) {
return new WatcherChain(watchers);
}
/**
* 构造
* @param watchers 观察者列表
*/
public WatcherChain(Watcher... watchers) {
chain = CollectionUtil.newArrayList(watchers);
}
@Override
public void onCreate(WatchEvent> event, Path currentPath) {
for (Watcher watcher : chain) {
watcher.onCreate(event, currentPath);
}
}
@Override
public void onModify(WatchEvent> event, Path currentPath) {
for (Watcher watcher : chain) {
watcher.onModify(event, currentPath);
}
}
@Override
public void onDelete(WatchEvent> event, Path currentPath) {
for (Watcher watcher : chain) {
watcher.onDelete(event, currentPath);
}
}
@Override
public void onOverflow(WatchEvent> event, Path currentPath) {
for (Watcher watcher : chain) {
watcher.onOverflow(event, currentPath);
}
}
@Override
public Iterator iterator() {
return this.chain.iterator();
}
@Override
public WatcherChain addChain(Watcher element) {
this.chain.add(element);
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy