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

gephi / graphstore / #592

08 Oct 2026 07:01PM UTC coverage: 91.154% (+0.02%) from 91.138%
#592

push

web-flow
Restore id-only credential matching for the CI deploy (#305)

Maven 3.10 on the GitHub runners scopes server credentials to declared
origins, so the 'central' credentials were not sent to central.sonatype.com
and the snapshot deploy failed with HTTP 401.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

11923 of 13080 relevant lines covered (91.15%)

0.91 hits per line

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

93.25
/src/main/java/org/gephi/graph/impl/IndexStore.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.objects.Object2ObjectOpenHashMap;
20
import java.util.Iterator;
21
import java.util.Map;
22
import java.util.Map.Entry;
23
import org.gephi.graph.api.Column;
24
import org.gephi.graph.api.DirectedSubgraph;
25
import org.gephi.graph.api.Edge;
26
import org.gephi.graph.api.Element;
27
import org.gephi.graph.api.Graph;
28
import org.gephi.graph.api.GraphView;
29
import org.gephi.graph.api.Node;
30

31
public class IndexStore<T extends Element> {
32

33
    protected final ColumnStore<T> columnStore;
34
    protected final TableLockImpl lock;
35
    protected final IndexImpl<T> mainIndex;
36
    protected final Map<GraphView, IndexImpl<T>> viewIndexes;
37

38
    public IndexStore(ColumnStore<T> columnStore) {
1 ✔
39
        this.columnStore = columnStore;
1 ✔
40
        this.mainIndex = new IndexImpl<>(columnStore);
1 ✔
41
        this.viewIndexes = new Object2ObjectOpenHashMap<>();
1 ✔
42
        this.lock = columnStore.lock;
1 ✔
43
    }
1 ✔
44

45
    // Table locked
46
    protected void addColumn(ColumnImpl col) {
47
        mainIndex.addColumn(col);
1 ✔
48
        for (IndexImpl<T> index : viewIndexes.values()) {
1 ✔
49
            index.addColumn(col);
1 ✔
50
        }
1 ✔
51
    }
1 ✔
52

53
    // Table locked
54
    protected void removeColumn(ColumnImpl col) {
55
        mainIndex.removeColumn(col);
1 ✔
56
        for (IndexImpl<T> index : viewIndexes.values()) {
1 ✔
57
            index.removeColumn(col);
1 ✔
58
        }
1 ✔
59
    }
1 ✔
60

61
    protected boolean hasColumn(ColumnImpl col) {
62
        return mainIndex.hasColumn(col);
1 ✔
63
    }
64

65
    protected IndexImpl getIndex(Graph graph) {
66
        GraphView view = graph.getView();
1 ✔
67
        if (view.isMainView()) {
1 ✔
68
            return mainIndex;
1 ✔
69
        }
70
        synchronized (viewIndexes) {
1 ✔
71
            IndexImpl<T> viewIndex = viewIndexes.get(view);
1 ✔
72
            if (viewIndex != null) {
1 ✔
73
                return viewIndex;
1 ✔
74
            }
75
        }
1 ✔
76
        // The graph lock is taken first, as indexing the view requires it
77
        graph.readLock();
1 ✔
78
        try {
79
            synchronized (viewIndexes) {
1 ✔
80
                IndexImpl<T> viewIndex = viewIndexes.get(view);
1 ✔
81
                if (viewIndex == null) {
1 ✔
82
                    viewIndex = createViewIndex(graph);
1 ✔
83
                }
84
                return viewIndex;
1 ✔
85
            }
86
        } finally {
87
            graph.readUnlock();
1 ✔
88
        }
89
    }
90

91
    protected IndexImpl createViewIndex(Graph graph) {
92
        if (graph.getView().isMainView()) {
1 ✔
93
            throw new IllegalArgumentException("Can't create a view index for the main view");
1 ✔
94
        }
95
        lock();
1 ✔
96
        try {
97
            IndexImpl viewIndex = new IndexImpl<>(columnStore, graph);
1 ✔
98
            ColumnImpl[] columns = columnStore.toArray();
1 ✔
99
            viewIndex.addAllColumns(columns);
1 ✔
100
            viewIndexes.put(graph.getView(), viewIndex);
1 ✔
101

102
            indexView(graph);
1 ✔
103

104
            return viewIndex;
1 ✔
105
        } finally {
106
            unlock();
1 ✔
107
        }
108
    }
109

110
    protected void deleteViewIndex(Graph graph) {
111
        if (graph.getView().isMainView()) {
1 ✔
112
            throw new IllegalArgumentException("Can't delete a view index for the main view");
1 ✔
113
        }
114
        lock();
1 ✔
115
        try {
116
            IndexImpl<T> index = viewIndexes.remove(graph.getView());
1 ✔
117
            if (index != null) {
1 ✔
118
                index.destroy();
1 ✔
119
            }
120
        } finally {
121
            unlock();
1 ✔
122
        }
123
    }
1 ✔
124

125
    public Object set(Column column, Object oldValue, Object value, T element) {
126
        value = mainIndex.set(column, oldValue, value, element);
1 ✔
127

128
        if (!viewIndexes.isEmpty()) {
1 ✔
129
            synchronized (viewIndexes) {
1 ✔
130
                for (Entry<GraphView, IndexImpl<T>> entry : viewIndexes.entrySet()) {
1 ✔
131
                    GraphViewImpl graphView = (GraphViewImpl) entry.getKey();
1 ✔
132
                    DirectedSubgraph graph = graphView.getDirectedGraph();
1 ✔
133
                    boolean inView = element instanceof Node ? graph.contains((Node) element)
1 ✔
134
                            : graph.contains((Edge) element);
1 ✔
135
                    if (inView) {
1 ✔
136
                        entry.getValue().set(column, oldValue, value, element);
1 ✔
137
                    }
138
                }
1 ✔
139
            }
1 ✔
140
        }
141

142
        return value;
1 ✔
143
    }
144

145
    public void clear(T element) {
146
        ElementImpl elementImpl = (ElementImpl) element;
1 ✔
147

148
        lock();
1 ✔
149
        try {
150
            final int length = columnStore.length;
1 ✔
151
            final ColumnImpl[] cols = columnStore.columns;
1 ✔
152
            for (int i = 0; i < length; i++) {
1 ✔
153
                Column c = cols[i];
1 ✔
154
                if (c != null) {
1 ✔
155
                    Object value = elementImpl.getAttribute(c);
1 ✔
156
                    mainIndex.remove(c, value, element);
1 ✔
157
                    if (!viewIndexes.isEmpty()) {
1 ✔
158
                        synchronized (viewIndexes) {
×
159
                            for (Entry<GraphView, IndexImpl<T>> entry : viewIndexes.entrySet()) {
×
160
                                GraphViewImpl graphView = (GraphViewImpl) entry.getKey();
×
161
                                DirectedSubgraph graph = graphView.getDirectedGraph();
×
162
                                boolean inView = element instanceof Node ? graph.contains((Node) element)
×
163
                                        : graph.contains((Edge) element);
×
164
                                if (inView) {
×
165
                                    entry.getValue().remove(c, value, element);
×
166
                                }
167
                            }
×
168
                        }
×
169
                    }
170
                }
171
            }
172
        } finally {
173
            unlock();
1 ✔
174
        }
175
    }
1 ✔
176

177
    public void index(T element) {
178
        ElementImpl elementImpl = (ElementImpl) element;
1 ✔
179
        lock();
1 ✔
180
        try {
181

182
            final int length = columnStore.length;
1 ✔
183
            final ColumnImpl[] cols = columnStore.columns;
1 ✔
184
            for (int i = 0; i < length; i++) {
1 ✔
185
                Column c = cols[i];
1 ✔
186
                if (c != null) {
1 ✔
187
                    Object value = elementImpl.getAttribute(c);
1 ✔
188
                    value = mainIndex.put(c, value, element);
1 ✔
189
                    elementImpl.attributes.setAttribute(c, value);
1 ✔
190
                }
191
            }
192
        } finally {
193
            unlock();
1 ✔
194
        }
195
    }
1 ✔
196

197
    public void indexView(Graph graph) {
198
        final IndexImpl viewIndex = viewIndexes.get(graph.getView());
1 ✔
199
        if (viewIndex != null) {
1 ✔
200
            graph.readLock();
1 ✔
201
            try {
202
                Iterator<T> iterator = null;
1 ✔
203
                if (columnStore.elementType.equals(Node.class)) {
1 ✔
204
                    iterator = (Iterator<T>) graph.getNodes().iterator();
1 ✔
205
                } else if (columnStore.elementType.equals(Edge.class)) {
1 ✔
206
                    iterator = (Iterator<T>) graph.getEdges().iterator();
1 ✔
207
                }
208

209
                if (iterator != null) {
1 ✔
210
                    while (iterator.hasNext()) {
1 ✔
211
                        ElementImpl element = (ElementImpl) iterator.next();
1 ✔
212

213
                        final ColumnImpl[] cols = columnStore.columns;
1 ✔
214
                        int length = columnStore.length;
1 ✔
215
                        for (int i = 0; i < length; i++) {
1 ✔
216
                            Column c = cols[i];
1 ✔
217
                            if (c != null) {
1 ✔
218
                                Object value = element.getAttribute(c);
1 ✔
219
                                viewIndex.put(c, value, element);
1 ✔
220
                            }
221
                        }
222
                    }
1 ✔
223
                }
224
            } finally {
225
                graph.readUnlock();
1 ✔
226
            }
227
        }
228
    }
1 ✔
229

230
    public void indexInView(T element, GraphView view) {
231
        ElementImpl elementImpl = (ElementImpl) element;
1 ✔
232
        lock();
1 ✔
233
        try {
234
            IndexImpl<T> index = viewIndexes.get(view);
1 ✔
235
            if (index != null) {
1 ✔
236
                final int length = columnStore.length;
1 ✔
237
                final ColumnImpl[] cols = columnStore.columns;
1 ✔
238
                for (int i = 0; i < length; i++) {
1 ✔
239
                    Column c = cols[i];
1 ✔
240
                    if (c != null) {
1 ✔
241
                        Object value = elementImpl.getAttribute(c);
1 ✔
242
                        index.put(c, value, element);
1 ✔
243
                    }
244
                }
245
            }
246
        } finally {
247
            unlock();
1 ✔
248
        }
249
    }
1 ✔
250

251
    public void clearInView(T element, GraphView view) {
252
        ElementImpl elementImpl = (ElementImpl) element;
1 ✔
253
        lock();
1 ✔
254
        try {
255
            IndexImpl<T> index = viewIndexes.get(view);
1 ✔
256
            if (index != null) {
1 ✔
257
                final int length = columnStore.length;
1 ✔
258
                final ColumnImpl[] cols = columnStore.columns;
1 ✔
259
                for (int i = 0; i < length; i++) {
1 ✔
260
                    Column c = cols[i];
1 ✔
261
                    if (c != null) {
1 ✔
262
                        Object value = elementImpl.getAttribute(c);
1 ✔
263
                        index.remove(c, value, element);
1 ✔
264
                    }
265
                }
266
            }
267
        } finally {
268
            unlock();
1 ✔
269
        }
270
    }
1 ✔
271

272
    public void clear(GraphView view) {
273
        lock();
1 ✔
274
        try {
275
            IndexImpl<T> index = viewIndexes.get(view);
1 ✔
276
            if (index != null) {
1 ✔
277
                index.clear();
×
278
            }
279
        } finally {
280
            unlock();
1 ✔
281
        }
282
    }
1 ✔
283

284
    public void clear() {
285
        lock();
1 ✔
286
        try {
287
            mainIndex.clear();
1 ✔
288
            for (IndexImpl index : viewIndexes.values()) {
1 ✔
289
                index.clear();
1 ✔
290
            }
1 ✔
291
        } finally {
292
            unlock();
1 ✔
293
        }
294
    }
1 ✔
295

296
    private void lock() {
297
        if (lock != null) {
1 ✔
298
            lock.lock();
1 ✔
299
        }
300
    }
1 ✔
301

302
    private void unlock() {
303
        if (lock != null) {
1 ✔
304
            lock.unlock();
1 ✔
305
        }
306
    }
1 ✔
307
}
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