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

gephi / graphstore / #656

25 Oct 2026 01:38PM UTC coverage: 91.912% (-0.04%) from 91.954%
#656

push

web-flow
Return an ElementIterable from the column index get and release its lock (#362)

* Return a snapshot from the column index get and entry iterator

Index.get locked the column index when called and unlocked it when the
iterator was exhausted, so a get that was never iterated or a loop that
broke early kept the lock, and setting an attribute inside the loop could
deadlock with a setter on a view index. Non-indexed, degree and edge type
columns held the graph read lock the same way. get and the entry iterator
now copy the elements under the lock and return the copy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Return an ElementIterable from the column index get and take the lock when iterating

Index.get took the index lock when called and released it only when the
iterator was exhausted, so a result that was never iterated or a loop that
stopped early kept the lock with no way to release it. Non-indexed, degree
and edge type columns held the graph read lock the same way.

get now returns an ElementIterable, like Graph.getNodes: the lock is taken
when iterator() is called and released when the iterator is exhausted or on
doBreak(). Each iteration takes and releases its own hold, and doBreak after
exhaustion or twice does nothing. The snapshot of the previous commit is
reverted, the entry iterator is unchanged. Code compiled against the
Iterable return type must be recompiled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Release every open iteration of an index get result and never leak the graph lock

doBreak only released the latest iterator of a result, so nested loops over
the same result kept the outer lock. parallelStream unlocked the lock from a
worker thread. A non-indexed column removed during an iteration of get,
count, values, getMinValue or getMaxValue left the graph read lock held by
the graph iterator.

doBreak now releases every iteration of the result still holding the lock,
parallelStream throws Unsupport... (continued)

145 of 166 new or added lines in 6 files covered. (87.35%)

12466 of 13563 relevant lines covered (91.91%)

0.92 hits per line

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

80.75
/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.lang.reflect.Array;
40
import java.util.ArrayList;
41
import java.util.Collection;
42
import java.util.Collections;
43
import java.util.Iterator;
44
import java.util.Map;
45
import java.util.NoSuchElementException;
46
import java.util.Set;
47
import java.util.SortedMap;
48
import java.util.Spliterator;
49
import java.util.concurrent.atomic.AtomicInteger;
50
import java.util.stream.Stream;
51
import org.gephi.graph.api.Element;
52
import org.gephi.graph.api.ElementIterable;
53

54
public abstract class ColumnStandardIndexImpl<K, T extends Element> implements ColumnIndexImpl<K, T> {
55

56
    // Lock (optional)
57
    protected final TableLockImpl lock;
58
    // Data
59
    protected final ColumnImpl column;
60
    protected final ValueSet<K, T> nullSet;
61
    protected Map<K, ValueSet<K, T>> map;
62
    // Variable
63
    protected int elements;
64
    // Version
65
    protected final AtomicInteger version = new AtomicInteger(Integer.MIN_VALUE);
1 ✔
66

67
    protected ColumnStandardIndexImpl(ColumnImpl column) {
1 ✔
68
        this.column = column;
1 ✔
69
        this.nullSet = new ValueSet<>(null);
1 ✔
70
        this.lock = column.table != null && column.table.configuration.isEnableAutoLocking() ? new TableLockImpl()
1 ✔
71
                : null;
1 ✔
72
    }
1 ✔
73

74
    protected static boolean isSupportedType(ColumnImpl col) {
75
        return !col.isDynamicAttribute();
1 ✔
76
    }
77

78
    @Override
79
    public K putValue(T element, K value) {
80
        lock();
1 ✔
81
        try {
82
            return put(element, value);
1 ✔
83
        } finally {
84
            unlock();
1 ✔
85
        }
86
    }
87

88
    private K put(T element, K value) {
89
        if (value == null) {
1 ✔
90
            if (nullSet.add(element)) {
1 ✔
91
                elements++;
1 ✔
92
                version.incrementAndGet();
1 ✔
93
            }
94
        } else {
95
            ValueSet<K, T> set = getValueSet(value);
1 ✔
96
            if (set == null) {
1 ✔
97
                set = addValue(value);
1 ✔
98
            }
99
            value = set.value;
1 ✔
100

101
            if (set.add(element)) {
1 ✔
102
                elements++;
1 ✔
103
                version.incrementAndGet();
1 ✔
104
            }
105
        }
106
        return value;
1 ✔
107
    }
108

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

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

142
    private boolean remove(T element, K value) {
143
        ValueSet<K, T> set = getValueSet(value);
1 ✔
144
        if (set == null || !set.remove(element)) {
1 ✔
145
            return false;
1 ✔
146
        }
147
        elements--;
1 ✔
148
        version.incrementAndGet();
1 ✔
149
        if (value != null && set.isEmpty()) {
1 ✔
150
            removeValue(value);
1 ✔
151
        }
152
        return true;
1 ✔
153
    }
154

155
    protected int getCount(K value) {
156
        lock();
1 ✔
157
        try {
158
            checkNotDestroyed();
1 ✔
159
            if (value == null) {
1 ✔
160
                return nullSet.size();
1 ✔
161
            }
162
            ValueSet<K, T> valueSet = getValueSet(value);
1 ✔
163
            if (valueSet != null) {
1 ✔
164
                return valueSet.size();
1 ✔
165
            } else {
166
                return 0;
1 ✔
167
            }
168
        } finally {
169
            unlock();
1 ✔
170
        }
171
    }
172

173
    @Override
174
    public int count(K value) {
175
        return getCount(value);
1 ✔
176
    }
177

178
    @Override
179
    public Collection<K> values() {
180
        lock();
1 ✔
181
        try {
182
            checkNotDestroyed();
1 ✔
183
            return new ArrayList<>(new WithNullDecorator());
1 ✔
184
        } finally {
185
            unlock();
1 ✔
186
        }
187
    }
188

189
    @Override
190
    public int countValues() {
191
        checkNotDestroyed();
1 ✔
192
        return (nullSet.isEmpty() ? 0 : 1) + map.size();
1 ✔
193
    }
194

195
    @Override
196
    public int countElements() {
197
        return elements;
1 ✔
198
    }
199

200
    @Override
201
    public Number getMinValue() {
202
        lock();
1 ✔
203
        try {
204
            if (isSortable()) {
1 ✔
205
                if (map.isEmpty()) {
1 ✔
206
                    return null;
1 ✔
207
                } else {
208
                    return (Number) ((SortedMap) map).firstKey();
1 ✔
209
                }
210
            } else {
211
                throw new UnsupportedOperationException("'" + column.getId() + "' is not a sortable column (" + column
1 ✔
212
                        .getTypeClass().getSimpleName() + ").");
1 ✔
213
            }
214
        } finally {
215
            unlock();
1 ✔
216
        }
217
    }
218

219
    @Override
220
    public Number getMaxValue() {
221
        lock();
1 ✔
222
        try {
223
            if (isSortable()) {
1 ✔
224
                if (map.isEmpty()) {
1 ✔
225
                    return null;
1 ✔
226
                } else {
227
                    return (Number) ((SortedMap) map).lastKey();
1 ✔
228
                }
229
            } else {
230
                throw new UnsupportedOperationException("'" + column.getId() + "' is not a sortable column (" + column
1 ✔
231
                        .getTypeClass().getSimpleName() + ").");
1 ✔
232
            }
233
        } finally {
234
            unlock();
1 ✔
235
        }
236
    }
237

238
    @Override
239
    public void destroy() {
240
        lock();
1 ✔
241
        try {
242
            map = null;
1 ✔
243
            nullSet.clear();
1 ✔
244
            elements = 0;
1 ✔
245
            version.incrementAndGet();
1 ✔
246
        } finally {
247
            unlock();
1 ✔
248
        }
249
    }
1 ✔
250

251
    @Override
252
    public void clear() {
253
        lock();
1 ✔
254
        try {
255
            map.clear();
1 ✔
256
            nullSet.clear();
1 ✔
257
            elements = 0;
1 ✔
258
            version.incrementAndGet();
1 ✔
259
        } finally {
260
            unlock();
1 ✔
261
        }
262
    }
1 ✔
263

264
    @Override
265
    public Iterator<Map.Entry<K, ? extends Set<T>>> iterator() {
266
        checkNotDestroyed();
1 ✔
267
        return new EntryIterator();
1 ✔
268
    }
269

270
    @Override
271
    public ElementIterable<T> get(K value) {
272
        return new ValueIterable(value);
1 ✔
273
    }
274

275
    // The index of a removed column is destroyed
276
    private void checkNotDestroyed() {
277
        if (map == null) {
1 ✔
278
            throw new IllegalArgumentException("The column does not exist");
1 ✔
279
        }
280
    }
1 ✔
281

282
    protected ValueSet<K, T> getValueSet(K value) {
283
        if (value == null) {
1 ✔
284
            return nullSet;
1 ✔
285
        }
286
        return map.get(value);
1 ✔
287
    }
288

289
    protected void removeValue(K value) {
290
        map.remove(value);
1 ✔
291
    }
1 ✔
292

293
    protected ValueSet<K, T> addValue(K value) {
294
        ValueSet<K, T> valueSet = new ValueSet<>(value);
1 ✔
295
        map.put(value, valueSet);
1 ✔
296
        return valueSet;
1 ✔
297
    }
298

299
    @Override
300
    public boolean isSortable() {
301
        return Number.class.isAssignableFrom(column.getTypeClass()) && map instanceof SortedMap;
1 ✔
302
    }
303

304
    @Override
305
    public ColumnImpl getColumn() {
306
        return column;
1 ✔
307
    }
308

309
    @Override
310
    public int getVersion() {
311
        return version.get();
1 ✔
312
    }
313

314
    void lock() {
315
        if (lock != null) {
1 ✔
316
            lock.lock();
1 ✔
317
        }
318
    }
1 ✔
319

320
    void unlock() {
321
        if (lock != null) {
1 ✔
322
            lock.unlock();
1 ✔
323
        }
324
    }
1 ✔
325

326
    protected static class DefaultStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Object, T> {
327

328
        public DefaultStandardIndex(ColumnImpl column) {
329
            super(column);
1 ✔
330

331
            map = new Object2ObjectOpenHashMap<>();
1 ✔
332
        }
1 ✔
333
    }
334

335
    protected static class BooleanStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Boolean, T> {
336

337
        public BooleanStandardIndex(ColumnImpl column) {
338
            super(column);
1 ✔
339

340
            map = new Object2ObjectOpenHashMap<>();
1 ✔
341
        }
1 ✔
342
    }
343

344
    protected static class DoubleStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Double, T> {
345

346
        public DoubleStandardIndex(ColumnImpl column) {
347
            super(column);
1 ✔
348

349
            map = new Double2ObjectAVLTreeMap<>();
1 ✔
350
        }
1 ✔
351
    }
352

353
    protected static class IntegerStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Integer, T> {
354

355
        public IntegerStandardIndex(ColumnImpl column) {
356
            super(column);
1 ✔
357

358
            map = new Int2ObjectAVLTreeMap<>();
1 ✔
359
        }
1 ✔
360
    }
361

362
    protected static class FloatStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Float, T> {
363

364
        public FloatStandardIndex(ColumnImpl column) {
365
            super(column);
1 ✔
366

367
            map = new Float2ObjectAVLTreeMap<>();
1 ✔
368
        }
1 ✔
369
    }
370

371
    protected static class LongStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Long, T> {
372

373
        public LongStandardIndex(ColumnImpl column) {
374
            super(column);
1 ✔
375

376
            map = new Long2ObjectAVLTreeMap<>();
1 ✔
377
        }
1 ✔
378
    }
379

380
    protected static class ShortStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Short, T> {
381

382
        public ShortStandardIndex(ColumnImpl column) {
383
            super(column);
1 ✔
384

385
            map = new Short2ObjectAVLTreeMap<>();
1 ✔
386
        }
1 ✔
387
    }
388

389
    protected static class ByteStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Byte, T> {
390

391
        public ByteStandardIndex(ColumnImpl column) {
392
            super(column);
1 ✔
393

394
            map = new Byte2ObjectAVLTreeMap<>();
1 ✔
395
        }
1 ✔
396
    }
397

398
    protected static class GenericNumberStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Number, T> {
399

400
        public GenericNumberStandardIndex(ColumnImpl column) {
401
            super(column);
1 ✔
402

403
            map = new Object2ObjectAVLTreeMap<>();
1 ✔
404
        }
1 ✔
405
    }
406

407
    protected static class CharStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Character, T> {
408

409
        public CharStandardIndex(ColumnImpl column) {
410
            super(column);
1 ✔
411

412
            map = new Char2ObjectAVLTreeMap<>();
1 ✔
413
        }
1 ✔
414
    }
415

416
    protected static class DefaultArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<Object[], T> {
417

418
        public DefaultArrayStandardIndex(ColumnImpl column) {
419
            super(column);
1 ✔
420

421
            map = new Object2ObjectOpenCustomHashMap<>(ObjectArrays.HASH_STRATEGY);
1 ✔
422
        }
1 ✔
423
    }
424

425
    protected static class BooleanArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<boolean[], T> {
426

427
        public BooleanArrayStandardIndex(ColumnImpl column) {
428
            super(column);
1 ✔
429

430
            map = new Object2ObjectOpenCustomHashMap<>(BooleanArrays.HASH_STRATEGY);
1 ✔
431
        }
1 ✔
432
    }
433

434
    protected static class DoubleArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<double[], T> {
435

436
        public DoubleArrayStandardIndex(ColumnImpl column) {
437
            super(column);
1 ✔
438

439
            map = new Object2ObjectOpenCustomHashMap<>(DoubleArrays.HASH_STRATEGY);
1 ✔
440
        }
1 ✔
441
    }
442

443
    protected static class IntegerArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<int[], T> {
444

445
        public IntegerArrayStandardIndex(ColumnImpl column) {
446
            super(column);
1 ✔
447

448
            map = new Object2ObjectOpenCustomHashMap<>(IntArrays.HASH_STRATEGY);
1 ✔
449
        }
1 ✔
450
    }
451

452
    protected static class FloatArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<float[], T> {
453

454
        public FloatArrayStandardIndex(ColumnImpl column) {
455
            super(column);
1 ✔
456

457
            map = new Object2ObjectOpenCustomHashMap<>(FloatArrays.HASH_STRATEGY);
1 ✔
458
        }
1 ✔
459
    }
460

461
    protected static class LongArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<long[], T> {
462

463
        public LongArrayStandardIndex(ColumnImpl column) {
464
            super(column);
1 ✔
465

466
            map = new Object2ObjectOpenCustomHashMap<>(LongArrays.HASH_STRATEGY);
1 ✔
467
        }
1 ✔
468
    }
469

470
    protected static class ShortArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<short[], T> {
471

472
        public ShortArrayStandardIndex(ColumnImpl column) {
473
            super(column);
1 ✔
474

475
            map = new Object2ObjectOpenCustomHashMap<>(ShortArrays.HASH_STRATEGY);
1 ✔
476
        }
1 ✔
477
    }
478

479
    protected static class ByteArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<byte[], T> {
480

481
        public ByteArrayStandardIndex(ColumnImpl column) {
482
            super(column);
1 ✔
483

484
            map = new Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
1 ✔
485
        }
1 ✔
486
    }
487

488
    protected static class CharArrayStandardIndex<T extends Element> extends ColumnStandardIndexImpl<char[], T> {
489

490
        public CharArrayStandardIndex(ColumnImpl column) {
491
            super(column);
1 ✔
492

493
            map = new Object2ObjectOpenCustomHashMap<>(CharArrays.HASH_STRATEGY);
1 ✔
494
        }
1 ✔
495
    }
496

497
    protected static final class ValueSet<K, T> implements Set<T> {
498

499
        protected final K value;
500
        private final Set<T> set;
501

502
        public ValueSet(K value) {
1 ✔
503
            this.value = value;
1 ✔
504
            this.set = new ObjectOpenHashSet<>();
1 ✔
505
        }
1 ✔
506

507
        @Override
508
        public int size() {
509
            return set.size();
1 ✔
510
        }
511

512
        @Override
513
        public boolean isEmpty() {
514
            return set.isEmpty();
1 ✔
515
        }
516

517
        @Override
518
        public boolean contains(Object o) {
519
            return set.contains(o);
1 ✔
520
        }
521

522
        @Override
523
        public Iterator<T> iterator() {
524
            return set.iterator();
1 ✔
525
        }
526

527
        @Override
528
        public Object[] toArray() {
529
            return set.toArray();
1 ✔
530
        }
531

532
        @Override
533
        public <T> T[] toArray(T[] ts) {
534
            return set.toArray(ts);
×
535
        }
536

537
        @Override
538
        public boolean add(T e) {
539
            return set.add(e);
1 ✔
540
        }
541

542
        @Override
543
        public boolean remove(Object o) {
544
            return set.remove(o);
1 ✔
545
        }
546

547
        @Override
548
        public boolean containsAll(Collection<?> clctn) {
549
            return set.containsAll(clctn);
×
550
        }
551

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

557
        @Override
558
        public boolean retainAll(Collection<?> clctn) {
559
            throw new UnsupportedOperationException("Not supported operation.");
×
560
        }
561

562
        @Override
563
        public boolean removeAll(Collection<?> clctn) {
564
            throw new UnsupportedOperationException("Not supported operation.");
×
565
        }
566

567
        @Override
568
        public void clear() {
569
            set.clear();
1 ✔
570
        }
1 ✔
571

572
        @Override
573
        public boolean equals(Object o) {
574
            return set.equals(o);
1 ✔
575
        }
576

577
        @Override
578
        public int hashCode() {
579
            return set.hashCode();
×
580
        }
581
    }
582

583
    protected final class WithNullDecorator implements Collection<K> {
1 ✔
584

585
        private boolean hasNull() {
586
            return !nullSet.isEmpty();
1 ✔
587
        }
588

589
        @Override
590
        public int size() {
591
            return (hasNull() ? 1 : 0) + map.size();
×
592
        }
593

594
        @Override
595
        public boolean isEmpty() {
596
            return !hasNull() && map.isEmpty();
×
597
        }
598

599
        @Override
600
        public boolean contains(Object o) {
601
            if (o == null && hasNull()) {
×
602
                return true;
×
603
            } else if (o != null) {
×
604
                return map.containsKey((K) o);
×
605
            }
606
            return false;
×
607
        }
608

609
        @Override
610
        public Iterator<K> iterator() {
611
            return new WithNullDecorator.WithNullIterator();
×
612
        }
613

614
        @Override
615
        public Object[] toArray() {
616
            if (hasNull()) {
1 ✔
617
                Object[] res = new Object[map.size() + 1];
1 ✔
618
                res[0] = null;
1 ✔
619
                System.arraycopy(map.keySet().toArray(), 0, res, 1, map.size());
1 ✔
620
                return res;
1 ✔
621
            } else {
622
                return map.keySet().toArray();
1 ✔
623
            }
624
        }
625

626
        @Override
627
        public <V> V[] toArray(V[] array) {
628
            if (hasNull()) {
×
629
                if (array.length < size()) {
×
630
                    array = (V[]) java.lang.reflect.Array
×
631
                            .newInstance(array.getClass().getComponentType(), map.size() + 1);
×
632
                }
633
                array[0] = null;
×
634
                System.arraycopy(map.keySet().toArray(), 0, array, 1, map.size());
×
635
                return array;
×
636
            } else {
637
                return map.keySet().toArray(array);
×
638
            }
639
        }
640

641
        @Override
642
        public boolean add(K e) {
643
            throw new UnsupportedOperationException("Not supported");
×
644
        }
645

646
        @Override
647
        public boolean remove(Object o) {
648
            throw new UnsupportedOperationException("Not supported");
×
649
        }
650

651
        @Override
652
        public boolean containsAll(Collection clctn) {
653
            for (Object o : clctn) {
×
654
                if (o == null && nullSet.isEmpty()) {
×
655
                    return false;
×
656
                } else if (o != null && !map.containsKey((K) o)) {
×
657
                    return false;
×
658
                }
659
            }
×
660
            return true;
×
661
        }
662

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

668
        @Override
669
        public boolean removeAll(Collection clctn) {
670
            throw new UnsupportedOperationException("Not supported");
×
671
        }
672

673
        @Override
674
        public boolean retainAll(Collection clctn) {
675
            throw new UnsupportedOperationException("Not supported");
×
676
        }
677

678
        @Override
679
        public void clear() {
680
            throw new UnsupportedOperationException("Not supported");
×
681
        }
682

683
        private final class WithNullIterator implements Iterator<K> {
684

685
            private final Iterator<K> mapIterator;
686
            private boolean hasNull;
687

688
            public WithNullIterator() {
×
689
                hasNull = hasNull();
×
690
                mapIterator = map.keySet().iterator();
×
691
            }
×
692

693
            @Override
694
            public boolean hasNext() {
695
                if (hasNull) {
×
696
                    return true;
×
697
                }
698
                return mapIterator.hasNext();
×
699
            }
700

701
            @Override
702
            public K next() {
703
                if (hasNull) {
×
704
                    hasNull = false;
×
705
                    return null;
×
706
                }
707
                return mapIterator.next();
×
708
            }
709

710
            @Override
711
            public void remove() {
712
                throw new UnsupportedOperationException("Not supported operation.");
×
713
            }
714
        }
715
    }
716

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

719
        private final Iterator<Map.Entry<K, ValueSet<K, T>>> mapIterator;
720
        private NullEntry nullEntry;
721

722
        public EntryIterator() {
1 ✔
723
            if (!nullSet.isEmpty()) {
1 ✔
724
                nullEntry = new NullEntry();
1 ✔
725
            }
726
            mapIterator = map.entrySet().iterator();
1 ✔
727
        }
1 ✔
728

729
        @Override
730
        public boolean hasNext() {
731
            if (nullEntry != null) {
1 ✔
732
                return true;
1 ✔
733
            }
734
            return mapIterator.hasNext();
1 ✔
735
        }
736

737
        @Override
738
        public Map.Entry<K, ? extends Set<T>> next() {
739
            if (nullEntry != null) {
1 ✔
740
                NullEntry ne = nullEntry;
1 ✔
741
                nullEntry = null;
1 ✔
742
                return ne;
1 ✔
743
            }
744
            return mapIterator.next();
1 ✔
745
        }
746

747
        @Override
748
        public void remove() {
749
            throw new UnsupportedOperationException("Not supported operation.");
×
750
        }
751
    }
752

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

755
        @Override
756
        public K getKey() {
757
            return null;
1 ✔
758
        }
759

760
        @Override
761
        public Set<T> getValue() {
762
            return nullSet;
1 ✔
763
        }
764

765
        @Override
766
        public Set<T> setValue(Set<T> v) {
767
            throw new UnsupportedOperationException("Not supported operation.");
1 ✔
768
        }
769
    }
