• 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

88.24
/commons/smartcollections/src/main/java/net/automatalib/common/smartcollection/ReflexiveMapView.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.smartcollection;
17

18
import java.util.AbstractMap;
19
import java.util.AbstractSet;
20
import java.util.Collections;
21
import java.util.Iterator;
22
import java.util.Map;
23
import java.util.Set;
24

25
import org.checkerframework.checker.nullness.qual.KeyFor;
26
import org.checkerframework.checker.nullness.qual.Nullable;
27

28
/**
29
 * An immutable, reflexive {@link Map} view for a given set of elements. This map is backed by the given set elements,
30
 * i.e. changes to the passed sets are propagated to this map.
31
 *
32
 * @param <T>
33
 *         element type
34
 */
35
public class ReflexiveMapView<T> extends AbstractMap<T, T> {
36

37
    private final Set<@KeyFor("this") T> domain;
38

39
    public ReflexiveMapView(Set<T> domain) {
2✔
40
        this.domain = Collections.unmodifiableSet(domain);
2✔
41
    }
2✔
42

43
    @Override
44
    public Set<Entry<@KeyFor("this") T, T>> entrySet() {
45
        return new EntrySet();
2✔
46
    }
47

48
    @Override
49
    public boolean containsValue(@Nullable Object value) {
50
        return containsKey(value);
×
51
    }
52

53
    @Override
54
    @SuppressWarnings("contracts.conditional.postcondition") // condition is satisfied
55
    public boolean containsKey(@Nullable Object key) {
56
        return this.domain.contains(key);
×
57
    }
58

59
    @Override
60
    @SuppressWarnings("unchecked")
61
    public @Nullable T get(@Nullable Object key) {
62
        return this.domain.contains(key) ? (T) key : null;
2✔
63
    }
64

65
    @Override
66
    public Set<@KeyFor("this") T> keySet() {
67
        return this.domain;
2✔
68
    }
69

70
    @Override
71
    public Set<T> values() {
72
        return this.domain;
2✔
73
    }
74

75
    private final class EntrySet extends AbstractSet<Entry<@KeyFor("this") T, T>> {
2✔
76

77
        @Override
78
        public Iterator<Entry<@KeyFor("this") T, T>> iterator() {
79
            return new Iter();
2✔
80
        }
81

82
        @Override
83
        public int size() {
84
            return domain.size();
2✔
85
        }
86
    }
87

88
    private final class Iter implements Iterator<Entry<@KeyFor("this") T, T>> {
2✔
89

90
        final Iterator<@KeyFor("this") T> iter = domain.iterator();
2✔
91

92
        @Override
93
        public boolean hasNext() {
94
            return iter.hasNext();
2✔
95
        }
96

97
        @Override
98
        public Entry<@KeyFor("this") T, T> next() {
99
            final @KeyFor("this") T next = iter.next();
2✔
100
            return new SimpleImmutableEntry<>(next, next);
2✔
101
        }
102
    }
103
}
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