Clock.java

1
package com.rox.clock;
2
3
/**
4
 * Something which generates ticks to {@link ClockWatcher}s
5
 */
6
public interface Clock {
7
    /** Add a {@link ClockWatcher} to watch for <cc>tick()</cc> events **/
8
    void addListener(final ClockWatcher listener);
9
    /** Remove a {@link ClockWatcher} to no longer watch for <cc>tick()</cc> events **/
10
    void removeListener(final ClockWatcher listener);
11
    /** Inform all {@link ClockWatcher}s of a <cc>tick()</cc> event **/
12
    void tick();
13
    /** Returns the number of {@link ClockWatcher}s on this {@link Clock} **/
14
    int listeners();
15
16
    void run();
17
    void stop();
18
19
    /**
20
     * Call before starting {@link #run()} on another thread: until {@code run()} begins, a {@link #stop()} then
21
     * cancels that run rather than being undone by it.
22
     */
23
    default void prepareToRun(){
24
    }
25
26
    /** {@link #stop()}, then wait until {@link #run()} has returned, so nothing ticks after. */
27
    default void stopAndWait(){
28 1 1. stopAndWait : removed call to com/rox/clock/Clock::stop → KILLED
        stop();
29
    }
30
31
    boolean isRunning();
32
33
    /**
34
     * Freeze a running {@link #run()} loop without ending it, after the tick in progress, blocking until it has
35
     * genuinely stopped ticking - so on {@code true} the caller may safely {@link #tick()} it by hand until
36
     * {@link #resume()}. Never call it from a {@link ClockWatcher}: use {@link #requestPause()}.
37
     *
38
     * @return false if there was nothing to pause (not running, or stopped while waiting)
39
     */
40
    default boolean pause(){
41 1 1. pause : replaced boolean return with true for com/rox/clock/Clock::pause → KILLED
        return false;
42
    }
43
44
    /**
45
     * {@link #pause()} without waiting: a running {@link #run()} loop parks after the tick in progress. Safe from a
46
     * {@link ClockWatcher}, on {@code run()}'s own thread.
47
     */
48
    default void requestPause(){
49
    }
50
51
    /** Let a {@link #pause()}d {@link #run()} loop carry on; does nothing if it isn't paused. */
52
    default void resume(){
53
    }
54
55
    /**
56
     * Runs {@link #run()} at {@code multiplier} times real time - e.g. 2 for double speed. Does nothing by
57
     * default, for clocks that aren't paced against real time.
58
     *
59
     * @throws IllegalArgumentException if {@code multiplier} isn't a positive number
60
     */
61
    default void setSpeed(final double multiplier){
62
    }
63
64
    /** The speed multiplier {@link #run()} is paced at - see {@link #setSpeed}. */
65
    default double speed(){
66 1 1. speed : replaced double return with 0.0d for com/rox/clock/Clock::speed → KILLED
        return 1;
67
    }
68
}

Mutations

28

1.1
Location : stopAndWait
Killed by : com.rox.clock.FPSClockTest.[engine:junit-jupiter]/[class:com.rox.clock.FPSClockTest]/[method:clockDefaultsHaveNothingToPause()]
removed call to com/rox/clock/Clock::stop → KILLED

41

1.1
Location : pause
Killed by : com.rox.clock.FPSClockTest.[engine:junit-jupiter]/[class:com.rox.clock.FPSClockTest]/[method:clockDefaultsHaveNothingToPause()]
replaced boolean return with true for com/rox/clock/Clock::pause → KILLED

66

1.1
Location : speed
Killed by : com.rox.clock.FPSClockTest.[engine:junit-jupiter]/[class:com.rox.clock.FPSClockTest]/[method:clockDefaultsHaveNothingToPause()]
replaced double return with 0.0d for com/rox/clock/Clock::speed → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1