• 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

91.22
/src/main/java/org/gephi/graph/impl/ElementImpl.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 java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
import org.gephi.graph.api.AttributeUtils;
23
import org.gephi.graph.api.Column;
24
import org.gephi.graph.api.ColumnIterable;
25
import org.gephi.graph.api.Element;
26
import org.gephi.graph.api.Estimator;
27
import org.gephi.graph.api.GraphView;
28
import org.gephi.graph.api.Interval;
29
import org.gephi.graph.api.TimeRepresentation;
30
import org.gephi.graph.api.types.IntervalBooleanMap;
31
import org.gephi.graph.api.types.IntervalByteMap;
32
import org.gephi.graph.api.types.IntervalCharMap;
33
import org.gephi.graph.api.types.IntervalDoubleMap;
34
import org.gephi.graph.api.types.IntervalFloatMap;
35
import org.gephi.graph.api.types.IntervalIntegerMap;
36
import org.gephi.graph.api.types.IntervalLongMap;
37
import org.gephi.graph.api.types.IntervalMap;
38
import org.gephi.graph.api.types.IntervalShortMap;
39
import org.gephi.graph.api.types.IntervalStringMap;
40
import org.gephi.graph.api.types.TimeMap;
41
import org.gephi.graph.api.types.TimeSet;
42
import org.gephi.graph.api.types.TimestampBooleanMap;
43
import org.gephi.graph.api.types.TimestampByteMap;
44
import org.gephi.graph.api.types.TimestampCharMap;
45
import org.gephi.graph.api.types.TimestampDoubleMap;
46
import org.gephi.graph.api.types.TimestampFloatMap;
47
import org.gephi.graph.api.types.TimestampIntegerMap;
48
import org.gephi.graph.api.types.TimestampLongMap;
49
import org.gephi.graph.api.types.TimestampMap;
50
import org.gephi.graph.api.types.TimestampShortMap;
51
import org.gephi.graph.api.types.TimestampStringMap;
52