770

771
    private final class ValueIterable implements ElementIterable<T> {
772

773
        private final K value;
774
        // Most recently opened iterator that still holds the lock
775
        private ValueIterator last;
776

777
        public ValueIterable(K value) {
1 ✔
778
            this.value = value;
1 ✔
779
        }
1 ✔
780

781
        @Override
782
        public Iterator<T> iterator() {
783
            return new ValueIterator();
1 ✔
784
        }
785

786
        @Override
787
        public Stream<T> parallelStream() {
788
            throw new UnsupportedOperationException("Parallel stream not supported for this operation.");
1 ✔
789
        }
790

791
        @Override
792
        public T[] toArray() {
793
            lock();
1 ✔
794
            try {
NEW
795
                checkNotDestroyed();
×
NEW
796
                ValueSet<K, T> valueSet = getValueSet(value);
×
NEW
797
                T[] array = (T[]) Array.newInstance(column.table != null ? column.table.getElementClass()
×
NEW
798
                        : Element.class, valueSet != null ? valueSet.size() : 0);
×
NEW
799
                return valueSet != null ? valueSet.toArray(array) : array;
×
800
            } finally {
801
                unlock();
1 ✔
802
            }
803
        }
804

805
        @Override
806
        public Collection<T> toCollection() {
807
            lock();
1 ✔
808
            try {
809
                checkNotDestroyed();
1 ✔
810
                ValueSet<K, T> valueSet = getValueSet(value);
1 ✔
811
                return valueSet != null ? new ArrayList<>(valueSet) : new ArrayList<>();
1 ✔
812
            } finally {
813
                unlock();
1 ✔
814
            }
815
        }
816

817
        @Override
818
        public Set<T> toSet() {
NEW
819
            lock();
×
820
            try {
NEW
821
                checkNotDestroyed();
×
NEW
822
                ValueSet<K, T> valueSet = getValueSet(value);
×
NEW
823
                return valueSet != null ? new ObjectOpenHashSet<>(valueSet) : new ObjectOpenHashSet<>();
×
824
            } finally {
NEW
825
                unlock();
×
826
            }
827
        }
828

829
        @Override
830
        public Spliterator<T> spliterator() {
831
            return toCollection().spliterator();
1 ✔
832
        }
833

834
        @Override
835
        public void doBreak() {
836
            ValueIterator iterator = last;
1 ✔
837
            while (iterator != null) {
1 ✔
838
                ValueIterator prev = iterator.prev;
1 ✔
839
                iterator.release();
1 ✔
840
                iterator = prev;
1 ✔
841
            }
1 ✔
842
        }
1 ✔
843

844
        // Holds the index lock until it is exhausted or released
845
        private final class ValueIterator implements Iterator<T> {
846

847
            private final Iterator<T> itr;
848
            private boolean locked;
849
            private ValueIterator prev;
850
            private ValueIterator next;
851

852
            public ValueIterator() {
1 ✔
853
                lock();
1 ✔
854
                locked = true;
1 ✔
855
                prev = last;
1 ✔
856
                if (prev != null) {
1 ✔
857
                    prev.next = this;
1 ✔
858
                }
859
                last = this;
1 ✔
860
                ValueSet<K, T> valueSet = null;
1 ✔
861
                try {
862
                    checkNotDestroyed();
1 ✔
863
                    valueSet = getValueSet(value);
1 ✔
864
                } finally {
865
                    if (valueSet == null) {
1 ✔
866
                        release();
1 ✔
867
                    }
868
                }
869
                itr = valueSet != null ? valueSet.iterator() : Collections.emptyIterator();
1 ✔
870
            }
1 ✔
871

872
            @Override
873
            public boolean hasNext() {
874
                if (locked && itr.hasNext()) {
1 ✔
875
                    return true;
1 ✔
876
                }
877
                release();
1 ✔
878
                return false;
1 ✔
879
            }
880

881
            @Override
882
            public T next() {
883
                if (!hasNext()) {
1 ✔
NEW
884
                    throw new NoSuchElementException();
×
885
                }
886
                return itr.next();
1 ✔
887
            }
888

889
            @Override
890
            public void remove() {
NEW
891
                throw new UnsupportedOperationException("Not supported.");
×
892
            }
893

894
            private void release() {
895
                if (locked) {
1 ✔
896
                    unlock();
1 ✔
897
                    locked = false;
1 ✔
898
                    if (prev != null) {
1 ✔
899
                        prev.next = next;
1 ✔
900
                    }
901
                    if (next != null) {
1 ✔
NEW
902
                        next.prev = prev;
×
903
                    } else {
904
                        last = prev;
1 ✔
905
                    }
906
                    prev = null;
1 ✔
907
                    next = null;
1 ✔
908
                }
909
            }
1 ✔
910
        }
911
    }
912
}
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