diff --git a/src/main/java/org/gephi/graph/api/Configuration.java b/src/main/java/org/gephi/graph/api/Configuration.java index d74a1925..70c00675 100644 --- a/src/main/java/org/gephi/graph/api/Configuration.java +++ b/src/main/java/org/gephi/graph/api/Configuration.java @@ -27,7 +27,7 @@ * create a GraphModel with custom configuration. *

* Create instances by using the builder: - * + * *

  * Configuration config = Configuration.builder().build();
  * 
@@ -260,7 +260,7 @@ public boolean isEnableObservers() { * for each type. *

* Default is true. - * + * * @param enableAutoEdgeTypeRegistration enable auto edge type registration * @return this builder */ @@ -281,7 +281,7 @@ public boolean isEnableAutoEdgeTypeRegistration() { * properties aren't needed, disabling them can save memory. *

* Default is true. - * + * * @param enableNodeProperties enable node properties * @return this builder */ @@ -302,7 +302,7 @@ public boolean isEnableNodeProperties() { * properties aren't needed, disabling them can save memory. *

* Default is true. - * + * * @param enableEdgeProperties enable edge properties * @return this builder */ @@ -325,7 +325,7 @@ public boolean isEnableEdgeProperties() { * The spatial index can be retrieved from {@link GraphModel#getSpatialIndex()}. *

* Default is false. - * + * * @param enableSpatialIndex enable edge properties * @return this builder */ @@ -349,7 +349,7 @@ public boolean isEnableSpatialIndex() { * return results. *

* Default is true. - * + * * @param enableIndexNodes enable node attribute indexing * @return this builder */ @@ -373,7 +373,7 @@ public boolean isEnableIndexNodes() { * return results. *

* Default is true. - * + * * @param enableIndexEdges enable edge attribute indexing * @return this builder */ @@ -416,7 +416,7 @@ public boolean isEnableIndexTime() { * If disabled, only a single edge of a given type can exist between two nodes. *

* Default is false. - * + * * @param enableParallelEdgesSameType enable parallel edges of the same type * @return this builder */ @@ -586,7 +586,7 @@ public Boolean getEdgeWeightColumn() { /** * Sets whether to create an edge weight column. *

- * + * * @deprecated Use {@link #builder()} instead. * * @param edgeWeightColumn edge weight column diff --git a/src/main/java/org/gephi/graph/api/Graph.java b/src/main/java/org/gephi/graph/api/Graph.java index ad56cc8d..10ad9b24 100644 --- a/src/main/java/org/gephi/graph/api/Graph.java +++ b/src/main/java/org/gephi/graph/api/Graph.java @@ -131,6 +131,14 @@ public interface Graph { */ public Node getNode(Object id); + /** + * Gets a node given its store id. + * + * @param storeId the store id + * @return the node, or null if not found + */ + public Node getNodeByStoreId(int storeId); + /** * Returns true if a node with id as identifier exists. * @@ -147,6 +155,14 @@ public interface Graph { */ public Edge getEdge(Object id); + /** + * Gets an edge given its store id. + * + * @param storeId the store id + * @return the edge, or null if not found + */ + public Edge getEdgeByStoreId(int storeId); + /** * Returns true if an edge with id as identifier exists. * diff --git a/src/main/java/org/gephi/graph/api/GraphModel.java b/src/main/java/org/gephi/graph/api/GraphModel.java index 0e138a1c..ba545069 100644 --- a/src/main/java/org/gephi/graph/api/GraphModel.java +++ b/src/main/java/org/gephi/graph/api/GraphModel.java @@ -38,7 +38,7 @@ * *

* New instances can be obtained via the embedded factory: - * + * *

  * GraphModel model = GraphModel.Factory.newInstance();
  * 
@@ -49,7 +49,7 @@ * Configuration configuration = Configuration.builder().build(); * GraphModel model = GraphModel.Factory.newInstance(configuration); * - * + * * This API revolves around a set of simple concepts. A GraphModel * encapsulate all elements and metadata associated with a graph structure. In * other words it's a single graph, but it also contains configuration, indices, diff --git a/src/main/java/org/gephi/graph/api/SpatialIndex.java b/src/main/java/org/gephi/graph/api/SpatialIndex.java index 633a1356..882852ec 100644 --- a/src/main/java/org/gephi/graph/api/SpatialIndex.java +++ b/src/main/java/org/gephi/graph/api/SpatialIndex.java @@ -17,7 +17,7 @@ /** * Object to query the nodes and edges of the graph in a spatial context. - * + * * @author Eduardo Ramos */ public interface SpatialIndex { diff --git a/src/main/java/org/gephi/graph/api/package.html b/src/main/java/org/gephi/graph/api/package.html index 172830cd..ae5d4a6f 100644 --- a/src/main/java/org/gephi/graph/api/package.html +++ b/src/main/java/org/gephi/graph/api/package.html @@ -1,8 +1,8 @@ - - + + - Complete API description, where + Complete API description, where GraphModel - is the entry point. + is the entry point. - \ No newline at end of file + diff --git a/src/main/java/org/gephi/graph/api/types/package.html b/src/main/java/org/gephi/graph/api/types/package.html index dba9d896..ca0a00dd 100644 --- a/src/main/java/org/gephi/graph/api/types/package.html +++ b/src/main/java/org/gephi/graph/api/types/package.html @@ -1,6 +1,6 @@ - - + + - Custom types the API supports, in addition of primitive and arrays. + Custom types the API supports, in addition of primitive and arrays. - \ No newline at end of file + diff --git a/src/main/java/org/gephi/graph/impl/EdgeStore.java b/src/main/java/org/gephi/graph/impl/EdgeStore.java index d60cc48f..7328bb01 100644 --- a/src/main/java/org/gephi/graph/impl/EdgeStore.java +++ b/src/main/java/org/gephi/graph/impl/EdgeStore.java @@ -448,6 +448,14 @@ public EdgeImpl get(int id) { return blocks[id / GraphStoreConfiguration.EDGESTORE_BLOCK_SIZE].get(id); } + // Only used for Graph.getEdgeByStoreId + public EdgeImpl getForGetByStoreId(int id) { + if (id < 0 || !isValidIndex(id)) { + return null; + } + return blocks[id / GraphStoreConfiguration.EDGESTORE_BLOCK_SIZE].get(id); + } + public EdgeImpl get(final Object id) { checkNonNullObject(id); diff --git a/src/main/java/org/gephi/graph/impl/GraphStore.java b/src/main/java/org/gephi/graph/impl/GraphStore.java index 3038d5c4..3d6a114f 100644 --- a/src/main/java/org/gephi/graph/impl/GraphStore.java +++ b/src/main/java/org/gephi/graph/impl/GraphStore.java @@ -197,6 +197,16 @@ public NodeImpl getNode(final Object id) { } } + @Override + public NodeImpl getNodeByStoreId(final int id) { + autoReadLock(); + try { + return nodeStore.getForGetByStoreId(id); + } finally { + autoReadUnlock(); + } + } + @Override public boolean hasNode(final Object id) { return getNode(id) != null; @@ -212,6 +222,16 @@ public EdgeImpl getEdge(final Object id) { } } + @Override + public EdgeImpl getEdgeByStoreId(final int id) { + autoReadLock(); + try { + return edgeStore.getForGetByStoreId(id); + } finally { + autoReadUnlock(); + } + } + @Override public boolean hasEdge(final Object id) { return getEdge(id) != null; diff --git a/src/main/java/org/gephi/graph/impl/GraphViewDecorator.java b/src/main/java/org/gephi/graph/impl/GraphViewDecorator.java index 76823d09..266ffa7e 100644 --- a/src/main/java/org/gephi/graph/impl/GraphViewDecorator.java +++ b/src/main/java/org/gephi/graph/impl/GraphViewDecorator.java @@ -318,6 +318,20 @@ public Node getNode(Object id) { } } + @Override + public Node getNodeByStoreId(int id) { + graphStore.autoReadLock(); + try { + NodeImpl node = graphStore.getNodeByStoreId(id); + if (node != null && view.containsNode(node)) { + return node; + } + return null; + } finally { + graphStore.autoReadUnlock(); + } + } + @Override public boolean hasNode(final Object id) { return getNode(id) != null; @@ -337,6 +351,20 @@ public Edge getEdge(Object id) { } } + @Override + public Edge getEdgeByStoreId(int id) { + graphStore.autoReadLock(); + try { + EdgeImpl edge = graphStore.getEdgeByStoreId(id); + if (edge != null && view.containsEdge(edge)) { + return edge; + } + return null; + } finally { + graphStore.autoReadUnlock(); + } + } + @Override public boolean hasEdge(final Object id) { return getEdge(id) != null; diff --git a/src/main/java/org/gephi/graph/impl/NodeStore.java b/src/main/java/org/gephi/graph/impl/NodeStore.java index 9c2c8add..709deb31 100644 --- a/src/main/java/org/gephi/graph/impl/NodeStore.java +++ b/src/main/java/org/gephi/graph/impl/NodeStore.java @@ -125,6 +125,14 @@ public NodeImpl get(final int id) { return blocks[id / GraphStoreConfiguration.NODESTORE_BLOCK_SIZE].get(id); } + // Only used for Graph.getNodeByStoreId + public NodeImpl getForGetByStoreId(int id) { + if (id < 0 || !isValidIndex(id)) { + return null; + } + return blocks[id / GraphStoreConfiguration.NODESTORE_BLOCK_SIZE].get(id); + } + public NodeImpl get(final Object id) { int index = dictionary.getInt(id); if (index != NodeStore.NULL_ID) { diff --git a/src/main/java/org/gephi/graph/impl/NodesQuadTree.java b/src/main/java/org/gephi/graph/impl/NodesQuadTree.java index a31746ef..c32de592 100644 --- a/src/main/java/org/gephi/graph/impl/NodesQuadTree.java +++ b/src/main/java/org/gephi/graph/impl/NodesQuadTree.java @@ -17,7 +17,7 @@ * Adapted from https://bitbucket.org/C3/quadtree/wiki/Home * * TODO: unit tests!! - * + * * @author Eduardo Ramos */ public class NodesQuadTree { diff --git a/src/main/java/org/gephi/graph/impl/UndirectedDecorator.java b/src/main/java/org/gephi/graph/impl/UndirectedDecorator.java index 55af3b70..92f60a41 100644 --- a/src/main/java/org/gephi/graph/impl/UndirectedDecorator.java +++ b/src/main/java/org/gephi/graph/impl/UndirectedDecorator.java @@ -110,6 +110,11 @@ public Node getNode(Object id) { return store.getNode(id); } + @Override + public Node getNodeByStoreId(int id) { + return store.getNodeByStoreId(id); + } + @Override public boolean hasNode(final Object id) { return store.hasNode(id); @@ -120,6 +125,11 @@ public Edge getEdge(Object id) { return store.getEdge(id); } + @Override + public Edge getEdgeByStoreId(int storeId) { + return store.getEdgeByStoreId(storeId); + } + @Override public boolean hasEdge(final Object id) { return store.hasEdge(id); diff --git a/src/main/java/org/gephi/graph/spi/package.html b/src/main/java/org/gephi/graph/spi/package.html index b65b2e11..39474ac9 100644 --- a/src/main/java/org/gephi/graph/spi/package.html +++ b/src/main/java/org/gephi/graph/spi/package.html @@ -1,6 +1,6 @@ - - + + - SPI interfaces clients can implement to extend the API. + SPI interfaces clients can implement to extend the API. - \ No newline at end of file + diff --git a/src/test/java/org/gephi/graph/impl/BasicGraphStore.java b/src/test/java/org/gephi/graph/impl/BasicGraphStore.java index ddd0fc68..d4dffa29 100644 --- a/src/test/java/org/gephi/graph/impl/BasicGraphStore.java +++ b/src/test/java/org/gephi/graph/impl/BasicGraphStore.java @@ -209,6 +209,10 @@ public Node getNode(Object id) { return nodeStore.get(id); } + public Node getNodeByStoreId(int storeId) { + throw new UnsupportedOperationException("Not supported yet."); + } + @Override public boolean hasNode(Object id) { return nodeStore.get(id) != null; @@ -219,6 +223,11 @@ public Edge getEdge(Object id) { return edgeStore.get(id); } + @Override + public Edge getEdgeByStoreId(int storeId) { + throw new UnsupportedOperationException("Not supported yet."); + } + @Override public boolean hasEdge(Object id) { return edgeStore.get(id) != null; diff --git a/src/test/java/org/gephi/graph/impl/GraphStoreTest.java b/src/test/java/org/gephi/graph/impl/GraphStoreTest.java index ec6fb2e4..9d4c70ab 100644 --- a/src/test/java/org/gephi/graph/impl/GraphStoreTest.java +++ b/src/test/java/org/gephi/graph/impl/GraphStoreTest.java @@ -620,6 +620,24 @@ public void testGetNode() { Assert.assertFalse(graphStore.hasNode("bar")); } + @Test + public void testGetNodeByStoreId() { + GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); + for (Node node : graphStore.getNodes().toArray()) { + Assert.assertNotNull(graphStore.getNodeByStoreId(node.getStoreId())); + } + } + + @Test + public void testGetNodeByStoreIdIsNull() { + GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); + for (Node node : graphStore.getNodes().toArray()) { + int storeId = node.getStoreId(); + graphStore.removeNode(node); + Assert.assertNull(graphStore.getNodeByStoreId(storeId)); + } + } + @Test public void testGetEdge() { GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); @@ -629,6 +647,23 @@ public void testGetEdge() { Assert.assertFalse(graphStore.hasEdge("bar")); } + @Test + public void testGetEdgeByStoreId() { + GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); + for (Edge edge : graphStore.getEdges().toArray()) { + Assert.assertNotNull(graphStore.getEdgeByStoreId(edge.getStoreId())); + } + } + + @Test + public void testGetEdgeByStoreIdIsNull() { + GraphStore graphStore = GraphGenerator.generateTinyGraphStore(); + Edge toRemove = graphStore.getEdge("0"); + int storeId = toRemove.getStoreId(); + graphStore.removeEdge(toRemove); + Assert.assertNull(graphStore.getEdgeByStoreId(storeId)); + } + @Test public void testGetMutualEdge() { GraphStore graphStore = new GraphStore();