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

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

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

72.22
/commons/util/src/main/java/net/automatalib/common/util/collection/AbstractTwoLevelIterator.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://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.collection;
17

18
import java.util.Iterator;
19
import java.util.NoSuchElementException;
20

21
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
22
import org.checkerframework.checker.nullness.qual.Nullable;
23

24
public abstract class AbstractTwoLevelIterator<L1, L2, O> implements Iterator<O> {
25

26
    private final Iterator<? extends L1> l1Iterator;
27
    private L1 l1Object;
28
    private @Nullable Iterator<L2> l2Iterator;
29

30
    public AbstractTwoLevelIterator(Iterator<? extends L1> l1Iterator) {
1✔
31
        this.l1Iterator = l1Iterator;
1✔
32
        this.l2Iterator = null;
1✔
33
    }
1✔
34

35
    @Override
36
    public boolean hasNext() {
37
        return l2Iterator != null && l2Iterator.hasNext() || advance();
1✔
38
    }
39

40
    @EnsuresNonNullIf(expression = "l2Iterator", result = true)
41
    private boolean advance() {
42
        while (l2Iterator == null || !l2Iterator.hasNext()) {
1✔
43
            if (!l1Iterator.hasNext()) {
1✔
44
                return false;
1✔
45
            }
46
            this.l1Object = l1Iterator.next();
1✔
47
            this.l2Iterator = l2Iterator(this.l1Object);
1✔
48
        }
49
        return true;
1✔
50
    }
51

52
    protected abstract Iterator<L2> l2Iterator(L1 l1Object);
53

54
    @Override
55
    public O next() {
56
        if ((l2Iterator == null || !l2Iterator.hasNext()) && !advance()) {
1✔
57
            throw new NoSuchElementException();
×
58
        }
59

60
        return combine(l1Object, l2Iterator.next());
1✔
61
    }
62

63
    protected abstract O combine(L1 l1Object, L2 l2Object);
64

65
    @Override
66
    public void remove() {
67
        if (l2Iterator == null) {
×
68
            throw new IllegalStateException();
×
69
        }
70
        l2Iterator.remove();
×
71
    }
×
72

73
}
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