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

gephi / graphstore / #653

24 Oct 2026 08:16PM UTC coverage: 91.896% (+0.01%) from 91.886%
#653

push

web-flow
Keep the column index consistent when an attribute is set concurrently (#360)

Element.setAttribute writes the value and then updates the index without the
table lock, while adding and removing nodes, view changes and view index fills
read the value and update the index on their own. In between, the index update
threw a NullPointerException on the missing old value, or left the element
under a stale value or in the index after its removal. An index now only moves
an element it holds under the old value, a removal finds the element under any
value, and each update checks the value again afterwards to move the element
to the current one. addColumn indexes the existing elements itself, and fill
rebuilds the view indexes like not.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>

80 of 83 new or added lines in 6 files covered. (96.39%)

1 existing line in 1 file now uncovered.

12360 of 13450 relevant lines covered (91.9%)

0.92 hits per line

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

81.18
/src/main/java/org/gephi/graph/impl/ColumnStandardIndexImpl.java
1
/*
2
 * Copyright 2012-2013 Gephi Consortium
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * 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, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16

17
package org.gephi.graph.impl;
18

19
import it.unimi.dsi.fastutil.booleans.BooleanArrays;
20
import it.unimi.dsi.fastutil.bytes.Byte2ObjectAVLTreeMap;
21
import it.unimi.dsi.fastutil.bytes.ByteArrays;
22
import it.unimi.dsi.fastutil.chars.Char2ObjectAVLTreeMap;
23
import it.unimi.dsi.fastutil.chars.CharArrays;
24
import it.unimi.dsi.fastutil.doubles.Double2ObjectAVLTreeMap;
25
import it.unimi.dsi.fastutil.doubles.DoubleArrays;
26
import it.unimi.dsi.fastutil.floats.Float2ObjectAVLTreeMap;
27
import it.unimi.dsi.fastutil.floats.FloatArrays;
28
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
29
import it.unimi.dsi.fastutil.ints.IntArrays;
30
import it.unimi.dsi.fastutil.longs.Long2ObjectAVLTreeMap;
31
import it.unimi.dsi.fastutil.longs.LongArrays;
32
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
33
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
34
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
35
import it.unimi.dsi.fastutil.objects.ObjectArrays;
36
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
37
import it.unimi.dsi.fastutil.shorts.Short2ObjectAVLTreeMap;
38
import it.unimi.dsi.fastutil.shorts.ShortArrays;
39
import java.util.ArrayList;
40
import java.util.Collection;
41
import java.util.Iterator;
42
import java.util.Map;
43
import java.util.Set;
44
import java.util.SortedMap;
45
import java.util.concurrent.atomic.AtomicInteger;
46
import org.gephi.graph.api.Element;
47

48
public abstract class ColumnStandardIndexImpl<K, T extends Element> implements ColumnIndexImpl<K, T> {
49

50
    // Lock (optional)
51
    protected final TableLockImpl lock;
52
    // Data
53
    protected final ColumnImpl column;
54
    protected final ValueSet<K, T> nullSet;
55
    protected Map<K, ValueSet<K, T>> map;
56
    // Variable
57
    protected int elements;
58
    // Version
59
    protected final AtomicInteger version = new AtomicInteger(Integer.MIN_VALUE);
1 ✔
60

61
    protected ColumnStandardIndexImpl(ColumnImpl column) {
1 ✔
62
        this.column = column;
1 ✔
63
        this.nullSet = new ValueSet<>(null);
1 ✔
64
        this.lock = column.table != null && column.table.configuration.isEnableAutoLocking() ? new TableLockImpl()
1 ✔
65
                : null;
1 ✔
66
    }
1 ✔
67

68
    protected static boolean isSupportedType(ColumnImpl col) {
69
        return !col.isDynamicAttribute();
1 ✔
70
    }
71

72
    @Override
73
    public K putValue(T element, K value) {
74
        lock();
1 ✔
75
        try {
76
            return put(element, value);
1 ✔
77
        } finally {
78
            unlock();
1 ✔
79
        }
80
    }
81

82
    private K put(T element, K value) {
83
        if (value == null) {
1 ✔
84
            if (nullSet.add(element)) {
1 ✔
85
                elements++;
1 ✔
86
                version.incrementAndGet();
1 ✔
87
            }
88
        } else {
89
            ValueSet<K, T> set = getValueSet(value);
1 ✔
90
            if (set == null) {
1 ✔
91
                set = addValue(value);
1 ✔
92
            }
93
            value = set.value;
1 ✔
94

95
            if (set.add(element)) {
1 ✔
96
                elements++;
1 ✔
97
                version.incrementAndGet();
1 ✔
98
            }
99
        }
100
        return value;
1 ✔
101
    }
102

103
    @Override
104
    public void removeValue(T element, K value) {
105
        lock();
1 ✔
106
        try {
107
            // A concurrent set can have written a new value without moving the element to it yet
108
            if (!remove(element, value) && !remove(element, null)) {
1 ✔
109
                for (ValueSet<K, T> set : map.values()) {
1 ✔
110
                    if (set.contains(element)) {
1 ✔
111
                        remove(element, set.value);
1 ✔
112
                        break;
1 ✔
113
                    }
UNCOV
114
                }
×
115
            }
116
        } finally {
117
            unlock();
1 ✔
118
        }
119
    }
1 ✔
120

121
    @Override
122
    public K replaceValue(T element, K oldValue, K newValue) {
123
        lock();
1 ✔
124
        try {
125
            // An element not indexed under its old value is left out, it's indexed with its current value when added.
126
            // The index of a column removed meanwhile is destroyed.
127
            if (map != null && remove(element, oldValue)) {
1 ✔
128
                return put(element, newValue);
1 ✔
129
            }
130
            return newValue;
1 ✔
131
        } finally {
132
            unlock();
1 ✔
133
        }
134
    }
135

136
    private boolean remove(T element, K value) {
137
        ValueSet<K, T> set = getValueSet(value);
1 ✔
138
        if (set == null || !set.remove(element)) {
1 ✔
139
            return false;
1 ✔
140
        }
141
        elements--;
1 ✔
142
        version.incrementAndGet();
1 ✔
143
        if (value != null && set.isEmpty()) {
1 ✔
144
            removeValue(value);
1 ✔
145
        }
146
        return true;
1 ✔
147
    }
148

149
    protected int getCount(K value) {
150
        lock();
1 ✔
151
        try {
152
            if (value == null) {
1 ✔
153
                return nullSet.size();
1 ✔
154
            }
155
            ValueSet<K, T> valueSet = getValueSet(value);
1 ✔
156
            if (valueSet != null) {
1 ✔
157
                return valueSet.size();
1 ✔
158
            } else {
159
                return 0;
1 ✔
160
            }
161
        } finally {
162
            unlock();
1 ✔
163
        }
164
    }
165

166
    @Override
167
    public int count(K value) {
168
        return getCount(value);
1 ✔
169
    }
170

171
    @Override
172
    public Collection<K> values() {
173
        lock();
1 ✔
174
        try {
175
            return new ArrayList<>(new WithNullDecorator());
1 ✔
176
        } finally {
177
            unlock();
1 ✔
178
        }
179
    }
180

181
    @Override
182
    public int countValues() {
183
        return (nullSet.isEmpty() ? 0 : 1) + map.size();
1 ✔
184
    }
185

186
    @Override
187
    public int countElements() {
188
        return elements;
1 ✔
189
    }
190

191
    @Override
192
    public Number getMinValue() {
193
        lock();
1 ✔
194
        try {
195
            if (isSortable()) {
1 ✔
196
                if (map.isEmpty()) {
1 ✔
197
                    return null;
1 ✔
198
                } else {
199
                    return (Number) ((SortedMap) map).firstKey();
1 ✔
200
                }
201
            } else {
202
                throw new UnsupportedOperationException("'" + column.getId() + "' is not a sortable column (" + column
1 ✔
203
                        .getTypeClass().getSimpleName() + ").");
1 ✔
204
            }
205
        } finally {
206
            unlock();
1 ✔
207
        }
208
    }
209

210
    @Override
211
    public Number getMaxValue() {
212
        lock();
1 ✔
213
        try {
214
            if (isSortable()) {
1 ✔
215
                if (map.isEmpty()) {
1 ✔
216
                    return null;
1 ✔
217
                } else {
218
                    return (Number) ((SortedMap) map).lastKey();
1 ✔
219
                }
220
            } else {
221
                throw new UnsupportedOperationException("'" + column.getId() + "' is not a sortable column (" + column
1 ✔
222
                        .getTypeClass().getSimpleName() + ").");
1 ✔
223
            }
224
        } finally {
225
            unlock();
1 ✔
226
        }
227
    }
228

229
    @Override
230
    public void destroy() {
231
        lock();
1 ✔
232
        try {
233
            map = null;
1 ✔
234
            nullSet.clear();
1 ✔
235
            elements = 0;
1 ✔
236
            version.incrementAndGet();
1 ✔
237
        } finally {
238
            unlock();
1 ✔
239
        }
240
    }
1 ✔
241

242
    @Override
243
    public void clear() {
244
        lock();
1 ✔
245
        try {
246
            map.clear();
1 ✔
247
            nullSet.clear();
1 ✔
248
            elements = 0;
1 ✔
249
            version.incrementAndGet();
1 ✔
250
        } finally {
251
            unlock();
1 ✔
252
        }
253
    }
1 ✔
254

255
    @Override
256
    public Iterator<Map.Entry<K, ? extends Set<T>>> iterator() {
257
        return new EntryIterator();
1 ✔
258
    }
259

260
    @Override
261
    public Iterable<T> get(K value) {
262
        lock();
1 ✔
263
        ValueSet<K, T> valueSet = getValueSet(value);
1 ✔
264
        if (valueSet == null) {
1 ✔
265
            unlock();
1 ✔
266
            return ValueSet.EMPTY;
1 ✔
267
        }
268
        return new LockableIterable<>(valueSet.set);
1 ✔
269
    }
270

271
    protected ValueSet<K, T> getValueSet(K value) {
272
        if (value == null) {
1 ✔
273
            return nullSet;
1 ✔
274
        }
275
        return map.get(value);
1 ✔
276
    }
277

278
    protected void removeValue(K value) {
279
        map.remove(value);
1 ✔
280
    }
1 ✔
281

282
    protected ValueSet<K, T> addValue(K value) {
283
        ValueSet<K, T> valueSet = new ValueSet<>(value);
1 ✔
284
        map.put(value, valueSet);
1 ✔
285
        return valueSet;
1 ✔
286
    }
287

288
    @Override
289
    public boolean isSortable() {
290
        return Number.class.isAssignableFrom(column.getTypeClass()) && map instanceof SortedMap;
1 ✔
291
    }
292

293
    @Override
294
    public ColumnImpl getColumn() {
295
        return column;
1 ✔
296
    }
297

298
    @Override
299
    public int getVersion() {
300
        return version.get();
1 ✔
301
    }
302

303
    void lock() {
304
        if (lock != null) {
1 ✔
305
            lock.lock();
1 ✔
306
        }
307
    }
1 ✔
308

309
    void unlock() {
310
        if (lock != null) {
1 ✔
311
            lock.unlock();
1 ✔
312
        }
313
    }
1 ✔
314

315
    protected static class DefaultStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Object, T> {
316

317
        public DefaultStandardIndex(ColumnImpl column) {
318
            super(column);
1 ✔
319

320
            map = new Object2ObjectOpenHashMap<>();
1 ✔
321
        }
1 ✔
322
    }
323

324
    protected static class BooleanStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Boolean, T> {
325

326
        public BooleanStandardIndex(ColumnImpl column) {
327
            super(column);
1 ✔
328

329
            map = new Object2ObjectOpenHashMap<>();
1 ✔
330
        }
1 ✔
331
    }
332

333
    protected static class DoubleStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Double, T> {
334

335
        public DoubleStandardIndex(ColumnImpl column) {
336
            super(column);
1 ✔
337

338
            map = new Double2ObjectAVLTreeMap<>();
1 ✔
339
        }
1 ✔
340
    }
341

342
    protected static class IntegerStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Integer, T> {
343

344
        public IntegerStandardIndex(ColumnImpl column) {
345
            super(column);
1 ✔
346

347
            map = new Int2ObjectAVLTreeMap<>();
1 ✔
348
        }
1 ✔
349
    }
350

351
    protected static class FloatStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Float, T> {
352

353
        public FloatStandardIndex(ColumnImpl column) {
354
            super(column);
1 ✔
355

356
            map = new Float2ObjectAVLTreeMap<>();
1 ✔
357
        }
1 ✔
358
    }
359

360
    protected static class LongStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Long, T> {
361

362
        public LongStandardIndex(ColumnImpl column) {
363
            super(column);
1 ✔
364

365
            map = new Long2ObjectAVLTreeMap<>();
1 ✔
366
        }
1 ✔
367
    }
368

369
    protected static class ShortStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Short, T> {
370

371
        public ShortStandardIndex(ColumnImpl column) {
372
            super(column);
1 ✔
373

374
            map = new Short2ObjectAVLTreeMap<>();
1 ✔
375
        }
1 ✔
376
    }
377

378
    protected static class ByteStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Byte, T> {
379

380
        public ByteStandardIndex(ColumnImpl column) {
381
            super(column);
1 ✔
382

383
            map = new Byte2ObjectAVLTreeMap<>();
1 ✔
384
        }
1 ✔
385
    }
386

387
    protected static class GenericNumberStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Number, T> {
388

389
        public GenericNumberStandardIndex(ColumnImpl column) {
390
            super(column);
1 ✔
391

392
            map = new Object2ObjectAVLTreeMap<>();
1 ✔
393
        }
1 ✔
394
    }
395

396
    protected static class CharStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Character, T> {
397

398
        public CharStandardIndex(ColumnImpl column) {
399
            super(column);
1 ✔
400

401
            map = new Char2ObjectAVLTreeMap<>();
1 ✔
402
        }
1 ✔
403
    }
404

405
    protected static class DefaultArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Object[], T> {
406

407
        public DefaultArrayStandardIndex(ColumnImpl column) {
408
            super(column);
1 ✔
409

410
            map = new Object2ObjectOpenCustomHashMap<>(ObjectArrays.HASH_STRATEGY);
1 ✔
411
        }
1 ✔
412
    }
413

414
    protected static class BooleanArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<boolean[], T> {
415

416
        public BooleanArrayStandardIndex(ColumnImpl column) {
417
            super(column);
1 ✔
418

419
            map = new Object2ObjectOpenCustomHashMap<>(BooleanArrays.HASH_STRATEGY);
1 ✔
420
        }
1 ✔
421
    }
422

423
    protected static class DoubleArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<double[], T> {
424

425
        public DoubleArrayStandardIndex(ColumnImpl column) {
426
            super(column);
1 ✔
427

428
            map = new Object2ObjectOpenCustomHashMap<>(DoubleArrays.HASH_STRATEGY);
1 ✔
429
        }
1 ✔
430
    }
431

432
    protected static class IntegerArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<int[], T> {
433

434
        public IntegerArrayStandardIndex(ColumnImpl column) {
435
            super(column);
1 ✔
436

437
            map = new Object2ObjectOpenCustomHashMap<>(IntArrays.HASH_STRATEGY);
1 ✔
438
        }
1 ✔
439
    }
440

441
    protected static class FloatArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<float[], T> {
442

443
        public FloatArrayStandardIndex(ColumnImpl column) {
444
            super(column);
1 ✔
445

446
            map = new Object2ObjectOpenCustomHashMap<>(FloatArrays.HASH_STRATEGY);
1 ✔
447
        }
1 ✔
448
    }
449

450
    protected static class LongArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<long[], T> {
451

452
        public LongArrayStandardIndex(ColumnImpl column) {
453
            super(column);
1 ✔
454

455
            map = new Object2ObjectOpenCustomHashMap<>(LongArrays.HASH_STRATEGY);
1 ✔
456
        }
1 ✔
457
    }
458

459
    protected static class ShortArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<short[], T> {
460

461
        public ShortArrayStandardIndex(ColumnImpl column) {
462
            super(column);
1 ✔
463

464
            map = new Object2ObjectOpenCustomHashMap<>(ShortArrays.HASH_STRATEGY);
1 ✔
465
        }
1 ✔
466
    }
467

468
    protected static class ByteArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<byte[], T> {
469

470
        public ByteArrayStandardIndex(ColumnImpl column) {
471
            super(column);
1 ✔
472

473
            map = new Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
1 ✔
474
        }
1 ✔
475
    }
476

477
    protected static class CharArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<char[], T> {
478

479
        public CharArrayStandardIndex(ColumnImpl column) {
480
            super(column);
1 ✔
481

482
            map = new Object2ObjectOpenCustomHashMap<>(CharArrays.HASH_STRATEGY);
1 ✔
483
        }
1 ✔
484
    }
485

486
    protected static final class ValueSet<K, T> implements Set<T> {
487

488
        protected static ValueSet EMPTY = new ValueSet(null);
1 ✔
489
        protected final K value;
490
        private final Set<T> set;
491

492
        public ValueSet(K value) {
1 ✔
493
            this.value = value;
1 ✔
494
            this.set = new ObjectOpenHashSet<>();
1 ✔
495
        }
1 ✔
496

497
        @Override
498
        public int size() {
499
            return set.size();
1 ✔
500
        }
501

502
        @Override
503
        public boolean isEmpty() {
504
            return set.isEmpty();
1 ✔
505
        }
506

507
        @Override
508
        public boolean contains(Object o) {
509
            return set.contains(o);
1 ✔
510
        }
511

512
        @Override
513
        public Iterator<T> iterator() {
514
            return set.iterator();
1 ✔
515
        }
516

517
        @Override
518
        public Object[] toArray() {
519
            return set.toArray();
×
520
        }
521

522
        @Override
523
        public <T> T[] toArray(T[] ts) {
524
            return set.toArray(ts);
×
525
        }
526

527
        @Override
528
        public boolean add(T e) {
529
            return set.add(e);
1 ✔
530
        }
531

532
        @Override
533
        public boolean remove(Object o) {
534
            return set.remove(o);
1 ✔
535
        }
536

537
        @Override
538
        public boolean containsAll(Collection<?> clctn) {
539
            return set.containsAll(clctn);
×
540
        }
541

542
        @Override
543
        public boolean addAll(Collection<? extends T> clctn) {
544
            throw new UnsupportedOperationException("Not supported operation.");
×
545
        }
546

547
        @Override
548
        public boolean retainAll(Collection<?> clctn) {
549
            throw new UnsupportedOperationException("Not supported operation.");
×
550
        }
551

552
        @Override
553
        public boolean removeAll(Collection<?> clctn) {
554
            throw new UnsupportedOperationException("Not supported operation.");
×
555
        }
556

557
        @Override
558
        public void clear() {
559
            set.clear();
1 ✔
560
        }
1 ✔
561

562
        @Override
563
        public boolean equals(Object o) {
564
            return set.equals(o);
1 ✔
565
        }
566

567
        @Override
568
        public int hashCode() {
569
            return set.hashCode();
×
570
        }
571
    }
572

573
    protected final class WithNullDecorator implements Collection<K> {
1 ✔
574

575
        private boolean hasNull() {
576
            return !nullSet.isEmpty();
1 ✔
577
        }
578

579
        @Override
580
        public int size() {
581
            return (hasNull() ? 1 : 0) + map.size();
×
582
        }
583

584
        @Override
585
        public boolean isEmpty() {
586
            return !hasNull() && map.isEmpty();
×
587
        }
588

589
        @Override
590
        public boolean contains(Object o) {
591
            if (o == null && hasNull()) {
×
592
                return true;
×
593
            } else if (o != null) {
×
594
                return map.containsKey((K) o);
×
595
            }
596
            return false;
×
597
        }
598

599
        @Override
600
        public Iterator<K> iterator() {
601
            return new WithNullDecorator.WithNullIterator();
×
602
        }
603

604
        @Override
605
        public Object[] toArray() {
606
            if (hasNull()) {
1 ✔
607
                Object[] res = new Object[map.size() + 1];
1 ✔
608
                res[0] = null;
1 ✔
609
                System.arraycopy(map.keySet().toArray(), 0, res, 1, map.size());
1 ✔
610
                return res;
1 ✔
611
            } else {
612
                return map.keySet().toArray();
1 ✔
613
            }
614
        }
615

616
        @Override
617
        public <V> V[] toArray(V[] array) {
618
            if (hasNull()) {
×
619
                if (array.length < size()) {
×
620
                    array = (V[]) java.lang.reflect.Array
×
621
                            .newInstance(array.getClass().getComponentType(), map.size() + 1);
×
622
                }
623
                array[0] = null;
×
624
                System.arraycopy(map.keySet().toArray(), 0, array, 1, map.size());
×
625
                return array;
×
626
            } else {
627
                return map.keySet().toArray(array);
×
628
            }
629
        }
630

631
        @Override
632
        public boolean add(K e) {
633
            throw new UnsupportedOperationException("Not supported");
×
634
        }
635

636
        @Override
637
        public boolean remove(Object o) {
638
            throw new UnsupportedOperationException("Not supported");
×
639
        }
640

641
        @Override
642
        public boolean containsAll(Collection clctn) {
643
            for (Object o : clctn) {
×
644
                if (o == null && nullSet.isEmpty()) {
×
645
                    return false;
×
646
                } else if (o != null && !map.containsKey((K) o)) {
×
647
                    return false;
×
648
                }
649
            }
×
650
            return true;
×
651
        }
652

653
        @Override
654
        public boolean addAll(Collection clctn) {
655
            throw new UnsupportedOperationException("Not supported");
×
656
        }
657

658
        @Override
659
        public boolean removeAll(Collection clctn) {
660
            throw new UnsupportedOperationException("Not supported");
×
661
        }
662

663
        @Override
664
        public boolean retainAll(Collection clctn) {
665
            throw new UnsupportedOperationException("Not supported");
×
666
        }
667

668
        @Override
669
        public void clear() {
670
            throw new UnsupportedOperationException("Not supported");
×
671
        }
672

673
        private final class WithNullIterator implements Iterator<K> {
674

675
            private final Iterator<K> mapIterator;
676
            private boolean hasNull;
677

678
            public WithNullIterator() {
×
679
                hasNull = hasNull();
×
680
                mapIterator = map.keySet().iterator();
×
681
            }
×
682

683
            @Override
684
            public boolean hasNext() {
685
                if (hasNull) {
×
686
                    return true;
×
687
                }
688
                return mapIterator.hasNext();
×
689
            }
690

691
            @Override
692
            public K next() {
693
                if (hasNull) {
×
694
                    hasNull = false;
×
695
                    return null;
×
696
                }
697
                return mapIterator.next();
×
698
            }
699

700
            @Override
701
            public void remove() {
702
                throw new UnsupportedOperationException("Not supported operation.");
×
703
            }
704
        }
705
    }
706

707
    private final class EntryIterator implements Iterator<Map.Entry<K, ? extends Set<T>>> {
708

709
        private final Iterator<Map.Entry<K, ValueSet<K, T>>> mapIterator;
710
        private NullEntry nullEntry;
711

712
        public EntryIterator() {
1 ✔
713
            if (!nullSet.isEmpty()) {
1 ✔
714
                nullEntry = new NullEntry();
1 ✔
715
            }
716
            mapIterator = map.entrySet().iterator();
1 ✔
717
        }
1 ✔
718

719
        @Override
720
        public boolean hasNext() {
721
            if (nullEntry != null) {
1 ✔
722
                return true;
1 ✔
723
            }
724
            return mapIterator.hasNext();
1 ✔
725
        }
726

727
        @Override
728
        public Map.Entry<K, ? extends Set<T>> next() {
729
            if (nullEntry != null) {
1 ✔
730
                NullEntry ne = nullEntry;
1 ✔
731
                nullEntry = null;
1 ✔
732
                return ne;
1 ✔
733
            }
734
            return mapIterator.next();
1 ✔
735
        }
736

737
        @Override
738
        public void remove() {
739
            throw new UnsupportedOperationException("Not supported operation.");
×
740
        }
741
    }
742

743
    private class NullEntry implements Map.Entry<K, Set<T>> {
1 ✔
744

745
        @Override
746
        public K getKey() {
747
            return null;
1 ✔
748
        }
749

750
        @Override
751
        public Set<T> getValue() {
752
            return nullSet;
1 ✔
753
        }
754

755
        @Override
756
        public Set<T> setValue(Set<T> v) {
757
            throw new UnsupportedOperationException("Not supported operation.");
1 ✔
758
        }
759
    }
760

761
    private class LockableIterable<E> implements Iterable<E> {
762

763
        private final Iterable<E> ite;
764

765
        public LockableIterable(Iterable<E> ite) {
1 ✔
766
            this.ite = ite;
1 ✔
767
        }
1 ✔
768

769
        @Override
770
        public Iterator<E> iterator() {
771
            return new LockableIterator<>(ite.iterator());
1 ✔
772
        }
773
    }
774

775
    private class LockableIterator<E> implements Iterator<E> {
776

777
        private final Iterator<E> itr;
778

779
        public LockableIterator(Iterator<E> itr) {
1 ✔
780
            this.itr = itr;
1 ✔
781
        }
1 ✔
782

783
        @Override
784
        public boolean hasNext() {
785
            boolean n = itr.hasNext();
1 ✔
786
            if (!n && lock != null) {
1 ✔
787
                lock.unlock();
1 ✔
788
            }
789
            return n;
1 ✔
790
        }
791

792
        @Override
793
        public E next() {
794
            return itr.next();
1 ✔
795
        }
796

797
        @Override
798
        public void remove() {
799
            throw new UnsupportedOperationException("Not supported.");
×
800
        }
801
    }
802
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc