• 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

71.43
/commons/util/src/main/java/net/automatalib/common/util/mapping/ArrayMapping.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.mapping;
17

18
import net.automatalib.common.util.array.ArrayStorage;
19
import net.automatalib.common.util.nid.IDChangeListener;
20
import net.automatalib.common.util.nid.NumericID;
21

22
public final class ArrayMapping<K extends NumericID, V> implements MutableMapping<K, V>, IDChangeListener<K> {
23

24
    private final ArrayStorage<V> storage;
25

26
    public ArrayMapping() {
×
27
        storage = new ArrayStorage<>();
×
28
    }
×
29

30
    public ArrayMapping(int initialSize) {
1✔
31
        storage = new ArrayStorage<>(initialSize);
1✔
32
    }
1✔
33

34
    @Override
35
    public V get(K elem) {
36
        return storage.get(elem.getId());
1✔
37
    }
38

39
    @Override
40
    public V put(K key, V value) {
41
        int id = key.getId();
1✔
42
        storage.ensureCapacity(id + 1);
1✔
43
        return storage.set(id, value);
1✔
44
    }
45

46
    @Override
47
    @SuppressWarnings("argument")
48
    public void idChanged(K obj, int newId, int oldId) {
49
        if (newId == -1) {
1✔
50
            if (oldId < storage.size()) {
×
51
                storage.set(oldId, null);
×
52
            }
53
            return;
×
54
        }
55
        V oldVal = null;
1✔
56
        if (oldId < storage.size()) {
1✔
57
            oldVal = storage.get(oldId);
1✔
58
            storage.set(oldId, oldVal);
1✔
59
        }
60
        storage.ensureCapacity(newId + 1);
1✔
61
        storage.set(newId, oldVal);
1✔
62
    }
1✔
63

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