• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / automatalib / 6685076669

29 Oct 2023 06:24PM UTC coverage: 89.857% (+0.06%) from 89.796%
6685076669

push

github

mtf90
align core packages with api packages

15814 of 17599 relevant lines covered (89.86%)

1.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.17
/commons/util/src/main/java/net/automatalib/common/util/nid/IDChangeNotifier.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of AutomataLib, http://www.automatalib.net/.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.automatalib.common.util.nid;
17

18
import java.util.Iterator;
19
import java.util.LinkedList;
20
import java.util.List;
21

22
import net.automatalib.common.util.ref.Ref;
23
import net.automatalib.common.util.ref.Refs;
24

25
public class IDChangeNotifier<T extends NumericID> {
1✔
26

27
    private final List<Ref<IDChangeListener<T>>> listeners = new LinkedList<>();
1✔
28

29
    public void addListener(IDChangeListener<T> listener, boolean weak) {
30
        Ref<IDChangeListener<T>> ref;
31
        if (weak) {
1✔
32
            ref = Refs.weak(listener);
1✔
33
        } else {
34
            ref = Refs.strong(listener);
×
35
        }
36

37
        listeners.add(ref);
1✔
38
    }
1✔
39

40
    public void removeListener(IDChangeListener<T> listener) {
41
        final Iterator<? extends Ref<?>> it = listeners.iterator();
×
42

43
        while (it.hasNext()) {
×
44
            Object referent = it.next().get();
×
45
            if (referent == null) {
×
46
                it.remove();
×
47
            } else if (referent.equals(listener)) {
×
48
                it.remove();
×
49
            }
50
        }
×
51
    }
×
52

53
    public void notifyListeners(T obj, int newId, int oldId) {
54
        Iterator<Ref<IDChangeListener<T>>> it = listeners.iterator();
1✔
55

56
        while (it.hasNext()) {
1✔
57
            IDChangeListener<T> listener = it.next().get();
1✔
58
            if (listener == null) {
1✔
59
                it.remove();
×
60
            } else {
61
                listener.idChanged(obj, newId, oldId);
1✔
62
            }
63
        }
1✔
64
    }
1✔
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc