1
0
Fork 0

Graph: Replace a given vertex by ID

This commit is contained in:
Lucas Dohmen 2013-10-31 14:45:21 +01:00
parent 3da8d973f9
commit 04c7cfce33
3 changed files with 32 additions and 0 deletions

View File

@ -279,6 +279,14 @@ Graph.prototype._saveVertex = function (id, params) {
return new Vertex(this, results.vertex);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief replace a vertex in the graph
////////////////////////////////////////////////////////////////////////////////
Graph.prototype._replaceVertex = function (id, data) {
GraphAPI.putVertex(this._properties._key, id, data);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a vertex given its id
////////////////////////////////////////////////////////////////////////////////

View File

@ -781,6 +781,18 @@ Graph.prototype.addVertex = function (id, data, waitForSync) {
return this._saveVertex(id, this._prepareVertexData(data), waitForSync);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief replaces an existing vertex by ID
///
/// @FUN{@FA{graph}.replaceVertex(@FA{id}, @FA{data})}
///
/// Replaces an existing vertex by ID
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.replaceVertex = function (id, data) {
this._replaceVertex(id, data);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the number of vertices
///

View File

@ -194,6 +194,18 @@ function GraphBasicsSuite() {
assertEqual(23, v2.getProperty("age"));
},
////////////////////////////////////////////////////////////////////////////////
/// @brief replace a vertex
////////////////////////////////////////////////////////////////////////////////
testReplaceVertex : function () {
var v = graph.addVertex("vertex_to_replace", { age : 23 });
graph.replaceVertex("vertex_to_replace", { age: 24 });
v = graph.getVertex("vertex_to_replace");
assertEqual(24, v.getProperty("age"));
},
////////////////////////////////////////////////////////////////////////////////
/// @brief change a property
////////////////////////////////////////////////////////////////////////////////