Skip to content

Commit 16d793d

Browse files
committed
chg: add a PeriodicClockListener that trigger a ClockListener at periodic times
1 parent 6df9ff3 commit 16d793d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2008 - 2020, Arnaud Casteigts and the JBotSim contributors <contact@jbotsim.io>
3+
*
4+
*
5+
* This file is part of JBotSim.
6+
*
7+
* JBotSim is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* JBotSim is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with JBotSim. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
package io.jbotsim.core.event;
23+
24+
import io.jbotsim.core.Topology;
25+
26+
public class PeriodicClockListener extends FilteredClockListener {
27+
private int period;
28+
29+
public PeriodicClockListener(Topology tp, ClockListener listener, int period) {
30+
super(tp, listener);
31+
this.period = period;
32+
}
33+
34+
@Override
35+
protected boolean shouldTriggerListener(Topology tp, int currentTime) {
36+
return ((currentTime + 1) % period == 0);
37+
}
38+
}

0 commit comments

Comments
 (0)