EventManager.java

1
package g0803.bindingofshiba.events;
2
3
import g0803.bindingofshiba.events.game.*;
4
import java.lang.ref.WeakReference;
5
import java.util.*;
6
7
public class EventManager implements IEventManager {
8
9
    private final Set<WeakReference<Observer>> refs = new HashSet<>();
10
11
    @Override
12
    public void addObserver(Observer observer) {
13
        refs.add(new WeakReference<>(observer));
14
    }
15
16
    @Override
17
    public void removeObserver(Observer observer) {
18 2 1. lambda$removeObserver$0 : replaced boolean return with true for g0803/bindingofshiba/events/EventManager::lambda$removeObserver$0 → SURVIVED
2. lambda$removeObserver$0 : replaced boolean return with false for g0803/bindingofshiba/events/EventManager::lambda$removeObserver$0 → KILLED
        refs.removeIf(ref -> ref.refersTo(observer));
19
    }
20
21
    @Override
22
    public Set<Observer> getObservers() {
23
        Set<Observer> observers = new HashSet<>();
24
25
        Iterator<WeakReference<Observer>> iterator = refs.iterator();
26 1 1. getObservers : negated conditional → KILLED
        while (iterator.hasNext()) {
27
            WeakReference<Observer> ref = iterator.next();
28
29 1 1. getObservers : negated conditional → KILLED
            if (ref.refersTo(null)) {
30 1 1. getObservers : removed call to java/util/Iterator::remove → NO_COVERAGE
                iterator.remove();
31
                continue;
32
            }
33
34
            observers.add(ref.get());
35
        }
36
37 1 1. getObservers : replaced return value with Collections.emptySet for g0803/bindingofshiba/events/EventManager::getObservers → KILLED
        return observers;
38
    }
39
40
    private void dispatchEvent(Event event, Observer listener) {
41 1 1. dispatchEvent : negated conditional → KILLED
        if (event instanceof PlayerCollisionWithMonsterEvent e) {
42 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithMonster → KILLED
            listener.onPlayerCollisionWithMonster(e);
43 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof MonsterCollisionWithMonsterEvent e) {
44 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithMonster → KILLED
            listener.onMonsterCollisionWithMonster(e);
45 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof PlayerCollisionWithObstacleEvent e) {
46 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithObstacle → KILLED
            listener.onPlayerCollisionWithObstacle(e);
47 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof MonsterCollisionWithObstacleEvent e) {
48 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithObstacle → KILLED
            listener.onMonsterCollisionWithObstacle(e);
49 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof PlayerCollisionWithWallsEvent e) {
50 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithWalls → KILLED
            listener.onPlayerCollisionWithWalls(e);
51 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof MonsterCollisionWithWallsEvent e) {
52 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithWalls → KILLED
            listener.onMonsterCollisionWithWalls(e);
53 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof PlayerEnterDoorEvent e) {
54 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onPlayerEnterDoor → KILLED
            listener.onPlayerEnterDoor(e);
55 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof PlayerUnlockDoorEvent e) {
56 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onPlayerUnlockDoor → KILLED
            listener.onPlayerUnlockDoor(e);
57 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof ProjectileCollisionWithMonsterEvent e) {
58 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onProjectileCollisionWithMonster → KILLED
            listener.onProjectileCollisionWithMonster(e);
59 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof ProjectileDestroyedEvent e) {
60 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onProjectileDestroyed → KILLED
            listener.onProjectileDestroyed(e);
61 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof ProjectileSpawnedEvent e) {
62 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onProjectileSpawned → KILLED
            listener.onProjectileSpawned(e);
63 1 1. dispatchEvent : negated conditional → KILLED
        } else if (event instanceof MonsterDamagedEvent e) {
64 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/Observer::onMonsterDamaged → KILLED
            listener.onMonsterDamaged(e);
65
        }
66
    }
67
68
    @Override
69
    public void dispatchEvent(Event event) {
70
        for (Observer observer : getObservers()) {
71 1 1. dispatchEvent : removed call to g0803/bindingofshiba/events/EventManager::dispatchEvent → KILLED
            dispatchEvent(event, observer);
72
        }
73
    }
74
}

Mutations

18

1.1
Location : lambda$removeObserver$0
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:removeObserver()]
replaced boolean return with false for g0803/bindingofshiba/events/EventManager::lambda$removeObserver$0 → KILLED

2.2
Location : lambda$removeObserver$0
Killed by : none
replaced boolean return with true for g0803/bindingofshiba/events/EventManager::lambda$removeObserver$0 → SURVIVED

26

1.1
Location : getObservers
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:removeObserver()]
negated conditional → KILLED

29

1.1
Location : getObservers
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
negated conditional → KILLED

30

1.1
Location : getObservers
Killed by : none
removed call to java/util/Iterator::remove → NO_COVERAGE

37

1.1
Location : getObservers
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
replaced return value with Collections.emptySet for g0803/bindingofshiba/events/EventManager::getObservers → KILLED

41

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
negated conditional → KILLED

42

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithMonster → KILLED

43

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
negated conditional → KILLED

44

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithMonster → KILLED

45

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

46

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithObstacle → KILLED

47

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

48

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithObstacle → KILLED

49

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

50

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onPlayerCollisionWithWalls → KILLED

51

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

52

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onMonsterCollisionWithWalls → KILLED

53

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

54

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onPlayerEnterDoor → KILLED

55

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

56

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onPlayerUnlockDoor → KILLED

57

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

58

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onProjectileCollisionWithMonster → KILLED

59

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

60

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onProjectileDestroyed → KILLED

61

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

62

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onProjectileSpawned → KILLED

63

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
negated conditional → KILLED

64

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchesEvents()]
removed call to g0803/bindingofshiba/events/Observer::onMonsterDamaged → KILLED

71

1.1
Location : dispatchEvent
Killed by : g0803.bindingofshiba.events.EventManagerTest.[engine:junit-jupiter]/[class:g0803.bindingofshiba.events.EventManagerTest]/[method:dispatchEventWithMultipleObservers()]
removed call to g0803/bindingofshiba/events/EventManager::dispatchEvent → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.0