53
public abstract class ElementImpl implements Element {
54

55
    // Reference to store
56
    protected final GraphStore graphStore;
57
    // Attributes
58
    protected final AttributesImpl attributes;
59

60
    public ElementImpl(Object id, GraphStore graphStore) {
1 ✔
61
        if (id == null) {
1 ✔
62
            throw new NullPointerException();
1 ✔
63
        }
64
        this.graphStore = graphStore;
1 ✔
65
        this.attributes = new AttributesImpl(getColumnStore());
1 ✔
66
        this.attributes.setId(id);
1 ✔
67
    }
1 ✔
68

69
    abstract ColumnStore getColumnStore();
70

71
    abstract TimeIndexStore getTimeIndexStore();
72

73
    abstract boolean isValid();
74

75
    abstract DefaultColumnsImpl.TableDefaultColumns getDefaultColumns();
76

77
    @Override
78
    public Object getId() {
79
        return attributes.getId();
1 ✔
80
    }
81

82
    @Override
83
    public String getLabel() {
84
        return attributes.getLabel();
1 ✔
85
    }
86

87
    @Override
88
    public void setLabel(String label) {
89
        if (GraphStoreConfiguration.ENABLE_ELEMENT_LABEL) {
90
            setAttribute(getDefaultColumns().label, label);
1 ✔
91
        }
92
    }
1 ✔
93

94
    @Override
95
    public Object getAttribute(String key) {
96
        return getAttribute(checkColumnExists(key));
1 ✔
97
    }
98

99
    @Override
100
    public Object getAttribute(Column column) {
101
        checkColumn(column);
1 ✔
102

103
        return attributes.getAttribute(column);
1 ✔
104
    }
105

106
    @Override
107
    public Object getAttribute(String key, double timestamp) {
108
        return getAttribute(checkColumnExists(key), timestamp);
1 ✔
109
    }
110

111
    @Override
112
    public Object getAttribute(Column column, double timestamp) {
113
        checkTimeRepresentationTimestamp();
1 ✔
114
        checkDouble(timestamp);
1 ✔
115
        checkColumn(column);
1 ✔
116
        checkColumnDynamic(column);
1 ✔
117
        return attributes.getAttribute(column, timestamp, null);
1 ✔
118
    }
119

120
    @Override
121
    public Object getAttribute(String key, Interval interval) {
122
        return getAttribute(checkColumnExists(key), interval);
1 ✔
123
    }
124

125
    @Override
126
    public Object getAttribute(Column column, Interval interval) {
127
        checkTimeRepresentationInterval();
1 ✔
128
        checkColumn(column);
1 ✔
129
        checkColumnDynamic(column);
1 ✔
130
        return attributes.getAttribute(column, interval, null);
1 ✔
131
    }
132

133
    @Override
134
    public Object getAttribute(String key, GraphView view) {
135
        return getAttribute(checkColumnExists(key), view);
1 ✔
136
    }
137

138
    @Override
139
    public Object getAttribute(Column column, GraphView view) {
140
        Estimator estimator = column.getEstimator();
1 ✔
141
        return getAttribute(column, view, estimator);
1 ✔
142
    }
143

144
    protected Object getAttribute(Column column, GraphView view, Estimator estimator) {
145
        checkColumn(column);
1 ✔
146

147
        if (!column.isDynamic()) {
1 ✔
148
            return getAttribute(column);
1 ✔
149
        } else {
150
            checkViewExist(view);
1 ✔
151
            Interval interval = view.getTimeInterval();
1 ✔
152
            return attributes.getAttribute(column, interval, estimator);
1 ✔
153
        }
154
    }
155

156
    @Override
157
    public Object[] getAttributes() {
158
        return attributes.getBackingArray();
1 ✔
159
    }
160

161
    @Override
162
    public Set<String> getAttributeKeys() {
163
        return getColumnStore().getColumnKeys();
1 ✔
164
    }
165

166
    @Override
167
    public ColumnIterable getAttributeColumns() {
168
        return getColumnStore();
1 ✔
169
    }
170

171
    @Override
172
    public Object removeAttribute(String key) {
173
        return removeAttribute(checkColumnExists(key));
1 ✔
174
    }
175

176
    @Override
177
    public Object removeAttribute(Column column) {
178
        checkColumn(column);
1 ✔
179
        checkReadOnlyColumn(column);
1 ✔
180

181
        Object oldValue = attributes.setAttribute(column, column.getDefaultValue());
1 ✔
182
        updateIndex(column, oldValue, column.getDefaultValue());
1 ✔
183
        updateIndexToCurrentValue(column, column.getDefaultValue());
1 ✔
184

185
        return oldValue;
1 ✔
186
    }
187

188
    @Override
189
    public Object removeAttribute(Column column, double timestamp) {
190
        checkTimeRepresentationTimestamp();
1 ✔
191
        checkDouble(timestamp);
1 ✔
192
        return removeTimeAttribute(column, timestamp);
1 ✔
193
    }
194

195
    @Override
196
    public Object removeAttribute(String key, double timestamp) {
197
        return removeAttribute(checkColumnExists(key), timestamp);
1 ✔
198
    }
199

200
    @Override
201
    public Object removeAttribute(Column column, Interval interval) {
202
        checkTimeRepresentationInterval();
1 ✔
203
        return removeTimeAttribute(column, interval);
1 ✔
204
    }
205

206
    @Override
207
    public Object removeAttribute(String key, Interval interval) {
208
        return removeAttribute(checkColumnExists(key), interval);
1 ✔
209
    }
210

211
    private Object removeTimeAttribute(Column column, Object timeObject) {
212
        checkColumn(column);
1 ✔
213
        checkColumnDynamic(column);
1 ✔
214
        checkReadOnlyColumn(column);
1 ✔
215

216
        Object oldValue = attributes.removeTimeAttribute(column, timeObject);
1 ✔
217

218
        // TODO
219
        if (oldValue != null && isValid()) {
1 ✔
220
            TimeIndexStore timeIndexStore = getTimeIndexStore();
1 ✔
221
            if (timeIndexStore != null) {
1 ✔
222
                timeIndexStore.remove(timeObject);
1 ✔
223
            }
224
            ((ColumnImpl) column).incrementVersion(this);
1 ✔
225
        }
226
        return oldValue;
1 ✔
227
    }
228

229
    @Override
230
    public void setAttribute(String key, Object value) {
231
        setAttribute(checkColumnExists(key), value);
1 ✔
232
    }
1 ✔
233

234
    @Override
235
    public void setAttribute(Column column, Object value) {
236
        checkColumn(column);
1 ✔
237
        checkReadOnlyColumn(column);
1 ✔
238

239
        value = AttributeUtils.standardizeValue(value);
1 ✔
240
        checkType(column, value);
1 ✔
241

242
        Object oldValue = attributes.setAttribute(column, value);
1 ✔
243
        updateIndex(column, oldValue, value);
1 ✔
244
        updateIndexToCurrentValue(column, value);
1 ✔
245
    }
1 ✔
246

247
    // Another thread can set the attribute between the write and the index update, so the index follows the value
248
    // read again
249
    private void updateIndexToCurrentValue(Column column, Object indexedValue) {
250
        int index = column.getIndex();
1 ✔
251
        Object value;
252
        while (index != ColumnStore.NULL_ID && (value = attributes.getAttribute(index)) != indexedValue && isValid()) {
1 ✔
253
            ColumnStore columnStore = getColumnStore();
1 ✔
254
            // Stops when the column is removed meanwhile
255
            if (columnStore == null || columnStore.columns[index] != column) {
1 ✔
NEW
256
                return;
×
257
            }
258
            columnStore.indexStore.set(column, indexedValue, value, this);
1 ✔
259
            indexedValue = value;
1 ✔
260
        }
1 ✔
261
    }
1 ✔
262

263
    @Override
264
    public void setAttribute(String key, Object value, double timestamp) {
265
        setAttribute(checkColumnExists(key), value, timestamp);
1 ✔
266
    }
1 ✔
267

268
    @Override
269
    public void setAttribute(Column column, Object value, double timestamp) {
270
        checkTimeRepresentationTimestamp();
1 ✔
271
        checkDouble(timestamp);
1 ✔
272
        setTimeAttribute(column, value, timestamp);
1 ✔
273
    }
1 ✔
274

275
    @Override
276
    public void setAttribute(String key, Object value, Interval interval) {
277
        setAttribute(checkColumnExists(key), value, interval);
1 ✔
278
    }
1 ✔
279

280
    @Override
281
    public void setAttribute(Column column, Object value, Interval interval) {
282
        checkTimeRepresentationInterval();
1 ✔
283
        setTimeAttribute(column, value, interval);
1 ✔
284
    }
1 ✔
285

286
    private void setTimeAttribute(Column column, Object value, Object timeObject) {
287
        checkColumn(column);
1 ✔
288
        checkColumnDynamic(column);
1 ✔
289
        checkReadOnlyColumn(column);
1 ✔
290
        checkDynamicType(column, value);
1 ✔
291

292
        // Only a time the map did not already hold is a new reference for the time index. Passing the whole map would
293
        // re-count every time in it, as removeTimeAttribute decrements one at a time.
294
        boolean isNewTime = attributes.setAttribute(column, value, timeObject);
1 ✔
295
        updateIndex(column, null, isNewTime ? timeObject : null);
1 ✔
296
    }
1 ✔
297

298
    private void updateIndex(Column column, Object oldValue, Object newValue) {
299
        // Update index
300
        if (isValid()) {
1 ✔
301
            ColumnStore columnStore = getColumnStore();
1 ✔
302
            ColumnImpl columnImpl = (ColumnImpl) column;
1 ✔
303
            if (columnImpl.isDynamic()) {
1 ✔
304
                TimeIndexStore timeIndexStore = getTimeIndexStore();
1 ✔
305
                if (timeIndexStore != null) {
1 ✔
306
                    if (TimeMap.class.isAssignableFrom(columnImpl.getTypeClass())) {
1 ✔
307
                        if (oldValue instanceof TimeMap && newValue instanceof TimeMap && oldValue != newValue) {
1 ✔
308
                            timeIndexStore.replace((TimeMap) oldValue, (TimeMap) newValue);
1 ✔
309
                        } else {
310
                            if (oldValue instanceof TimeMap) {
1 ✔
311
                                timeIndexStore.remove((TimeMap) oldValue);
1 ✔
312
                            } else if (oldValue != null) {
1 ✔
313
                                timeIndexStore.remove(oldValue);
×
314
                            }
315
                            if (newValue instanceof TimeMap) {
1 ✔
316
                                timeIndexStore.add((TimeMap) newValue);
1 ✔
317
                            } else if (newValue != null) {
1 ✔
318
                                timeIndexStore.add(newValue);
1 ✔
319
                            }
320
                        }
321
                    } else if (TimeSet.class.isAssignableFrom(columnImpl.getTypeClass())) {
1 ✔
322
                        if (oldValue instanceof TimeSet && newValue instanceof TimeSet && oldValue != newValue) {
1 ✔
323
                            timeIndexStore.replace((TimeSet) oldValue, (TimeSet) newValue, this);
1 ✔
324
                        } else {
325
                            if (oldValue instanceof TimeSet) {
1 ✔
326
                                timeIndexStore.remove((TimeSet) oldValue, this);
1 ✔
327
                            } else if (oldValue != null) {
1 ✔
328
                                timeIndexStore.remove(oldValue, this);
1 ✔
329
                            }
330
                            if (newValue instanceof TimeSet) {
1 ✔
331
                                timeIndexStore.add((TimeSet) newValue, this);
1 ✔
332
                            } else if (newValue != null) {
1 ✔
333
                                timeIndexStore.add(newValue, this);
1 ✔
334
                            }
335
                        }
336
                    }
337
                }
338
            }
339
            if (columnStore != null) {
1 ✔
340
                columnStore.indexStore.set(column, oldValue, newValue, this);
1 ✔
341
            }
342
            columnImpl.incrementVersion(this);
1 ✔
343
        }
344
    }
1 ✔
345

346
    // Called when a dynamic column is removed, its times no longer count in the time index
347
    void removeFromTimeIndex(Object oldValue) {
348
        if (oldValue instanceof TimeMap && isValid()) {
1 ✔
349
            TimeIndexStore timeIndexStore = getTimeIndexStore();
1 ✔
350
            if (timeIndexStore != null) {
1 ✔
351
                timeIndexStore.remove((TimeMap) oldValue);
1 ✔
352
            }
353
        }
354
    }
1 ✔
355

356
    @Override
357
    public boolean addTimestamp(double timestamp) {
358
        checkDouble(timestamp);
1 ✔
359
        checkTimeRepresentationTimestamp();
1 ✔
360
        return addTime(timestamp);
1 ✔
361
    }
362

363
    @Override
364
    public boolean addInterval(Interval interval) {
365
        checkTimeRepresentationInterval();
1 ✔
366
        return addTime(interval);
1 ✔
367
    }
368

369
    private boolean addTime(Object timeObject) {
370
        checkEnabledTimeSet();
1 ✔
371

372
        boolean res = attributes.addTime(timeObject);
1 ✔
373
        if (res) {
1 ✔
374
            updateIndex(getDefaultColumns().timeset, null, timeObject);
1 ✔
375
        }
376
        return res;
1 ✔
377
    }
378

379
    @Override
380
    public boolean removeTimestamp(double timestamp) {
381
        checkDouble(timestamp);
1 ✔
382
        checkTimeRepresentationTimestamp();
1 ✔
383
        return removeTime(timestamp);
1 ✔
384
    }
385

386
    @Override
387
    public boolean removeInterval(Interval interval) {
388
        checkTimeRepresentationInterval();
1 ✔
389
        return removeTime(interval);
1 ✔
390
    }
391

392
    private boolean removeTime(Object timeObject) {
393
        checkEnabledTimeSet();
1 ✔
394

395
        boolean res = attributes.removeTime(timeObject);
1 ✔
396
        if (res) {
1 ✔
397
            updateIndex(getDefaultColumns().timeset, timeObject, null);
1 ✔
398
        }
399
        return res;
1 ✔
400
    }
401

402
    @Override
403
    public double[] getTimestamps() {
404
        checkTimeRepresentationTimestamp();
1 ✔
405
        checkEnabledTimeSet();
1 ✔
406
        Object res = attributes.getTimeSetArray();
1 ✔
407
        if (res == null) {
1 ✔
408
            return new double[0];
1 ✔
409
        }
410
        return (double[]) res;
1 ✔
411
    }
412

413
    @Override
414
    public Interval[] getIntervals() {
415
        checkTimeRepresentationInterval();
1 ✔
416
        checkEnabledTimeSet();
1 ✔
417
        Object res = attributes.getTimeSetArray();
1 ✔
418
        if (res == null) {
1 ✔
419
            return new Interval[0];
1 ✔
420
        }
421
        return (Interval[]) res;
1 ✔
422
    }
423

424
    @Override
425
    public Interval getTimeBounds() {
426
        checkEnabledTimeSet();
×
427
        TimeSet timeSet = attributes.getTimeSet();
×
428
        if (timeSet != null) {
×
429
            Double min = timeSet.getMinDouble();
×
430
            Double max = timeSet.getMaxDouble();
×
431
            if (min != null) {
×
432
                return new Interval(min, max);
×
433
            }
434
        }
435
        return null;
×
436
    }
437

438
    @Override
439
    public boolean hasTimestamp(double timestamp) {
440
        checkTimeRepresentationTimestamp();
1 ✔
441
        checkEnabledTimeSet();
1 ✔
442
        return attributes.hasTime(timestamp);
1 ✔
443
    }
444

445
    @Override
446
    public boolean hasInterval(Interval interval) {
447
        checkTimeRepresentationInterval();
1 ✔
448
        checkEnabledTimeSet();
1 ✔
449
        return attributes.hasTime(interval);
1 ✔
450
    }
451

452
    @Override
453
    public Iterable<Map.Entry> getAttributes(Column column) {
454
        checkColumn(column);
1 ✔
455
        checkColumnDynamicAttribute(column);
1 ✔
456

457
        return attributes.getAttributes(column);
1 ✔
458
    }
459

460
    // Called when elements are added
461
    // TODO
462
    protected void indexAttributes() {
463
        synchronized (this) {
1 ✔
464
            ColumnStore columnStore = getColumnStore();
1 ✔
465
            if (columnStore != null) {
1 ✔
466
                columnStore.indexStore.index(this);
1 ✔
467
            }
468

469
            TimeIndexStore timeIndexStore = getTimeIndexStore();
1 ✔
470
            if (timeIndexStore != null) {
1 ✔
471
                timeIndexStore.index(this);
1 ✔
472
            }
473
        }
1 ✔
474
    }
1 ✔
475

476
    @Override
477
    public void clearAttributes() {
478
        synchronized (this) {
1 ✔
479
            ColumnStore columnStore = getColumnStore();
1 ✔
480
            if (columnStore != null) {
1 ✔
481
                final int length = columnStore.length;
1 ✔
482
                final ColumnImpl[] cols = columnStore.columns;
1 ✔
483
                for (int i = 0; i < length; i++) {
1 ✔
484
                    Column c = cols[i];
1 ✔
485
                    if (c != null && !c.isProperty() && !c.isReadOnly()) {
1 ✔
486
                        removeAttribute(c);
1 ✔
487
                    }
488
                }
489
            }
490
        }
1 ✔
491
    }
1 ✔
492

493
    protected void destroyAttributes() {
494
        synchronized (this) {
1 ✔
495
            ColumnStore columnStore = getColumnStore();
1 ✔
496
            if (columnStore != null) {
1 ✔
497
                columnStore.indexStore.clear(this);
1 ✔
498
            }
499

500
            TimeIndexStore timeIndexStore = getTimeIndexStore();
1 ✔
501
            if (timeIndexStore != null) {
1 ✔
502
                timeIndexStore.clear(this);
1 ✔
503
            }
504
        }
1 ✔
505
    }
1 ✔
506

507
    @Override
508
    public int hashCode() {
509
        int hash = 7;
1 ✔
510
        hash = 29 * hash + this.getId().hashCode();
1 ✔
511
        return hash;
1 ✔
512
    }
513

514
    @Override
515
    public boolean equals(Object obj) {
516
        if (obj == null) {
1 ✔
517
            return false;
×
518
        }
519
        if (getClass() != obj.getClass()) {
1 ✔
520
            return false;
×
521
        }
522
        final ElementImpl other = (ElementImpl) obj;
1 ✔
523
        return this.getId().equals(other.getId());
1 ✔
524
    }
525

526
    protected Estimator getEstimator(Column column) {
527
        Estimator estimator = column.getEstimator();
1 ✔
528
        if (estimator == null) {
1 ✔
529
            return GraphStoreConfiguration.DEFAULT_ESTIMATOR;
×
530
        }
531
        return estimator;
1 ✔
532
    }
533

534
    protected GraphStore getGraphStore() {
535
        return graphStore;
×
536
    }
537

538
    protected void checkTimeRepresentationTimestamp() {
539
        if (!getTimeRepresentation().equals(TimeRepresentation.TIMESTAMP)) {
1 ✔
540
            throw new RuntimeException(
1 ✔
541
                    "Can't use timestamps as the configuration is set to " + getTimeRepresentation());
1 ✔
542
        }
543
    }
1 ✔
544

545
    protected void checkTimeRepresentationInterval() {
546
        if (!getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
1 ✔
547
            throw new RuntimeException("Can't use intervals as the configuration is set to " + getTimeRepresentation());
1 ✔
548
        }
549
    }
1 ✔
550

551
    void checkEnabledTimeSet() {
552
        if (!GraphStoreConfiguration.ENABLE_ELEMENT_TIME_SET) {
553
            throw new RuntimeException("Can't call timestamp or intervals methods if they are disabled");
554
        }
555
    }
1 ✔
556

557
    void checkDouble(double timestamp) {
558
        if (Double.isInfinite(timestamp) || Double.isNaN(timestamp)) {
1 ✔
559
            throw new IllegalArgumentException("Timestamp can't be NaN or infinity");
1 ✔
560
        }
561
    }
1 ✔
562

563
    Column checkColumnExists(String key) {
564
        Column col = getColumnStore().getColumn(key);
1 ✔
565
        if (col == null) {
1 ✔
566
            throw new IllegalArgumentException("The column '" + key + "' is not found");
1 ✔
567
        }
568
        return col;
1 ✔
569
    }
570

571
    void checkColumn(Column column) {
572
        if (column.getIndex() == ColumnStore.NULL_ID) {
1 ✔
573
            throw new IllegalArgumentException("The column does not exist");
1 ✔
574
        }
575
        ColumnStore columnStore = getColumnStore();
1 ✔
576
        if (columnStore != null && columnStore.getColumnByIndex(column.getIndex()) != column) {
1 ✔
577
            throw new IllegalArgumentException("The column does not belong to the right column store");
×
578
        }
579
    }
1 ✔
580

581
    void checkReadOnlyColumn(Column column) {
582
        if (column.isReadOnly()) {
1 ✔
583
            throw new RuntimeException("Can't modify the read-only '" + column.getId() + "' column");
×
584
        }
585
    }
1 ✔
586

587
    void checkColumnDynamic(Column column) {
588
        if (!column.isDynamic()) {
1 ✔
589
            throw new IllegalArgumentException("The column is not dynamic");
1 ✔
590
        }
591
    }
1 ✔
592

593
    void checkColumnDynamicAttribute(Column column) {
594
        if (!column.isDynamicAttribute()) {
1 ✔
595
            throw new IllegalArgumentException("The column is not a dynamic attribute");
1 ✔
596
        }
597
    }
1 ✔
598

599
    void checkDynamicType(Column column, Object value) {
600
        if (value != null) {
1 ✔
601
            Class typeClass = column.getTypeClass();
1 ✔
602
            if (TimestampMap.class.isAssignableFrom(typeClass)) {
1 ✔
603
                checkTimeRepresentationTimestamp();
1 ✔
604
                if ((value instanceof Double && (!typeClass
1 ✔
605
                        .equals(TimestampDoubleMap.class))) || (value instanceof Float && !typeClass
1 ✔
606
                                .equals(TimestampFloatMap.class)) || (value instanceof Boolean && !typeClass
1 ✔
607
                                        .equals(TimestampBooleanMap.class)) || (value instanceof Integer && !typeClass
1 ✔
608
                                                .equals(TimestampIntegerMap.class)) || (value instanceof Long && !typeClass
1 ✔
609
                                                        .equals(TimestampLongMap.class)) || (value instanceof Short && !typeClass
1 ✔
610
                                                                .equals(TimestampShortMap.class)) || (value instanceof Byte && !typeClass
1 ✔
611
                                                                        .equals(TimestampByteMap.class)) || (value instanceof String && !typeClass
1 ✔
612
                                                                                .equals(TimestampStringMap.class)) || (value instanceof Character && !typeClass
1 ✔
613
                                                                                        .equals(TimestampCharMap.class))) {
1 ✔
614
                    throw new IllegalArgumentException(
×
615
                            "The object class does not match with the dynamic type (" + typeClass.getName() + ")");
×
616
                }
617
            } else if (IntervalMap.class.isAssignableFrom(typeClass)) {
1 ✔
618
                checkTimeRepresentationInterval();
1 ✔
619
                if ((value instanceof Double && (!typeClass
1 ✔
620
                        .equals(IntervalDoubleMap.class))) || (value instanceof Float && !typeClass
1 ✔
621
                                .equals(IntervalFloatMap.class)) || (value instanceof Boolean && !typeClass
1 ✔
622
                                        .equals(IntervalBooleanMap.class)) || (value instanceof Integer && !typeClass
1 ✔
623
                                                .equals(IntervalIntegerMap.class)) || (value instanceof Long && !typeClass
1 ✔
624
                                                        .equals(IntervalLongMap.class)) || (value instanceof Short && !typeClass
1 ✔
625
                                                                .equals(IntervalShortMap.class)) || (value instanceof Byte && !typeClass
1 ✔
626
                                                                        .equals(IntervalByteMap.class)) || (value instanceof String && !typeClass
1 ✔
627
                                                                                .equals(IntervalStringMap.class)) || (value instanceof Character && !typeClass
1 ✔
628
                                                                                        .equals(IntervalCharMap.class))) {
1 ✔
629
                    throw new IllegalArgumentException(
×
630
                            "The object class does not match with the dynamic type (" + typeClass.getName() + ")");
×
631
                }
632
            }
633
        }
634
    }
1 ✔
635

636
    void checkType(Column column, Object value) {
637
        if (value != null) {
1 ✔
638
            Class typeClass = column.getTypeClass();
1 ✔
639
            if (List.class.isAssignableFrom(typeClass)) {
1 ✔
640
                if (!(value instanceof List)) {
1 ✔
641
                    throw new IllegalArgumentException("The object class " + value.getClass()
×
642
                            .getName() + " does not match with the list type (" + typeClass.getName() + ")");
×
643
                }
644
            } else if (Set.class.isAssignableFrom(typeClass)) {
1 ✔
645
                if (!(value instanceof Set)) {
1 ✔
646
                    throw new IllegalArgumentException("The object class " + value.getClass()
×
647
                            .getName() + " does not match with the set type (" + typeClass.getName() + ")");
×
648
                }
649
            } else if (Map.class.isAssignableFrom(typeClass)) {
1 ✔
650
                if (!(value instanceof Map)) {
1 ✔
651
                    throw new IllegalArgumentException("The object class " + value.getClass()
×
652
                            .getName() + " does not match with the map type (" + typeClass.getName() + ")");
×
653
                }
654
            } else if (!value.getClass().equals(typeClass)) {
1 ✔
655
                throw new IllegalArgumentException("The object class " + value.getClass()
1 ✔
656
                        .getName() + " does not match with the column type (" + typeClass.getName() + ")");
1 ✔
657
            }
658
        }
659
    }
1 ✔
660

661
    void checkViewExist(final GraphView view) {
662
        if (view == null) {
1 ✔
663
            throw new NullPointerException();
1 ✔
664
        }
665
        if (view.isMainView()) {
1 ✔
666
            return;
1 ✔
667
        }
668
        if (!(view instanceof GraphViewImpl)) {
1 ✔
669
            throw new IllegalArgumentException("The view is not from this implementation");
×
670
        }
671
        // Lock-free: callers may hold the table lock or the element monitor
672
        GraphViewImpl viewImpl = (GraphViewImpl) view;
1 ✔
673
        if (viewImpl.isDestroyed() || (graphStore != null && viewImpl.graphStore != graphStore)) {
1 ✔
674
            throw new IllegalArgumentException("The view doesn't exist");
1 ✔
675
        }
676
    }
1 ✔
677

678
    TimeRepresentation getTimeRepresentation() {
679
        if (graphStore != null) {
1 ✔
680
            return graphStore.configuration.getTimeRepresentation();
1 ✔
681
        }
682
        return GraphStoreConfiguration.DEFAULT_TIME_REPRESENTATION;
×
683
    }
684
}
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