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

leeonky / test-charm-java / 249

12 May 2025 09:46AM UTC coverage: 74.26% (-0.03%) from 74.288%
249

push

circleci

leeonky
Rename

3 of 3 new or added lines in 3 files covered. (100.0%)

21 existing lines in 5 files now uncovered.

8075 of 10874 relevant lines covered (74.26%)

0.74 hits per line

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

96.55
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/IterableDALCollection.java
1
package com.github.leeonky.dal.runtime;
2

3
import java.util.*;
4
import java.util.function.Predicate;
5
import java.util.stream.StreamSupport;
6

7
public class IterableDALCollection<E> extends DALCollectionBase<E> {
8
    private final Iterator<E> iterator;
9
    private final List<E> cached = new ArrayList<>();
1✔
10

11
    public IterableDALCollection(Iterable<E> iterable) {
1✔
12
        iterator = StreamSupport.stream(iterable.spliterator(), false).iterator();
1✔
13
    }
1✔
14

15
    @Override
16
    public Iterator<IndexedElement<E>> iterator() {
17
        return new Iterator<IndexedElement<E>>() {
1✔
18
            private int index = firstIndex();
1✔
19
            private int position = 0;
1✔
20

21
            @Override
22
            public boolean hasNext() {
23
                if (position < cached.size()) {
1✔
24
                    return true;
1✔
25
                }
26
                return iterator.hasNext();
1✔
27
            }
28

29
            @Override
30
            public IndexedElement<E> next() {
31
                if (position < cached.size())
1✔
32
                    return new IndexedElement<>(index++, cached.get(position++));
1✔
33
                position++;
1✔
34
                return new IndexedElement<>(index++, getNext());
1✔
35
            }
36
        };
37
    }
38

39
    private E getNext() {
40
        E next = iterator.next();
1✔
41
        cached.add(next);
1✔
42
        return next;
1✔
43
    }
44

45
    @Override
46
    protected E getByPosition(int position) {
47
        if (position < cached.size())
1✔
48
            return cached.get(position);
1✔
49
        while (iterator.hasNext()) {
1✔
50
            getNext();
1✔
51
            if (position < cached.size())
1✔
52
                return cached.get(position);
1✔
53
        }
UNCOV
54
        throw new IndexOutOfBoundsException();
×
55
    }
56

57
    @Override
58
    public int size() {
59
        return (int) StreamSupport.stream(
1✔
60
                requireLimitedCollection("Not supported for infinite collection").spliterator(), false).count();
1✔
61
    }
62

63
    @Override
64
    public DALCollection<E> filter(Predicate<E> predicate) {
65
        return new IterableDALCollection<E>(() -> Spliterators.iterator(StreamSupport.stream(
1✔
66
                Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false).filter(predicate).spliterator())) {
1✔
67

68
            @Override
69
            public int firstIndex() {
70
                return IterableDALCollection.this.firstIndex();
1✔
71
            }
72
        };
73
    }
74
}
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

© 2026 Coveralls, Inc